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.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-get-schema-settings.php

class-get-schema-settings.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/settings/class-get-schema-settings.php

205 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get schema 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\Schema_Management_System;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank structured-data (schema) settings.
21 *
22 * Schema settings are stored via the Schema_Management_System SEO manager and
23 * cover organization, website, local business, and person markup.
24 */
25 class Get_Schema_Settings extends Ability_Base {
26 /**
27 * Boolean-typed schema keys.
28 */
29 private const BOOL_KEYS = [
30 'enabled',
31 'auto_generate_schema',
32 'rich_snippets_optimization',
33 'auto_deploy',
34 'organization_schema',
35 'knowledge_graph',
36 'website_enable_search',
37 'enable_breadcrumbs_schema',
38 'enable_local_business',
39 ];
40
41 /**
42 * Integer-typed schema keys.
43 */
44 private const INT_KEYS = [
45 'cache_duration',
46 ];
47
48 /**
49 * Array-typed schema keys.
50 */
51 private const ARRAY_KEYS = [
52 'enabled_schema_types',
53 'business_opening_hours',
54 'person_same_as',
55 ];
56
57 /**
58 * String-typed schema keys.
59 */
60 private const STRING_KEYS = [
61 'validation_level',
62 'organization_name',
63 'organization_type',
64 'organization_logo',
65 'organization_url',
66 'organization_description',
67 'organization_social_facebook',
68 'organization_social_twitter',
69 'organization_social_linkedin',
70 'organization_social_instagram',
71 'organization_social_youtube',
72 'organization_social_pinterest',
73 'organization_social_whatsapp',
74 'organization_social_telegram',
75 'organization_contact_type',
76 'organization_contact_phone',
77 'organization_contact_email',
78 'organization_contact_hours',
79 'website_name',
80 'website_url',
81 'website_description',
82 'website_author',
83 'website_search_url',
84 'business_price_range',
85 'business_geo_latitude',
86 'business_geo_longitude',
87 'person_name',
88 'person_job_title',
89 'person_description',
90 'person_image',
91 'person_url',
92 'person_email',
93 'person_telephone',
94 'person_address',
95 'person_birth_date',
96 'person_nationality',
97 'person_works_for',
98 ];
99
100 /**
101 * Constructor.
102 */
103 public function __construct() {
104 $this->id = 'thinkrank/get-schema-settings';
105 $this->label = __( 'Get ThinkRank Schema Settings', 'thinkrank' );
106 $this->description = __( 'Retrieve ThinkRank structured-data (schema) settings, including organization, website, local business, and person markup. Use update-schema-settings to change them.', 'thinkrank' );
107 }
108
109 /**
110 * {@inheritDoc}
111 *
112 * @return array<string, bool|float|string>
113 */
114 public function get_annotations() {
115 return [
116 'readonly' => true,
117 'destructive' => false,
118 'idempotent' => true,
119 'priority' => 1.0,
120 'openWorldHint' => false,
121 ];
122 }
123
124 /**
125 * Build the JSON schema properties for schema settings.
126 *
127 * @return array<string, mixed>
128 */
129 private static function schema_properties() {
130 $props = [];
131
132 foreach ( self::BOOL_KEYS as $key ) {
133 $props[ $key ] = [ 'type' => 'boolean' ];
134 }
135 foreach ( self::INT_KEYS as $key ) {
136 $props[ $key ] = [ 'type' => 'integer' ];
137 }
138 foreach ( self::ARRAY_KEYS as $key ) {
139 $props[ $key ] = [ 'type' => 'array' ];
140 }
141 foreach ( self::STRING_KEYS as $key ) {
142 $props[ $key ] = [ 'type' => 'string' ];
143 }
144
145 return $props;
146 }
147
148 /**
149 * {@inheritDoc}
150 *
151 * @return array<string, mixed>
152 */
153 public function get_input_schema() {
154 return [
155 'type' => 'object',
156 'additionalProperties' => false,
157 'properties' => self::empty_properties(),
158 ];
159 }
160
161 /**
162 * {@inheritDoc}
163 *
164 * @return array<string, mixed>
165 */
166 public function get_output_schema() {
167 return [
168 'type' => 'object',
169 'properties' => [
170 'settings' => [
171 'type' => 'object',
172 'properties' => self::schema_properties(),
173 ],
174 ],
175 ];
176 }
177
178 /**
179 * Execute ability.
180 *
181 * @param array<string, mixed> $input Ability input payload.
182 * @return array<string, mixed>
183 */
184 public function execute( $input ) {
185 $mgr = new Schema_Management_System();
186 $s = $mgr->get_settings( 'site', null );
187
188 $out = [];
189 foreach ( self::BOOL_KEYS as $key ) {
190 $out[ $key ] = (bool) ( $s[ $key ] ?? false );
191 }
192 foreach ( self::INT_KEYS as $key ) {
193 $out[ $key ] = (int) ( $s[ $key ] ?? 0 );
194 }
195 foreach ( self::ARRAY_KEYS as $key ) {
196 $out[ $key ] = isset( $s[ $key ] ) && is_array( $s[ $key ] ) ? array_values( $s[ $key ] ) : [];
197 }
198 foreach ( self::STRING_KEYS as $key ) {
199 $out[ $key ] = (string) ( $s[ $key ] ?? '' );
200 }
201
202 return [ 'settings' => $out ];
203 }
204 }
205