PluginProbe
ActivityPub / 3.2.4
ActivityPub v3.2.4
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/transformer/class-base.php +21 -7 2.0.1 → 3.2.4 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 2 namespace Activitypub\Transformer;
3 3
4 +use WP_Error;
4 5 use WP_Post;
5 6 use WP_Comment;
6 7
7 8 use Activitypub\Activity\Activity;
@@ -29,11 +30,11 @@
29 30 * This helps to chain the output of the Transformer.
30 31 *
31 32 * @param WP_Post|WP_Comment $wp_object The WordPress object
32 33 *
33 - * @return void
34 + * @return Base
34 35 */
35 - public static function transform( $object ) {
36 + public static function transform( $object ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
36 37 return new static( $object );
37 38 }
38 39
39 40 /**
@@ -45,15 +46,15 @@
45 46 $this->wp_object = $wp_object;
46 47 }
47 48
48 49 /**
49 - * Transform the WordPress Object into an ActivityPub Object.
50 + * Transform all properties with available get(ter) functions.
50 51 *
51 - * @return Activitypub\Activity\Base_Object
52 + * @param Base_Object|object $object
53 + *
54 + * @return Base_Object|object $object
52 55 */
53 - public function to_object() {
54 - $activitypub_object = new Base_Object();
55 -
56 + protected function transform_object_properties( $activitypub_object ) {
56 57 $vars = $activitypub_object->get_object_var_keys();
57 58
58 59 foreach ( $vars as $var ) {
59 60 $getter = 'get_' . $var;
@@ -67,9 +68,20 @@
67 68 call_user_func( array( $activitypub_object, $setter ), $value );
68 69 }
69 70 }
70 71 }
72 + return $activitypub_object;
73 + }
71 74
75 + /**
76 + * Transform the WordPress Object into an ActivityPub Object.
77 + *
78 + * @return Activitypub\Activity\Base_Object
79 + */
80 + public function to_object() {
81 + $activitypub_object = new Base_Object();
82 + $activitypub_object = $this->transform_object_properties( $activitypub_object );
83 +
72 84 return $activitypub_object;
73 85 }
74 86
75 87 /**
@@ -83,8 +95,10 @@
83 95 $object = $this->to_object();
84 96
85 97 $activity = new Activity();
86 98 $activity->set_type( $type );
99 +
100 + // Pre-fill the Activity with data (for example cc and to).
87 101 $activity->set_object( $object );
88 102
89 103 // Use simple Object (only ID-URI) for Like and Announce
90 104 if ( in_array( $type, array( 'Like', 'Announce' ), true ) ) {