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

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

150 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get llms.txt 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\LLMs_Txt_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Retrieves ThinkRank llms.txt settings.
21 *
22 * These settings feed the AI-oriented llms.txt file describing the site to
23 * language models, stored via the LLMs_Txt_Manager SEO manager.
24 */
25 class Get_Llms_Txt_Settings extends Ability_Base {
26 /**
27 * Boolean-typed llms.txt keys.
28 */
29 private const BOOL_KEYS = [
30 'enabled',
31 'auto_generate',
32 ];
33
34 /**
35 * String-typed llms.txt keys.
36 */
37 private const STRING_KEYS = [
38 'delivery_mode',
39 'site_name',
40 'website_description',
41 'key_features',
42 'target_audience',
43 'business_type',
44 'technical_stack',
45 'development_approach',
46 'setup_instructions',
47 'ai_context_custom',
48 'documentation_links',
49 'technical_links',
50 'optional_links',
51 'custom_sections',
52 ];
53
54 /**
55 * Constructor.
56 */
57 public function __construct() {
58 $this->id = 'thinkrank/get-llms-txt-settings';
59 $this->label = __( 'Get ThinkRank llms.txt Settings', 'thinkrank' );
60 $this->description = __( 'Retrieve ThinkRank llms.txt settings, which describe the site to AI language models via the llms.txt file.', 'thinkrank' );
61 }
62
63 /**
64 * {@inheritDoc}
65 *
66 * @return array<string, bool|float|string>
67 */
68 public function get_annotations() {
69 return [
70 'readonly' => true,
71 'destructive' => false,
72 'idempotent' => true,
73 'priority' => 1.0,
74 'openWorldHint' => false,
75 ];
76 }
77
78 /**
79 * Build the JSON schema properties for llms.txt settings.
80 *
81 * @return array<string, mixed>
82 */
83 private static function schema_properties() {
84 $props = [];
85
86 foreach ( self::BOOL_KEYS as $key ) {
87 $props[ $key ] = [ 'type' => 'boolean' ];
88 }
89 foreach ( self::STRING_KEYS as $key ) {
90 $props[ $key ] = [ 'type' => 'string' ];
91 }
92
93 $props['delivery_mode']['enum'] = [ 'auto', 'static', 'dynamic' ];
94 $props['delivery_mode']['description'] = __( 'How /llms.txt is served: "static" writes a physical file the web server answers, "dynamic" keeps the document in WordPress and serves it from PHP as UTF-8, "auto" picks static on Apache/LiteSpeed and dynamic elsewhere.', 'thinkrank' );
95
96 return $props;
97 }
98
99 /**
100 * {@inheritDoc}
101 *
102 * @return array<string, mixed>
103 */
104 public function get_input_schema() {
105 return [
106 'type' => 'object',
107 'additionalProperties' => false,
108 'properties' => self::empty_properties(),
109 ];
110 }
111
112 /**
113 * {@inheritDoc}
114 *
115 * @return array<string, mixed>
116 */
117 public function get_output_schema() {
118 return [
119 'type' => 'object',
120 'properties' => [
121 'settings' => [
122 'type' => 'object',
123 'properties' => self::schema_properties(),
124 ],
125 ],
126 ];
127 }
128
129 /**
130 * Execute ability.
131 *
132 * @param array<string, mixed> $input Ability input payload.
133 * @return array<string, mixed>
134 */
135 public function execute( $input ) {
136 $mgr = new LLMs_Txt_Manager();
137 $s = $mgr->get_settings( 'site', null );
138
139 $out = [];
140 foreach ( self::BOOL_KEYS as $key ) {
141 $out[ $key ] = (bool) ( $s[ $key ] ?? false );
142 }
143 foreach ( self::STRING_KEYS as $key ) {
144 $out[ $key ] = (string) ( $s[ $key ] ?? '' );
145 }
146
147 return [ 'settings' => $out ];
148 }
149 }
150