@@ -35,4 +35,78 @@ protected function check_object_id( $object_id ) {
3535 return $ site ->blog_id ;
3636 }
3737
38+ /**
39+ * Wrapper method for add_metadata that can be overridden in sub classes.
40+ *
41+ * @param int $object_id ID of the object the metadata is for.
42+ * @param string $meta_key Metadata key to use.
43+ * @param mixed $meta_value Metadata value. Must be serializable if
44+ * non-scalar.
45+ * @param bool $unique Optional, default is false. Whether the
46+ * specified metadata key should be unique for the
47+ * object. If true, and the object already has a
48+ * value for the specified metadata key, no change
49+ * will be made.
50+ *
51+ * @return int|false The meta ID on success, false on failure.
52+ */
53+ protected function add_metadata ( $ object_id , $ meta_key , $ meta_value , $ unique = false ) {
54+ return add_site_meta ( $ object_id , $ meta_key , $ meta_value , $ unique );
55+ }
56+
57+ /**
58+ * Wrapper method for update_metadata that can be overridden in sub classes.
59+ *
60+ * @param int $object_id ID of the object the metadata is for.
61+ * @param string $meta_key Metadata key to use.
62+ * @param mixed $meta_value Metadata value. Must be serializable if
63+ * non-scalar.
64+ * @param mixed $prev_value Optional. If specified, only update existing
65+ * metadata entries with the specified value.
66+ * Otherwise, update all entries.
67+ *
68+ * @return int|bool Meta ID if the key didn't exist, true on successful
69+ * update, false on failure.
70+ */
71+ protected function update_metadata ( $ object_id , $ meta_key , $ meta_value , $ prev_value = '' ) {
72+ return update_site_meta ( $ object_id , $ meta_key , $ meta_value , $ prev_value );
73+ }
74+
75+ /**
76+ * Wrapper method for get_metadata that can be overridden in sub classes.
77+ *
78+ * @param int $object_id ID of the object the metadata is for.
79+ * @param string $meta_key Optional. Metadata key. If not specified,
80+ * retrieve all metadata for the specified object.
81+ * @param bool $single Optional, default is false. If true, return only
82+ * the first value of the specified meta_key. This
83+ * parameter has no effect if meta_key is not
84+ * specified.
85+ *
86+ * @return mixed Single metadata value, or array of values.
87+ */
88+ protected function get_metadata ( $ object_id , $ meta_key = '' , $ single = false ) {
89+ return get_site_meta ( $ object_id , $ meta_key , $ single );
90+ }
91+
92+ /**
93+ * Wrapper method for delete_metadata that can be overridden in sub classes.
94+ *
95+ * @param int $object_id ID of the object metadata is for
96+ * @param string $meta_key Metadata key
97+ * @param mixed $meta_value Optional. Metadata value. Must be serializable
98+ * if non-scalar. If specified, only delete
99+ * metadata entries with this value. Otherwise,
100+ * delete all entries with the specified meta_key.
101+ * Pass `null, `false`, or an empty string to skip
102+ * this check. For backward compatibility, it is
103+ * not possible to pass an empty string to delete
104+ * those entries with an empty string for a value.
105+ *
106+ * @return bool True on successful delete, false on failure.
107+ */
108+ protected function delete_metadata ( $ object_id , $ meta_key , $ meta_value = '' ) {
109+ return delete_site_meta ( $ object_id , $ meta_key , $ meta_value );
110+ }
111+
38112}
0 commit comments