2424class Comment_Meta_Command extends \WP_CLI \CommandWithMeta {
2525 protected $ meta_type = 'comment ' ;
2626
27+ /**
28+ * Wrapper method for add_metadata that can be overridden in sub classes.
29+ *
30+ * @param int $object_id ID of the object the metadata is for.
31+ * @param string $meta_key Metadata key to use.
32+ * @param mixed $meta_value Metadata value. Must be serializable if
33+ * non-scalar.
34+ * @param bool $unique Optional, default is false. Whether the
35+ * specified metadata key should be unique for the
36+ * object. If true, and the object already has a
37+ * value for the specified metadata key, no change
38+ * will be made.
39+ *
40+ * @return int|false The meta ID on success, false on failure.
41+ */
42+ protected function add_metadata ( $ object_id , $ meta_key , $ meta_value , $ unique = false ) {
43+ return add_comment_meta ( $ object_id , $ meta_key , $ meta_value , $ unique );
44+ }
45+
46+ /**
47+ * Wrapper method for update_metadata that can be overridden in sub classes.
48+ *
49+ * @param int $object_id ID of the object the metadata is for.
50+ * @param string $meta_key Metadata key to use.
51+ * @param mixed $meta_value Metadata value. Must be serializable if
52+ * non-scalar.
53+ * @param mixed $prev_value Optional. If specified, only update existing
54+ * metadata entries with the specified value.
55+ * Otherwise, update all entries.
56+ *
57+ * @return int|bool Meta ID if the key didn't exist, true on successful
58+ * update, false on failure.
59+ */
60+ protected function update_metadata ( $ object_id , $ meta_key , $ meta_value , $ prev_value = '' ) {
61+ return update_comment_meta ( $ object_id , $ meta_key , $ meta_value , $ prev_value );
62+ }
63+
64+ /**
65+ * Wrapper method for get_metadata that can be overridden in sub classes.
66+ *
67+ * @param int $object_id ID of the object the metadata is for.
68+ * @param string $meta_key Optional. Metadata key. If not specified,
69+ * retrieve all metadata for the specified object.
70+ * @param bool $single Optional, default is false. If true, return only
71+ * the first value of the specified meta_key. This
72+ * parameter has no effect if meta_key is not
73+ * specified.
74+ *
75+ * @return mixed Single metadata value, or array of values.
76+ */
77+ protected function get_metadata ( $ object_id , $ meta_key = '' , $ single = false ) {
78+ return get_comment_meta ( $ object_id , $ meta_key , $ single );
79+ }
80+
81+ /**
82+ * Wrapper method for delete_metadata that can be overridden in sub classes.
83+ *
84+ * @param int $object_id ID of the object metadata is for
85+ * @param string $meta_key Metadata key
86+ * @param mixed $meta_value Optional. Metadata value. Must be serializable
87+ * if non-scalar. If specified, only delete
88+ * metadata entries with this value. Otherwise,
89+ * delete all entries with the specified meta_key.
90+ * Pass `null, `false`, or an empty string to skip
91+ * this check. For backward compatibility, it is
92+ * not possible to pass an empty string to delete
93+ * those entries with an empty string for a value.
94+ *
95+ * @return bool True on successful delete, false on failure.
96+ */
97+ protected function delete_metadata ( $ object_id , $ meta_key , $ meta_value = '' ) {
98+ return delete_comment_meta ( $ object_id , $ meta_key , $ meta_value );
99+ }
100+
27101 /**
28102 * Check that the comment ID exists
29103 *
@@ -35,4 +109,3 @@ protected function check_object_id( $object_id ) {
35109 return $ comment ->comment_ID ;
36110 }
37111}
38-
0 commit comments