PluginProbe
BuddyPress / trunk
BuddyPress vtrunk
11.6.2 12.7.2 14.5.2 11.6.0 12.7.0 2.5.0-rc1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.0-beta1 2.6.0-rc1 2.6.1 2.6.1.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.0-beta1 2.7.0-rc1 2.7.0-rc2 2.7.1 2.7.2 All 274 releases
buddypress / cli / src / activity-meta.php

activity-meta.php in BuddyPress trunk, at cli/src/activity-meta.php

126 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Buddypress\CLI\Command;
4
5 use WP_CLI\CommandWithMeta;
6
7 /**
8 * Adds, updates, deletes, and lists activity custom fields.
9 *
10 * ## EXAMPLES
11 *
12 * # Set activity meta
13 * $ wp bp activity meta set 123 description "Mary is a activity user."
14 * Success: Updated custom field 'description'.
15 *
16 * # Get activity meta
17 * $ wp bp activity meta get 123 description
18 * Mary is a Activity user.
19 *
20 * # Update activity meta
21 * $ wp bp activity meta update 123 description "Mary is an awesome activity user."
22 * Success: Updated custom field 'description'.
23 *
24 * # Delete activity meta
25 * $ wp bp activity meta delete 123 description
26 * Success: Deleted custom field.
27 *
28 * @since 2.0.0
29 */
30 class Activity_Meta extends CommandWithMeta {
31
32 /**
33 * Type of the meta.
34 *
35 * @var string
36 */
37 protected $meta_type = 'activity';
38
39 /**
40 * Wrapper method for add_metadata that can be overridden in sub classes.
41 *
42 * @param int $object_id ID of the object the metadata is for.
43 * @param string $meta_key Metadata key to use.
44 * @param mixed $meta_value Metadata value. Must be serializable if
45 * non-scalar.
46 * @param bool $unique Optional, default is false. Whether the
47 * specified metadata key should be unique for the
48 * object. If true, and the object already has a
49 * value for the specified metadata key, no change
50 * will be made.
51 *
52 * @return int|false The meta ID on success, false on failure.
53 */
54 protected function add_metadata( $object_id, $meta_key, $meta_value, $unique = false ) {
55 return bp_activity_add_meta( $object_id, $meta_key, $meta_value );
56 }
57
58 /**
59 * Wrapper method for update_metadata that can be overridden in sub classes.
60 *
61 * @param int $object_id ID of the object the metadata is for.
62 * @param string $meta_key Metadata key to use.
63 * @param mixed $meta_value Metadata value. Must be serializable if
64 * non-scalar.
65 * @param mixed $prev_value Optional. If specified, only update existing
66 * metadata entries with the specified value.
67 * Otherwise, update all entries.
68 *
69 * @return int|bool Meta ID if the key didn't exist, true on successful
70 * update, false on failure.
71 */
72 protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_value = '' ) {
73 return bp_activity_update_meta( $object_id, $meta_key, $meta_value, $prev_value );
74 }
75
76 /**
77 * Wrapper method for get_metadata that can be overridden in sub classes.
78 *
79 * @param int $object_id ID of the object the metadata is for.
80 * @param string $meta_key Optional. Metadata key. If not specified,
81 * retrieve all metadata for the specified object.
82 * @param bool $single Optional, default is false. If true, return only
83 * the first value of the specified meta_key. This
84 * parameter has no effect if meta_key is not
85 * specified.
86 *
87 * @return mixed Single metadata value, or array of values.
88 */
89 protected function get_metadata( $object_id, $meta_key = '', $single = true ) {
90 return bp_activity_get_meta( $object_id, $meta_key, $single );
91 }
92
93 /**
94 * Wrapper method for delete_metadata that can be overridden in sub classes.
95 *
96 * @param int $object_id ID of the object metadata is for
97 * @param string $meta_key Metadata key
98 * @param mixed $meta_value Optional. Metadata value. Must be serializable
99 * if non-scalar. If specified, only delete
100 * metadata entries with this value. Otherwise,
101 * delete all entries with the specified meta_key.
102 * Pass `null, `false`, or an empty string to skip
103 * this check. For backward compatibility, it is
104 * not possible to pass an empty string to delete
105 * those entries with an empty string for a value.
106 *
107 * @return bool True on successful delete, false on failure.
108 */
109 protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) {
110 return bp_activity_delete_meta( $object_id, $meta_key, $meta_value );
111 }
112
113 /**
114 * Check that the activity ID exists.
115 *
116 * @param int $object_id Object ID.
117 * @return int
118 */
119 protected function check_object_id( $object_id ) {
120 $fetcher = new Activity_Fetcher();
121 $activity = $fetcher->get_check( $object_id );
122
123 return $activity->id;
124 }
125 }
126