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.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 1.0.1 All 51 releases
thinkrank / includes / abilities / settings / class-get-social-meta-settings.php

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

181 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get social meta 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\Social_Meta_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank social meta settings.
21 *
22 * Covers Open Graph, Twitter Cards, and per-network verification/handle
23 * configuration stored via the Social_Meta_Manager SEO manager.
24 */
25 class Get_Social_Meta_Settings extends Ability_Base {
26 /**
27 * Boolean-typed social meta keys.
28 */
29 private const BOOL_KEYS = [
30 'enable_open_graph',
31 'enable_twitter_cards',
32 'enable_linkedin',
33 'enable_pinterest',
34 'enable_instagram',
35 'enable_tiktok',
36 'enable_youtube',
37 'enable_whatsapp',
38 'og_multiple_images',
39 'oembed_use_seo_title',
40 'oembed_use_social_image',
41 'oembed_remove_author',
42 'auto_generate_descriptions',
43 'fallback_to_excerpt',
44 'strip_html_tags',
45 'image_optimization',
46 'auto_generate',
47 ];
48
49 /**
50 * Integer-typed social meta keys.
51 */
52 private const INT_KEYS = [
53 'og_image_width',
54 'og_image_height',
55 'max_description_length',
56 ];
57
58 /**
59 * String-typed social meta keys.
60 */
61 private const STRING_KEYS = [
62 'og_site_name',
63 'og_description',
64 'og_type',
65 'og_locale',
66 'default_og_image',
67 'twitter_username',
68 'twitter_creator',
69 'twitter_card_type',
70 'default_twitter_image',
71 'twitter_site',
72 'default_image',
73 'facebook_app_id',
74 'facebook_admins',
75 'pinterest_site_verification',
76 'instagram_verification',
77 'tiktok_verification',
78 'youtube_channel_id',
79 'whatsapp_business_id',
80 ];
81
82 /**
83 * Constructor.
84 */
85 public function __construct() {
86 $this->id = 'thinkrank/get-social-meta-settings';
87 $this->label = __( 'Get ThinkRank Social Meta Settings', 'thinkrank' );
88 $this->description = __( 'Retrieve ThinkRank social meta settings, covering Open Graph, Twitter Cards, and per-network verification and handle configuration. Use update-social-meta-settings to change them.', 'thinkrank' );
89 }
90
91 /**
92 * {@inheritDoc}
93 *
94 * @return array<string, bool|float|string>
95 */
96 public function get_annotations() {
97 return [
98 'readonly' => true,
99 'destructive' => false,
100 'idempotent' => true,
101 'priority' => 1.0,
102 'openWorldHint' => false,
103 ];
104 }
105
106 /**
107 * Build the JSON schema properties for social meta settings.
108 *
109 * @return array<string, mixed>
110 */
111 private static function schema_properties() {
112 $props = [];
113
114 foreach ( self::BOOL_KEYS as $key ) {
115 $props[ $key ] = [ 'type' => 'boolean' ];
116 }
117 foreach ( self::INT_KEYS as $key ) {
118 $props[ $key ] = [ 'type' => 'integer' ];
119 }
120 foreach ( self::STRING_KEYS as $key ) {
121 $props[ $key ] = [ 'type' => 'string' ];
122 }
123
124 return $props;
125 }
126
127 /**
128 * {@inheritDoc}
129 *
130 * @return array<string, mixed>
131 */
132 public function get_input_schema() {
133 return [
134 'type' => 'object',
135 'additionalProperties' => false,
136 'properties' => self::empty_properties(),
137 ];
138 }
139
140 /**
141 * {@inheritDoc}
142 *
143 * @return array<string, mixed>
144 */
145 public function get_output_schema() {
146 return [
147 'type' => 'object',
148 'properties' => [
149 'settings' => [
150 'type' => 'object',
151 'properties' => self::schema_properties(),
152 ],
153 ],
154 ];
155 }
156
157 /**
158 * Execute ability.
159 *
160 * @param array<string, mixed> $input Ability input payload.
161 * @return array<string, mixed>
162 */
163 public function execute( $input ) {
164 $mgr = new Social_Meta_Manager();
165 $s = $mgr->get_settings( 'site', null );
166
167 $out = [];
168 foreach ( self::BOOL_KEYS as $key ) {
169 $out[ $key ] = (bool) ( $s[ $key ] ?? false );
170 }
171 foreach ( self::INT_KEYS as $key ) {
172 $out[ $key ] = (int) ( $s[ $key ] ?? 0 );
173 }
174 foreach ( self::STRING_KEYS as $key ) {
175 $out[ $key ] = (string) ( $s[ $key ] ?? '' );
176 }
177
178 return [ 'settings' => $out ];
179 }
180 }
181