| @@ -27,15 +27,8 @@ | ||
| 27 | 27 | * |
| 28 | 28 | * @since 3.1.0 |
| 29 | 29 | */ |
| 30 | 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 | - */ | |
| 38 | 31 | if ( apply_filters( 'wp_parsely_enable_rest_api_support', true ) && $this->parsely->site_id_is_set() ) { |
| 39 | 32 | $this->register_meta(); |
| 40 | 33 | } |
| 41 | 34 | } |
| @@ -65,8 +58,12 @@ | ||
| 65 | 58 | /** |
| 66 | 59 | * Function to get hooked into the `get_callback` property of the `parsely` |
| 67 | 60 | * REST API field. It generates the `parsely` object in the REST API. |
| 68 | 61 | * |
| 62 | + * @since 3.1.0 | |
| 63 | + * @since 3.19.0 Added the `canonical_url` field. | |
| 64 | + * @since 3.24.2 Removed the `smart_links` and `traffic_boost_suggestions_count` fields. | |
| 65 | + * | |
| 69 | 66 | * @param array<string, mixed> $object_data The data of the object to render the metadata for, |
| 70 | 67 | * usually a post or a page. |
| 71 | 68 | * @return array<string, mixed> The `parsely` object to be rendered in the REST API. Contains a |
| 72 | 69 | * version number describing the response and the `meta` object |
| @@ -72,27 +69,25 @@ | ||
| 72 | 69 | * version number describing the response and the `meta` object |
| 73 | 70 | * containing the actual metadata. |
| 74 | 71 | */ |
| 75 | 72 | public function get_callback( array $object_data ): array { |
| 76 | - /** | |
| 77 | - * Variable. | |
| 78 | - * | |
| 79 | - * @var int | |
| 80 | - */ | |
| 73 | + /** @var int $post_id */ | |
| 81 | 74 | $post_id = $object_data['ID'] ?? $object_data['id'] ?? 0; |
| 82 | 75 | $post = WP_Post::get_instance( $post_id ); |
| 76 | + | |
| 83 | 77 | $options = $this->parsely->get_options(); |
| 84 | 78 | |
| 79 | + $response = array( | |
| 80 | + 'version' => self::REST_VERSION, | |
| 81 | + 'canonical_url' => \Parsely\Parsely::get_canonical_url_from_post( $post_id ), | |
| 82 | + ); | |
| 83 | + | |
| 85 | 84 | if ( false === $post ) { |
| 86 | - $metadata = ''; | |
| 87 | - } else { | |
| 88 | - $metadata = ( new Metadata( $this->parsely ) )->construct_metadata( $post ); | |
| 85 | + return $response; | |
| 89 | 86 | } |
| 90 | 87 | |
| 91 | - $response = array( | |
| 92 | - 'version' => self::REST_VERSION, | |
| 93 | - 'meta' => $metadata, | |
| 94 | - ); | |
| 88 | + $metadata = ( new Metadata( $this->parsely ) )->construct_metadata( $post ); | |
| 89 | + $response['meta'] = $metadata; | |
| 95 | 90 | |
| 96 | 91 | /** |
| 97 | 92 | * Filter whether REST API support in rendered string format is enabled |
| 98 | 93 | * or not. |