PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.7.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.7.0
2.8.0 2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 All 49 releases
thinkrank / includes / abilities / indexing / class-submit-urls-to-index.php

class-submit-urls-to-index.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 2.7.0, at includes/abilities/indexing/class-submit-urls-to-index.php

128 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Submit URLs to index ability.
4 *
5 * @package ThinkRank\Abilities\Indexing
6 */
7
8 declare(strict_types=1);
9
10 namespace ThinkRank\Abilities\Indexing;
11
12 use ThinkRank\Abilities\Ability_Base;
13 use ThinkRank\SEO\Instant_Indexing_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Submits URLs to search engines via the IndexNow protocol.
21 *
22 * Requires instant indexing to be configured (an API key must exist); otherwise
23 * the manager responds with "API Key missing". This calls the external IndexNow
24 * API.
25 */
26 class Submit_Urls_To_Index extends Ability_Base {
27 /**
28 * Constructor.
29 */
30 public function __construct() {
31 $this->id = 'thinkrank/submit-urls-to-index';
32 $this->label = __( 'Submit URLs to Instant Indexing', 'thinkrank' );
33 $this->description = __( 'Submit one or more URLs to search engines via the IndexNow protocol. Requires instant indexing to be configured (an API key must exist) or it returns "API Key missing". Calls the external IndexNow API. get-instant-indexing-settings reports whether a key is configured, and get-instant-indexing-history lists past submissions.', 'thinkrank' );
34 }
35
36 /**
37 * {@inheritDoc}
38 *
39 * @return array<string, bool|float|string>
40 */
41 public function get_annotations() {
42 return [
43 'readonly' => false,
44 // Deliberately kept. This calls the external IndexNow API, and a URL
45 // announced to a search engine cannot be un-announced — the one
46 // thing on the free surface that genuinely cannot be undone from
47 // inside ThinkRank, which is what `destructive` is for (#675).
48 'destructive' => true,
49 'idempotent' => false,
50 'priority' => 2.0,
51 'openWorldHint' => true,
52 ];
53 }
54
55 /**
56 * {@inheritDoc}
57 *
58 * @return array<string, mixed>
59 */
60 public function get_input_schema() {
61 return [
62 'type' => 'object',
63 'additionalProperties' => false,
64 'properties' => [
65 'urls' => [
66 'type' => 'array',
67 'description' => __( 'The URLs to submit for indexing (same-site host only).', 'thinkrank' ),
68 'minItems' => 1,
69 'maxItems' => \ThinkRank\SEO\Instant_Indexing_Manager::MAX_URLS_PER_SUBMISSION,
70 'items' => [
71 'type' => 'string',
72 'format' => 'uri',
73 ],
74 ],
75 ],
76 'required' => [ 'urls' ],
77 ];
78 }
79
80 /**
81 * {@inheritDoc}
82 *
83 * @return array<string, mixed>
84 */
85 public function get_output_schema() {
86 return [
87 'type' => 'object',
88 'properties' => [
89 'success' => [ 'type' => 'boolean' ],
90 'code' => [ 'type' => 'integer' ],
91 'message' => [ 'type' => 'string' ],
92 'submitted_count' => [ 'type' => 'integer' ],
93 ],
94 ];
95 }
96
97 /**
98 * Execute ability.
99 *
100 * @param array<string, mixed> $input Ability input payload.
101 * @return array<string, mixed>|\WP_Error
102 */
103 public function execute( $input ) {
104 $urls = isset( $input['urls'] ) && is_array( $input['urls'] ) ? $input['urls'] : [];
105 $urls = array_values( array_filter( array_map( 'esc_url_raw', $urls ) ) );
106
107 if ( empty( $urls ) ) {
108 return new \WP_Error(
109 'thinkrank_missing_index_urls',
110 __( 'At least one valid URL is required.', 'thinkrank' ),
111 [ 'status' => 400 ]
112 );
113 }
114
115 $manager = new Instant_Indexing_Manager();
116 $result = $manager->submit_urls( $urls );
117
118 return [
119 'success' => (bool) ( $result['success'] ?? false ),
120 'code' => (int) ( $result['code'] ?? 0 ),
121 'message' => (string) ( $result['message'] ?? '' ),
122 // The count the manager actually submitted after same-host filtering
123 // and its cap, not the raw input size.
124 'submitted_count' => (int) ( $result['submitted_count'] ?? 0 ),
125 ];
126 }
127 }
128