PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 1.28.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v1.28.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-platforms-settings.php

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

151 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 platforms 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\Core\Settings;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank social platform verification settings.
21 *
22 * Mirrors `GET /thinkrank/v1/social-platforms/settings`: returns the public
23 * platform IDs (Facebook app id/admins, YouTube channel, WhatsApp business id)
24 * verbatim and the sensitive site-verification codes (Pinterest, Instagram,
25 * TikTok) masked to a "first four + XXXX" preview so full codes are never
26 * exposed to an AI client. Read-only.
27 */
28 class Get_Social_Platforms_Settings extends Ability_Base {
29 /**
30 * Public platform IDs returned verbatim.
31 */
32 private const PUBLIC_KEYS = [
33 'facebook_app_id',
34 'facebook_admins',
35 'youtube_channel_id',
36 'whatsapp_business_id',
37 ];
38
39 /**
40 * Sensitive verification codes returned masked.
41 */
42 private const SENSITIVE_KEYS = [
43 'pinterest_site_verification',
44 'instagram_verification',
45 'tiktok_verification',
46 ];
47
48 /**
49 * Constructor.
50 */
51 public function __construct() {
52 $this->id = 'thinkrank/get-social-platforms-settings';
53 $this->label = __( 'Get ThinkRank Social Platform Settings', 'thinkrank' );
54 $this->description = __( 'Retrieve ThinkRank social platform verification settings: public platform IDs (Facebook, YouTube, WhatsApp) verbatim and sensitive site-verification codes (Pinterest, Instagram, TikTok) masked for security.', 'thinkrank' );
55 }
56
57 /**
58 * {@inheritDoc}
59 *
60 * @return array<string, bool|float|string>
61 */
62 public function get_annotations() {
63 return [
64 'readonly' => true,
65 'destructive' => false,
66 'idempotent' => true,
67 'priority' => 1.0,
68 'openWorldHint' => false,
69 ];
70 }
71
72 /**
73 * {@inheritDoc}
74 *
75 * @return array<string, mixed>
76 */
77 public function get_input_schema() {
78 return [
79 'type' => 'object',
80 'additionalProperties' => false,
81 'properties' => [],
82 ];
83 }
84
85 /**
86 * {@inheritDoc}
87 *
88 * @return array<string, mixed>
89 */
90 public function get_output_schema() {
91 return [
92 'type' => 'object',
93 'properties' => [
94 'settings' => [
95 'type' => 'object',
96 'description' => __( 'Social platform IDs (verbatim) and verification codes (masked).', 'thinkrank' ),
97 'properties' => [
98 'facebook_app_id' => [ 'type' => 'string' ],
99 'facebook_admins' => [ 'type' => 'string' ],
100 'youtube_channel_id' => [ 'type' => 'string' ],
101 'whatsapp_business_id' => [ 'type' => 'string' ],
102 'pinterest_site_verification' => [ 'type' => 'string' ],
103 'instagram_verification' => [ 'type' => 'string' ],
104 'tiktok_verification' => [ 'type' => 'string' ],
105 ],
106 'additionalProperties' => false,
107 ],
108 ],
109 ];
110 }
111
112 /**
113 * Execute ability.
114 *
115 * @param array<string, mixed> $input Ability input payload.
116 * @return array<string, mixed>
117 */
118 public function execute( $input ) {
119 $settings = Settings::instance();
120 $out = [];
121
122 foreach ( self::PUBLIC_KEYS as $key ) {
123 $out[ $key ] = (string) $settings->get( $key, '' );
124 }
125
126 foreach ( self::SENSITIVE_KEYS as $key ) {
127 $out[ $key ] = $this->mask_verification_code( (string) $settings->get( $key, '' ) );
128 }
129
130 return [ 'settings' => $out ];
131 }
132
133 /**
134 * Mask a verification code: first four chars + "XXXX", or "XXXX" when short.
135 *
136 * @param string $code Raw verification code.
137 * @return string Masked code, or empty string when unset.
138 */
139 private function mask_verification_code( string $code ): string {
140 if ( '' === $code ) {
141 return '';
142 }
143
144 if ( strlen( $code ) > 8 ) {
145 return substr( $code, 0, 4 ) . 'XXXX';
146 }
147
148 return 'XXXX';
149 }
150 }
151