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

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

137 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get global 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
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Retrieves ThinkRank global SEO settings.
20 *
21 * ThinkRank stores global SEO as per-post-type templates in the
22 * `thinkrank_global_seo_settings` option, so this ability optionally filters
23 * by a single post type.
24 */
25 class Get_Global_Settings extends Ability_Base {
26 /**
27 * Option storing per-post-type global SEO templates.
28 */
29 private const OPTION_NAME = 'thinkrank_global_seo_settings';
30
31 /**
32 * Constructor.
33 */
34 public function __construct() {
35 $this->id = 'thinkrank/get-global-settings';
36 $this->label = __( 'Get ThinkRank Global Settings', 'thinkrank' );
37 $this->description = __( 'Retrieve ThinkRank global SEO settings. ThinkRank stores these as per-post-type templates; pass a post type to filter. Use update-global-settings to change them.', 'thinkrank' );
38 }
39
40 /**
41 * {@inheritDoc}
42 *
43 * @return array<string, bool|float|string>
44 */
45 public function get_annotations() {
46 return [
47 'readonly' => true,
48 'destructive' => false,
49 'idempotent' => true,
50 'priority' => 1.0,
51 'openWorldHint' => false,
52 ];
53 }
54
55 /**
56 * {@inheritDoc}
57 *
58 * @return array<string, mixed>
59 */
60 public function get_input_schema() {
61 return [
62 'type' => 'object',
63 'additionalProperties' => false,
64 'properties' => [
65 'post_type' => [
66 'type' => 'string',
67 'description' => __( 'Optional post type slug to return settings for. Omit to return all post-type templates.', 'thinkrank' ),
68 ],
69 ],
70 ];
71 }
72
73 /**
74 * {@inheritDoc}
75 *
76 * @return array<string, mixed>
77 */
78 public function get_output_schema() {
79 return [
80 'type' => 'object',
81 'properties' => [
82 'post_type' => [ 'type' => 'string' ],
83 'settings' => [ 'type' => 'object' ],
84 ],
85 ];
86 }
87
88 /**
89 * Execute ability.
90 *
91 * @param array<string, mixed> $input Ability input payload.
92 * @return array<string, mixed>|\WP_Error
93 */
94 public function execute( $input ) {
95 $all = get_option( self::OPTION_NAME, [] );
96 if ( ! is_array( $all ) ) {
97 $all = [];
98 }
99
100 $post_type = isset( $input['post_type'] ) ? sanitize_key( (string) $input['post_type'] ) : '';
101
102 if ( '' !== $post_type ) {
103 // A slug this ability cannot answer for used to come back as
104 // `settings: {}`, indistinguishable from a real post type with no
105 // templates configured — so "category", "home" and a typo all read
106 // as "nothing set" (#518). Reject it with the same two checks
107 // thinkrank/update-global-settings applies.
108 if ( ! post_type_exists( $post_type ) ) {
109 return new \WP_Error(
110 'thinkrank_invalid_post_type',
111 __( 'A valid post type slug is required.', 'thinkrank' ),
112 [ 'status' => 400 ]
113 );
114 }
115
116 if ( ! \ThinkRank\SEO\Global_SEO_Post_Types::is_allowed( $post_type ) ) {
117 return new \WP_Error(
118 'thinkrank_non_public_post_type',
119 __( 'Global SEO settings are only available for valid Global SEO target post types.', 'thinkrank' ),
120 [ 'status' => 400 ]
121 );
122 }
123
124 $settings = isset( $all[ $post_type ] ) && is_array( $all[ $post_type ] ) ? $all[ $post_type ] : [];
125
126 return [
127 'post_type' => $post_type,
128 'settings' => $settings,
129 ];
130 }
131
132 return [
133 'settings' => $all,
134 ];
135 }
136 }
137