PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.10.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.10.0
2.11.0 2.10.0 2.9.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 All 52 releases
← All changes | includes/abilities/settings/class-update-sitemap-settings.php +57 -11 2.7.0 → 2.10.0 View file →
@@ -62,13 +62,18 @@
62 62 return [
63 63 'type' => 'object',
64 64 'additionalProperties' => false,
65 65 'properties' => [
66 - 'settings' => [
66 + 'settings' => [
67 67 'type' => 'object',
68 68 'description' => __( 'Sitemap settings to update.', 'thinkrank' ),
69 69 'properties' => Settings_Key_Map::sitemap(),
70 70 ],
71 + 'regenerate' => [
72 + 'type' => 'boolean',
73 + 'default' => true,
74 + 'description' => __( 'Rebuild the served sitemap before returning, so the change is live when this call reports success. Leave it on unless you are making several changes in a row and want to rebuild once at the end, in which case the last call should set it to true.', 'thinkrank' ),
75 + ],
71 76 ],
72 77 'required' => [ 'settings' ],
73 78 ];
74 79 }
@@ -81,10 +86,19 @@
81 86 public function get_output_schema() {
82 87 return [
83 88 'type' => 'object',
84 89 'properties' => [
85 - 'success' => [ 'type' => 'boolean' ],
86 - 'message' => [ 'type' => 'string' ],
90 + 'success' => [ 'type' => 'boolean' ],
91 + 'message' => [ 'type' => 'string' ],
92 + // Whether the SERVED sitemap reflects the change yet. Saving and
93 + // serving are separate steps, and reporting only the save let an
94 + // agent state the exclusion had taken effect while the static
95 + // file still listed the page (#764).
96 + 'rebuilt' => [ 'type' => 'boolean' ],
97 + 'pending_since' => [
98 + 'type' => [ 'integer', 'null' ],
99 + 'description' => __( 'Unix time a rebuild has been outstanding since, when the served sitemap has not caught up.', 'thinkrank' ),
100 + ],
87 101 ],
88 102 ];
89 103 }
90 104
@@ -119,18 +133,50 @@
119 133 }
120 134
121 135 $result = $gen->save_settings( 'site', null, $merged );
122 136
123 - // Rebuild the served sitemap so the change takes effect instead of going
124 - // stale until an unrelated content edit (debounced).
125 - if ( $result ) {
126 - $gen->schedule_regeneration();
137 + if ( ! $result ) {
138 + return [
139 + 'success' => false,
140 + 'message' => __( 'Failed to update sitemap settings.', 'thinkrank' ),
141 + 'rebuilt' => false,
142 + ];
127 143 }
128 144
145 + // Mark the rebuild outstanding either way, so a caller that opts out of
146 + // the synchronous rebuild still converges via cron or the request-time
147 + // takeover, and so a failed rebuild below is retried rather than lost.
148 + $gen->schedule_regeneration();
149 +
150 + $regenerate = ! isset( $input['regenerate'] ) || (bool) $input['regenerate'];
151 +
152 + // Rebuild inline rather than leaving it to WP-Cron. The sitemap is a
153 + // static file on most installs, so nothing re-runs PHP for it; where
154 + // cron does not fire, the old debounced-only path left the served file
155 + // stale indefinitely while this ability had already reported success
156 + // (#764). A settings change is deliberate and infrequent, and the
157 + // rebuild is lock-guarded, so doing it now is the honest thing.
158 + $rebuilt = $regenerate ? $gen->regenerate_sitemap_from_settings() : false;
159 +
160 + $pending_since = Sitemap_Generator::regeneration_pending_since();
161 +
162 + if ( $rebuilt && 0 === $pending_since ) {
163 + return [
164 + 'success' => true,
165 + 'message' => __( 'Sitemap settings updated and the served sitemap was rebuilt.', 'thinkrank' ),
166 + 'rebuilt' => true,
167 + 'pending_since' => null,
168 + ];
169 + }
170 +
171 + // Saved, but the file a crawler fetches does not reflect it yet. Say so
172 + // rather than report a success the caller cannot verify.
129 173 return [
130 - 'success' => (bool) $result,
131 - 'message' => (bool) $result
132 - ? __( 'Sitemap settings updated.', 'thinkrank' )
133 - : __( 'Failed to update sitemap settings.', 'thinkrank' ),
174 + 'success' => true,
175 + 'message' => $regenerate
176 + ? __( 'Sitemap settings updated, but the served sitemap could not be rebuilt yet and still shows the previous contents. It will be retried automatically; purge-caches with the "sitemap" scope forces another attempt.', 'thinkrank' )
177 + : __( 'Sitemap settings updated. The served sitemap has not been rebuilt, as requested; run purge-caches with the "sitemap" scope when you are ready to publish the change.', 'thinkrank' ),
178 + 'rebuilt' => false,
179 + 'pending_since' => $pending_since > 0 ? $pending_since : null,
134 180 ];
135 181 }
136 182 }