PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/activity/class-generic-object.php +24 -46 9.2.08.0.2 View file →
@@ -98,9 +98,9 @@
98 98 *
99 99 * @return mixed The value.
100 100 */
101 101 public function get( $key ) {
102 - return \call_user_func( array( $this, 'get_' . $key ) );
102 + return call_user_func( array( $this, 'get_' . $key ) );
103 103 }
104 104
105 105 /**
106 106 * Generic setter.
@@ -132,21 +132,21 @@
132 132 if ( ! isset( $this->$key ) ) {
133 133 $this->$key = array();
134 134 }
135 135
136 - if ( \is_string( $this->$key ) ) {
136 + if ( is_string( $this->$key ) ) {
137 137 $this->$key = array( $this->$key );
138 138 }
139 139
140 140 $attributes = $this->$key;
141 141
142 - if ( \is_array( $value ) ) {
143 - $attributes = \array_merge( $attributes, $value );
142 + if ( is_array( $value ) ) {
143 + $attributes = array_merge( $attributes, $value );
144 144 } else {
145 145 $attributes[] = $value;
146 146 }
147 147
148 - $this->$key = \array_unique( $attributes );
148 + $this->$key = array_unique( $attributes );
149 149
150 150 return $this->$key;
151 151 }
152 152
@@ -157,9 +157,9 @@
157 157 *
158 158 * @return boolean True if the object has the key.
159 159 */
160 160 public function has( $key ) {
161 - return \property_exists( $this, $key );
161 + return property_exists( $this, $key );
162 162 }
163 163
164 164 /**
165 165 * Convert JSON input to an array.
@@ -170,10 +170,10 @@
170 170 */
171 171 public static function init_from_json( $json ) {
172 172 $array = \json_decode( $json, true );
173 173
174 - if ( ! \is_array( $array ) ) {
175 - return new \WP_Error( 'invalid_json', \__( 'Invalid JSON', 'activitypub' ), array( 'status' => 400 ) );
174 + if ( ! is_array( $array ) ) {
175 + return new \WP_Error( 'invalid_json', __( 'Invalid JSON', 'activitypub' ), array( 'status' => 400 ) );
176 176 }
177 177
178 178 return self::init_from_array( $array );
179 179 }
@@ -185,10 +185,10 @@
185 185 *
186 186 * @return static|\WP_Error An Object built from the input array or WP_Error when it's not an array.
187 187 */
188 188 public static function init_from_array( $data ) {
189 - if ( ! \is_array( $data ) ) {
190 - return new \WP_Error( 'invalid_array', \__( 'Invalid array', 'activitypub' ), array( 'status' => 400 ) );
189 + if ( ! is_array( $data ) ) {
190 + return new \WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 400 ) );
191 191 }
192 192
193 193 $object = new static();
194 194 $object->from_array( $data );
@@ -208,9 +208,9 @@
208 208 if ( ! \str_starts_with( $key, '_' ) ) {
209 209 $key = camel_to_snake_case( $key );
210 210 }
211 211
212 - \call_user_func( array( $this, 'set_' . $key ), $value );
212 + call_user_func( array( $this, 'set_' . $key ), $value );
213 213 }
214 214 }
215 215 }
216 216
@@ -230,22 +230,15 @@
230 230 *
231 231 * It tries to get the object attributes if they exist
232 232 * and falls back to the getters. Empty values are ignored.
233 233 *
234 - * By default, `bto` and `bcc` (the blind audience fields) are stripped
235 - * from the output per ActivityPub Section 6, so every serialization path
236 - * is safe for emission. Internal callers that need to persist the blind
237 - * audience (e.g., outbox/inbox storage) can opt in by passing
238 - * `$include_blind_audience = true`.
239 - *
240 234 * @param bool $include_json_ld_context Whether to include the JSON-LD context. Default true.
241 - * @param bool $include_blind_audience Whether to keep `bto` and `bcc` in the output. Default false.
242 235 *
243 236 * @return array An array built from the Object.
244 237 */
245 - public function to_array( $include_json_ld_context = true, $include_blind_audience = false ) {
238 + public function to_array( $include_json_ld_context = true ) {
246 239 $array = array();
247 - $vars = \get_object_vars( $this );
240 + $vars = get_object_vars( $this );
248 241
249 242 foreach ( $vars as $key => $value ) {
250 243 if ( \is_wp_error( $value ) ) {
251 244 continue;
@@ -251,22 +244,22 @@
251 244 continue;
252 245 }
253 246
254 247 // Ignore all _prefixed keys.
255 - if ( '_' === \substr( $key, 0, 1 ) ) {
248 + if ( '_' === substr( $key, 0, 1 ) ) {
256 249 continue;
257 250 }
258 251
259 252 // If value is empty, try to get it from a getter.
260 253 if ( ! $value ) {
261 - $value = \call_user_func( array( $this, 'get_' . $key ) );
254 + $value = call_user_func( array( $this, 'get_' . $key ) );
262 255 }
263 256
264 - if ( \is_object( $value ) ) {
265 - $value = $value->to_array( false, $include_blind_audience );
257 + if ( is_object( $value ) ) {
258 + $value = $value->to_array( false );
266 259 }
267 260
268 - if ( \is_array( $value ) && $this->is_namespaced( $key ) ) {
261 + if ( is_array( $value ) && $this->is_namespaced( $key ) ) {
269 262 foreach ( $value as $sub_key => $sub_value ) {
270 263 $array[ snake_to_camel_case( $key ) . ':' . snake_to_camel_case( $sub_key ) ] = $sub_value;
271 264 }
272 265 } elseif ( isset( $value ) ) {
@@ -275,13 +268,13 @@
275 268 }
276 269
277 270 if ( $include_json_ld_context ) {
278 271 // Get JsonLD context and move it to '@context' at the top.
279 - $array = \array_merge( array( '@context' => $this->get_json_ld_context() ), $array );
272 + $array = array_merge( array( '@context' => $this->get_json_ld_context() ), $array );
280 273 }
281 274
282 275 $class = new \ReflectionClass( $this );
283 - $class = \strtolower( $class->getShortName() );
276 + $class = strtolower( $class->getShortName() );
284 277
285 278 /**
286 279 * Filter the array of the ActivityPub object.
287 280 *
@@ -302,23 +295,9 @@
302 295 * @param Generic_Object $object The ActivityPub object.
303 296 *
304 297 * @return array The filtered array of the ActivityPub object.
305 298 */
306 - $array = \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
307 -
308 - if ( ! $include_blind_audience ) {
309 - /*
310 - * Strip `bto` and `bcc` from the serialized array per ActivityPub Section 6.
311 - * Callers that need the blind audience either read it from the object via
312 - * `get_bto()` / `get_bcc()` or opt in with `$include_blind_audience = true`.
313 - */
314 - unset( $array['bto'], $array['bcc'] );
315 - if ( isset( $array['object'] ) && \is_array( $array['object'] ) ) {
316 - unset( $array['object']['bto'], $array['object']['bcc'] );
317 - }
318 - }
319 -
320 - return $array;
299 + return \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
321 300 }
322 301
323 302 /**
324 303 * Convert Object to JSON.
@@ -323,14 +302,13 @@
323 302 /**
324 303 * Convert Object to JSON.
325 304 *
326 305 * @param bool $include_json_ld_context Whether to include the JSON-LD context. Default true.
327 - * @param bool $include_blind_audience Whether to keep `bto` and `bcc` in the output. Default false.
328 306 *
329 307 * @return string The JSON string.
330 308 */
331 - public function to_json( $include_json_ld_context = true, $include_blind_audience = false ) {
332 - $array = $this->to_array( $include_json_ld_context, $include_blind_audience );
309 + public function to_json( $include_json_ld_context = true ) {
310 + $array = $this->to_array( $include_json_ld_context );
333 311 $options = \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT | \JSON_UNESCAPED_SLASHES;
334 312
335 313 /**
336 314 * Options to be passed to json_encode().
@@ -370,9 +348,9 @@
370 348 private function is_namespaced( $attribute ) {
371 349 $namespaces = array();
372 350
373 351 foreach ( static::JSON_LD_CONTEXT as $context ) {
374 - if ( \is_array( $context ) ) {
352 + if ( is_array( $context ) ) {
375 353 $namespaces = \array_merge( $namespaces, $context );
376 354 }
377 355 }
378 356