*/ protected function input_properties(): array { return array( 'content' => array( 'type' => 'string', 'description' => __( 'Full robots.txt content. Line breaks are preserved. Replaces the existing content entirely.', 'acrossai-abilities-manager' ), ), ); } /** * @return array */ protected function output_properties(): array { return array( 'content' => array( 'type' => 'string' ), 'state' => array( 'type' => 'object' ), ); } /** * @return string[] */ protected function required_input(): array { return array( 'content' ); } /** * @return array{readonly:bool,destructive:bool,idempotent:bool} */ protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { if ( ! isset( $input['content'] ) || ! is_string( $input['content'] ) ) { return new WP_Error( 'invalid_input', __( 'content must be a string.', 'acrossai-abilities-manager' ) ); } $physical = ABSPATH . 'robots.txt'; if ( file_exists( $physical ) ) { return new WP_Error( 'invalid_input', sprintf( /* translators: %s: absolute path to the physical robots.txt */ __( 'A physical robots.txt exists at %s and overrides the virtual one, so this write would have no effect. Remove the file first.', 'acrossai-abilities-manager' ), $physical ) ); } if ( ! get_option( 'blog_public' ) ) { return new WP_Error( 'invalid_input', __( 'The site is set to discourage search engines, so Rank Math suppresses robots.txt output. Enable search-engine visibility in Settings → Reading first.', 'acrossai-abilities-manager' ) ); } $result = Settings_Writer::save( 'general-robots-txt', '', array( 'robots_txt_content' => $input['content'] ) ); if ( is_wp_error( $result ) ) { return $result; } return array( 'content' => (string) ( $result['updated']['robots_txt_content'] ?? '' ), 'state' => array( 'editable' => true, 'physical_file_exists' => false, 'site_not_public' => false, ), 'message' => __( 'Updated the Rank Math virtual robots.txt.', 'acrossai-abilities-manager' ), ); } }