PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.3.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.3.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-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.3.0, at includes/abilities/settings/class-get-social-meta-settings.php

177 lines 3.8 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 'auto_generate_descriptions',
39 'fallback_to_excerpt',
40 'strip_html_tags',
41 'image_optimization',
42 'auto_generate',
43 ];
44
45 /**
46 * Integer-typed social meta keys.
47 */
48 private const INT_KEYS = [
49 'og_image_width',
50 'og_image_height',
51 'max_description_length',
52 ];
53
54 /**
55 * String-typed social meta keys.
56 */
57 private const STRING_KEYS = [
58 'og_site_name',
59 'og_description',
60 'og_type',
61 'og_locale',
62 'default_og_image',
63 'twitter_username',
64 'twitter_creator',
65 'twitter_card_type',
66 'default_twitter_image',
67 'twitter_site',
68 'default_image',
69 'facebook_app_id',
70 'facebook_admins',
71 'pinterest_site_verification',
72 'instagram_verification',
73 'tiktok_verification',
74 'youtube_channel_id',
75 'whatsapp_business_id',
76 ];
77
78 /**
79 * Constructor.
80 */
81 public function __construct() {
82 $this->id = 'thinkrank/get-social-meta-settings';
83 $this->label = __( 'Get ThinkRank Social Meta Settings', 'thinkrank' );
84 $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' );
85 }
86
87 /**
88 * {@inheritDoc}
89 *
90 * @return array<string, bool|float|string>
91 */
92 public function get_annotations() {
93 return [
94 'readonly' => true,
95 'destructive' => false,
96 'idempotent' => true,
97 'priority' => 1.0,
98 'openWorldHint' => false,
99 ];
100 }
101
102 /**
103 * Build the JSON schema properties for social meta settings.
104 *
105 * @return array<string, mixed>
106 */
107 private static function schema_properties() {
108 $props = [];
109
110 foreach ( self::BOOL_KEYS as $key ) {
111 $props[ $key ] = [ 'type' => 'boolean' ];
112 }
113 foreach ( self::INT_KEYS as $key ) {
114 $props[ $key ] = [ 'type' => 'integer' ];
115 }
116 foreach ( self::STRING_KEYS as $key ) {
117 $props[ $key ] = [ 'type' => 'string' ];
118 }
119
120 return $props;
121 }
122
123 /**
124 * {@inheritDoc}
125 *
126 * @return array<string, mixed>
127 */
128 public function get_input_schema() {
129 return [
130 'type' => 'object',
131 'additionalProperties' => false,
132 'properties' => self::empty_properties(),
133 ];
134 }
135
136 /**
137 * {@inheritDoc}
138 *
139 * @return array<string, mixed>
140 */
141 public function get_output_schema() {
142 return [
143 'type' => 'object',
144 'properties' => [
145 'settings' => [
146 'type' => 'object',
147 'properties' => self::schema_properties(),
148 ],
149 ],
150 ];
151 }
152
153 /**
154 * Execute ability.
155 *
156 * @param array<string, mixed> $input Ability input payload.
157 * @return array<string, mixed>
158 */
159 public function execute( $input ) {
160 $mgr = new Social_Meta_Manager();
161 $s = $mgr->get_settings( 'site', null );
162
163 $out = [];
164 foreach ( self::BOOL_KEYS as $key ) {
165 $out[ $key ] = (bool) ( $s[ $key ] ?? false );
166 }
167 foreach ( self::INT_KEYS as $key ) {
168 $out[ $key ] = (int) ( $s[ $key ] ?? 0 );
169 }
170 foreach ( self::STRING_KEYS as $key ) {
171 $out[ $key ] = (string) ( $s[ $key ] ?? '' );
172 }
173
174 return [ 'settings' => $out ];
175 }
176 }
177