PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.1.1
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.1.1
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 1.10.0 All 48 releases
thinkrank / includes / abilities / settings / class-update-sitemap-settings.php

class-update-sitemap-settings.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 2.1.1, at includes/abilities/settings/class-update-sitemap-settings.php

130 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Update sitemap settings ability.
4 *
5 * @package ThinkRank\Abilities\Settings
6 */
7
8 declare(strict_types=1);
9
10 namespace ThinkRank\Abilities\Settings;
11
12 use ThinkRank\Abilities\Ability_Base;
13 use ThinkRank\SEO\Sitemap_Generator;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Updates ThinkRank XML sitemap settings.
21 *
22 * Sitemap settings are persisted through the Sitemap_Generator SEO manager.
23 */
24 class Update_Sitemap_Settings extends Ability_Base {
25 /**
26 * Constructor.
27 */
28 public function __construct() {
29 $this->id = 'thinkrank/update-sitemap-settings';
30 $this->label = __( 'Update ThinkRank Sitemap Settings', 'thinkrank' );
31 $this->description = __( 'Update ThinkRank XML sitemap settings: per-type inclusion toggles, exclusion lists, and the index/splitting, styling, filename and search-engine ping options. Read the current values with get-sitemap-settings first; only the keys you pass are changed.', 'thinkrank' );
32 }
33
34 /**
35 * {@inheritDoc}
36 *
37 * @return array<string, bool|float|string>
38 */
39 public function get_annotations() {
40 return [
41 'readonly' => false,
42 'destructive' => true,
43 'idempotent' => true,
44 'priority' => 2.0,
45 'openWorldHint' => false,
46 ];
47 }
48
49 /**
50 * {@inheritDoc}
51 *
52 * @return array<string, mixed>
53 */
54 public function get_input_schema() {
55 return [
56 'type' => 'object',
57 'additionalProperties' => false,
58 'properties' => [
59 'settings' => [
60 'type' => 'object',
61 'description' => __( 'Sitemap settings to update.', 'thinkrank' ),
62 'properties' => Settings_Key_Map::sitemap(),
63 ],
64 ],
65 'required' => [ 'settings' ],
66 ];
67 }
68
69 /**
70 * {@inheritDoc}
71 *
72 * @return array<string, mixed>
73 */
74 public function get_output_schema() {
75 return [
76 'type' => 'object',
77 'properties' => [
78 'success' => [ 'type' => 'boolean' ],
79 'message' => [ 'type' => 'string' ],
80 ],
81 ];
82 }
83
84 /**
85 * Execute ability.
86 *
87 * @param array<string, mixed> $input Ability input payload.
88 * @return array<string, mixed>|\WP_Error
89 */
90 public function execute( $input ) {
91 $settings = isset( $input['settings'] ) && is_array( $input['settings'] ) ? $input['settings'] : [];
92
93 if ( empty( $settings ) ) {
94 return new \WP_Error(
95 'thinkrank_missing_sitemap_settings_payload',
96 __( 'A sitemap settings payload is required.', 'thinkrank' ),
97 [ 'status' => 400 ]
98 );
99 }
100
101 $gen = new Sitemap_Generator();
102 $merged = $gen->get_settings( 'site', null );
103 $patch = Settings_Key_Map::coerce( Settings_Key_Map::sitemap(), $settings );
104 $merged = array_merge( $merged, $patch );
105
106 if ( empty( $patch ) ) {
107 return new \WP_Error(
108 'thinkrank_no_valid_sitemap_setting_keys',
109 __( 'No valid sitemap setting keys were provided.', 'thinkrank' ),
110 [ 'status' => 400 ]
111 );
112 }
113
114 $result = $gen->save_settings( 'site', null, $merged );
115
116 // Rebuild the served sitemap so the change takes effect instead of going
117 // stale until an unrelated content edit (debounced).
118 if ( $result ) {
119 $gen->schedule_regeneration();
120 }
121
122 return [
123 'success' => (bool) $result,
124 'message' => (bool) $result
125 ? __( 'Sitemap settings updated.', 'thinkrank' )
126 : __( 'Failed to update sitemap settings.', 'thinkrank' ),
127 ];
128 }
129 }
130