PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.14.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.14.0
2.14.0 2.13.0 2.12.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 All 55 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.14.0, at includes/abilities/settings/class-get-schema-settings.php

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