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

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

181 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Update site identity 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\Site_Identity_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Updates ThinkRank site identity settings.
21 *
22 * Only the non-robots identity keys are writable here. The robots.txt keys
23 * (robots_txt_enabled, allow_search_engines, robots_txt_content) are never
24 * touched so this ability cannot clobber the robots.txt configuration.
25 */
26 class Update_Site_Identity_Settings extends Ability_Base {
27 /**
28 * Boolean-typed site identity keys.
29 */
30 private const BOOL_KEYS = [
31 'enabled',
32 'breadcrumbs_enabled',
33 ];
34
35 /**
36 * String-typed site identity keys.
37 */
38 private const STRING_KEYS = [
39 'title_template',
40 'title_separator',
41 'site_name',
42 'site_description',
43 'tagline',
44 'breadcrumb_type',
45 'breadcrumb_home_text',
46 'breadcrumb_separator',
47 'logo_url',
48 'favicon_url',
49 'apple_touch_icon_url',
50 ];
51
52 /**
53 * Constructor.
54 */
55 public function __construct() {
56 $this->id = 'thinkrank/update-site-identity-settings';
57 $this->label = __( 'Update ThinkRank Site Identity Settings', 'thinkrank' );
58 $this->description = __( 'Update ThinkRank site identity settings: title templates, site name/description, breadcrumb configuration, and brand imagery. Robots.txt configuration is never modified by this ability.', 'thinkrank' );
59 }
60
61 /**
62 * {@inheritDoc}
63 *
64 * @return array<string, bool|float|string>
65 */
66 public function get_annotations() {
67 return [
68 'readonly' => false,
69 'destructive' => true,
70 'idempotent' => true,
71 'priority' => 2.0,
72 'openWorldHint' => false,
73 ];
74 }
75
76 /**
77 * Build the JSON schema properties for site identity settings.
78 *
79 * @return array<string, mixed>
80 */
81 private static function schema_properties() {
82 $props = [];
83
84 foreach ( self::BOOL_KEYS as $key ) {
85 $props[ $key ] = [ 'type' => 'boolean' ];
86 }
87 foreach ( self::STRING_KEYS as $key ) {
88 $props[ $key ] = [ 'type' => 'string' ];
89 }
90
91 return $props;
92 }
93
94 /**
95 * {@inheritDoc}
96 *
97 * @return array<string, mixed>
98 */
99 public function get_input_schema() {
100 return [
101 'type' => 'object',
102 'additionalProperties' => false,
103 'properties' => [
104 'settings' => [
105 'type' => 'object',
106 'description' => __( 'Site identity settings to update.', 'thinkrank' ),
107 'properties' => self::schema_properties(),
108 ],
109 ],
110 'required' => [ 'settings' ],
111 ];
112 }
113
114 /**
115 * {@inheritDoc}
116 *
117 * @return array<string, mixed>
118 */
119 public function get_output_schema() {
120 return [
121 'type' => 'object',
122 'properties' => [
123 'success' => [ 'type' => 'boolean' ],
124 'message' => [ 'type' => 'string' ],
125 ],
126 ];
127 }
128
129 /**
130 * Execute ability.
131 *
132 * @param array<string, mixed> $input Ability input payload.
133 * @return array<string, mixed>|\WP_Error
134 */
135 public function execute( $input ) {
136 $settings = isset( $input['settings'] ) && is_array( $input['settings'] ) ? $input['settings'] : [];
137
138 if ( empty( $settings ) ) {
139 return new \WP_Error(
140 'thinkrank_missing_site_identity_settings_payload',
141 __( 'A site identity settings payload is required.', 'thinkrank' ),
142 [ 'status' => 400 ]
143 );
144 }
145
146 $mgr = new Site_Identity_Manager();
147 $merged = $mgr->get_settings( 'site', null );
148 $found = false;
149
150 foreach ( self::BOOL_KEYS as $key ) {
151 if ( array_key_exists( $key, $settings ) ) {
152 $merged[ $key ] = (bool) $settings[ $key ];
153 $found = true;
154 }
155 }
156 foreach ( self::STRING_KEYS as $key ) {
157 if ( array_key_exists( $key, $settings ) ) {
158 $merged[ $key ] = sanitize_text_field( (string) $settings[ $key ] );
159 $found = true;
160 }
161 }
162
163 if ( ! $found ) {
164 return new \WP_Error(
165 'thinkrank_no_valid_site_identity_setting_keys',
166 __( 'No valid site identity setting keys were provided.', 'thinkrank' ),
167 [ 'status' => 400 ]
168 );
169 }
170
171 $result = $mgr->save_settings( 'site', null, $merged );
172
173 return [
174 'success' => (bool) $result,
175 'message' => (bool) $result
176 ? __( 'Site identity settings updated.', 'thinkrank' )
177 : __( 'Failed to update site identity settings.', 'thinkrank' ),
178 ];
179 }
180 }
181