PluginProbe
Parse.ly / 3.8.4
Parse.ly v3.8.4
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
← All changes | src/Endpoints/class-rest-metadata.php +23 -30 3.23.63.8.4 View file →
@@ -11,11 +11,8 @@
11 11 namespace Parsely\Endpoints;
12 12
13 13 use Parsely\Metadata;
14 14 use WP_Post;
15 -use Parsely\Models\Smart_Link;
16 -use Parsely\Models\Smart_Link_Status;
17 -use Parsely\Models\Inbound_Smart_Link;
18 15
19 16 /**
20 17 * Injects Parse.ly Metadata to WordPress REST API.
21 18 *
@@ -30,8 +27,15 @@
30 27 *
31 28 * @since 3.1.0
32 29 */
33 30 public function run(): void {
31 + /**
32 + * Filter whether REST API support is enabled or not.
33 + *
34 + * @since 3.1.0
35 + *
36 + * @param bool $enabled True if enabled, false if not.
37 + */
34 38 if ( apply_filters( 'wp_parsely_enable_rest_api_support', true ) && $this->parsely->site_id_is_set() ) {
35 39 $this->register_meta();
36 40 }
37 41 }
@@ -61,40 +65,35 @@
61 65 /**
62 66 * Function to get hooked into the `get_callback` property of the `parsely`
63 67 * REST API field. It generates the `parsely` object in the REST API.
64 68 *
65 - * @since 3.1.0
66 - * @since 3.19.0 Added the `canonical_url` field.
69 + * @param array<string, mixed> $object The WordPress object to extract to render the metadata for,
70 + * usually a post or a page.
67 71 *
68 - * @param array<string, mixed> $object_data The data of the object to render the metadata for,
69 - * usually a post or a page.
70 72 * @return array<string, mixed> The `parsely` object to be rendered in the REST API. Contains a
71 73 * version number describing the response and the `meta` object
72 74 * containing the actual metadata.
73 75 */
74 - public function get_callback( array $object_data ): array {
75 - /** @var int $post_id */
76 - $post_id = $object_data['ID'] ?? $object_data['id'] ?? 0;
76 + public function get_callback( array $object ): array {
77 + /**
78 + * Variable.
79 + *
80 + * @var int
81 + */
82 + $post_id = $object['ID'] ?? $object['id'] ?? 0;
77 83 $post = WP_Post::get_instance( $post_id );
78 -
79 84 $options = $this->parsely->get_options();
80 85
81 - $response = array(
82 - 'version' => self::REST_VERSION,
83 - 'canonical_url' => \Parsely\Parsely::get_canonical_url_from_post( $post_id ),
84 - 'smart_links' => array(
85 - 'inbound' => 0,
86 - 'outbound' => 0,
87 - ),
88 - 'traffic_boost_suggestions_count' => 0,
89 - );
90 -
91 86 if ( false === $post ) {
92 - return $response;
87 + $metadata = '';
88 + } else {
89 + $metadata = ( new Metadata( $this->parsely ) )->construct_metadata( $post );
93 90 }
94 91
95 - $metadata = ( new Metadata( $this->parsely ) )->construct_metadata( $post );
96 - $response['meta'] = $metadata;
92 + $response = array(
93 + 'version' => self::REST_VERSION,
94 + 'meta' => $metadata,
95 + );
97 96
98 97 /**
99 98 * Filter whether REST API support in rendered string format is enabled
100 99 * or not.
@@ -118,14 +117,8 @@
118 117 */
119 118 if ( apply_filters( 'wp_parsely_enable_tracker_url', true, $post ) ) {
120 119 $response['tracker_url'] = $this->parsely->get_tracker_url();
121 120 }
122 -
123 - // Fetch Smart Link data.
124 - $response['smart_links'] = Smart_Link::get_link_counts( $post_id, Smart_Link_Status::APPLIED );
125 -
126 - // Fetch Traffic Boost data.
127 - $response['traffic_boost_suggestions_count'] = Inbound_Smart_Link::get_suggestions_count( $post_id );
128 121
129 122 return $response;
130 123 }
131 124 }