PluginProbe
Parse.ly / 3.14.1
Parse.ly v3.14.1
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 +19 -27 3.19.33.14.1 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,11 +65,8 @@
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.
67 - *
68 69 * @param array<string, mixed> $object_data The data of the object to render the metadata for,
69 70 * usually a post or a page.
70 71 * @return array<string, mixed> The `parsely` object to be rendered in the REST API. Contains a
71 72 * version number describing the response and the `meta` object
@@ -71,30 +72,27 @@
71 72 * version number describing the response and the `meta` object
72 73 * containing the actual metadata.
73 74 */
74 75 public function get_callback( array $object_data ): array {
75 - /** @var int $post_id */
76 + /**
77 + * Variable.
78 + *
79 + * @var int
80 + */
76 81 $post_id = $object_data['ID'] ?? $object_data['id'] ?? 0;
77 82 $post = WP_Post::get_instance( $post_id );
78 -
79 83 $options = $this->parsely->get_options();
80 84
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 85 if ( false === $post ) {
92 - return $response;
86 + $metadata = '';
87 + } else {
88 + $metadata = ( new Metadata( $this->parsely ) )->construct_metadata( $post );
93 89 }
94 90
95 - $metadata = ( new Metadata( $this->parsely ) )->construct_metadata( $post );
96 - $response['meta'] = $metadata;
91 + $response = array(
92 + 'version' => self::REST_VERSION,
93 + 'meta' => $metadata,
94 + );
97 95
98 96 /**
99 97 * Filter whether REST API support in rendered string format is enabled
100 98 * or not.
@@ -118,14 +116,8 @@
118 116 */
119 117 if ( apply_filters( 'wp_parsely_enable_tracker_url', true, $post ) ) {
120 118 $response['tracker_url'] = $this->parsely->get_tracker_url();
121 119 }
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 120
129 121 return $response;
130 122 }
131 123 }