PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.1.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.1.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-image-seo-settings.php

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

128 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get image SEO 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\Image_SEO_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank image SEO settings.
21 *
22 * Controls automatic alt/title injection and the token-based formats used when
23 * generating those attributes, stored via the Image_SEO_Manager SEO manager.
24 */
25 class Get_Image_Seo_Settings extends Ability_Base {
26 /**
27 * Boolean-typed image SEO keys.
28 */
29 private const BOOL_KEYS = [
30 'add_missing_alt',
31 'add_missing_title',
32 'save_alt_to_media',
33 'auto_fill_on_upload',
34 'media_alt_overwrite',
35 ];
36
37 /**
38 * String-typed image SEO keys.
39 */
40 private const STRING_KEYS = [
41 'alt_format',
42 'title_format',
43 ];
44
45 /**
46 * Constructor.
47 */
48 public function __construct() {
49 $this->id = 'thinkrank/get-image-seo-settings';
50 $this->label = __( 'Get ThinkRank Image SEO Settings', 'thinkrank' );
51 $this->description = __( 'Retrieve ThinkRank image SEO settings, which control automatic alt/title injection, the token-based formats used to generate them, and whether generated alt text is persisted to the Media Library.', 'thinkrank' );
52 }
53
54 /**
55 * {@inheritDoc}
56 *
57 * @return array<string, bool|float|string>
58 */
59 public function get_annotations() {
60 return [
61 'readonly' => true,
62 'destructive' => false,
63 'idempotent' => true,
64 'priority' => 1.0,
65 'openWorldHint' => false,
66 ];
67 }
68
69 /**
70 * {@inheritDoc}
71 *
72 * @return array<string, mixed>
73 */
74 public function get_input_schema() {
75 return [
76 'type' => 'object',
77 'additionalProperties' => false,
78 'properties' => self::empty_properties(),
79 ];
80 }
81
82 /**
83 * {@inheritDoc}
84 *
85 * @return array<string, mixed>
86 */
87 public function get_output_schema() {
88 return [
89 'type' => 'object',
90 'properties' => [
91 'settings' => [
92 'type' => 'object',
93 'properties' => [
94 'add_missing_alt' => [ 'type' => 'boolean' ],
95 'alt_format' => [ 'type' => 'string' ],
96 'add_missing_title' => [ 'type' => 'boolean' ],
97 'title_format' => [ 'type' => 'string' ],
98 'save_alt_to_media' => [ 'type' => 'boolean' ],
99 'auto_fill_on_upload' => [ 'type' => 'boolean' ],
100 'media_alt_overwrite' => [ 'type' => 'boolean' ],
101 ],
102 ],
103 ],
104 ];
105 }
106
107 /**
108 * Execute ability.
109 *
110 * @param array<string, mixed> $input Ability input payload.
111 * @return array<string, mixed>
112 */
113 public function execute( $input ) {
114 $mgr = new Image_SEO_Manager();
115 $s = $mgr->get_settings( 'site', null );
116
117 $out = [];
118 foreach ( self::BOOL_KEYS as $key ) {
119 $out[ $key ] = (bool) ( $s[ $key ] ?? false );
120 }
121 foreach ( self::STRING_KEYS as $key ) {
122 $out[ $key ] = (string) ( $s[ $key ] ?? '' );
123 }
124
125 return [ 'settings' => $out ];
126 }
127 }
128