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-update-robots-txt.php

class-update-robots-txt.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-update-robots-txt.php

113 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Update robots.txt 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\Site_Identity_Manager;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Updates the custom robots.txt content managed by ThinkRank.
21 */
22 class Update_Robots_Txt extends Ability_Base {
23 /**
24 * Constructor.
25 */
26 public function __construct() {
27 $this->id = 'thinkrank/update-robots-txt';
28 $this->label = __( 'Update ThinkRank Robots.txt', 'thinkrank' );
29 $this->description = __( 'Replace the robots.txt served to crawlers with custom content. This overrides ThinkRank\'s auto-generated rules entirely, so fetch get-robots-txt first and edit its "rendered" output to avoid dropping the default wp-admin/sitemap directives. Pass an empty string to revert to the auto-generated defaults.', 'thinkrank' );
30 }
31
32 /**
33 * {@inheritDoc}
34 *
35 * @return array<string, bool|float|string>
36 */
37 public function get_annotations() {
38 return [
39 'readonly' => false,
40 'destructive' => true,
41 'idempotent' => true,
42 'priority' => 2.0,
43 'openWorldHint' => false,
44 ];
45 }
46
47 /**
48 * {@inheritDoc}
49 *
50 * @return array<string, mixed>
51 */
52 public function get_input_schema() {
53 return [
54 'type' => 'object',
55 'additionalProperties' => false,
56 'properties' => [
57 'content' => [
58 'type' => 'string',
59 'description' => __( 'The full robots.txt content to serve. Replaces the generated defaults entirely; seed it from get-robots-txt\'s "rendered" field so default directives are preserved. Pass an empty string to restore auto-generation.', 'thinkrank' ),
60 ],
61 ],
62 'required' => [ 'content' ],
63 ];
64 }
65
66 /**
67 * {@inheritDoc}
68 *
69 * @return array<string, mixed>
70 */
71 public function get_output_schema() {
72 return [
73 'type' => 'object',
74 'properties' => [
75 'success' => [ 'type' => 'boolean' ],
76 'content' => [ 'type' => 'string' ],
77 'rendered' => [
78 'type' => 'string',
79 'description' => __( 'The effective robots.txt now served to crawlers after this update.', 'thinkrank' ),
80 ],
81 ],
82 ];
83 }
84
85 /**
86 * Execute ability.
87 *
88 * @param array<string, mixed> $input Ability input payload.
89 * @return array<string, mixed>
90 */
91 public function execute( $input ) {
92 $content = isset( $input['content'] ) ? sanitize_textarea_field( (string) $input['content'] ) : '';
93
94 $mgr = new Site_Identity_Manager();
95 $updated = $mgr->get_settings( 'site', null );
96
97 $updated['robots_txt_content'] = $content;
98 $updated['robots_txt_enabled'] = true;
99
100 $result = $mgr->save_settings( 'site', null, $updated );
101
102 // Keep the physical robots.txt in step with the saved override so the
103 // change is served immediately, matching a Save from the admin screen.
104 $mgr->sync_robots_txt_file();
105
106 return [
107 'success' => (bool) $result,
108 'content' => $content,
109 'rendered' => (string) $mgr->get_effective_robots_txt()['content'],
110 ];
111 }
112 }
113