| Server IP : 146.59.209.152 / Your IP : 216.73.216.152 Web Server : Apache System : Linux webm009.cluster131.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : monpetu ( 144298) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/monpetu/www/ipprint/wp-content/plugins/surerank/inc/api/ |
Upload File : |
<?php
/**
* RobotsTxt class
*
* Handles installed products related REST API endpoints for the SureRank plugin.
*
* @package SureRank\Inc\API
*/
namespace SureRank\Inc\API;
use SureRank\Inc\Functions\Send_Json;
use SureRank\Inc\Traits\Get_Instance;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Class RobotsTxt
*
* Handles robots.txt related REST API endpoints.
*/
class RobotsTxt extends Api_Base {
use Get_Instance;
/**
* Route Get Robots.txt
*/
protected const ROBOTS_TXT = '/robots-txt';
/**
* Register API routes.
*
* @since 1.2.0
* @return void
*/
public function register_routes() {
register_rest_route(
$this->get_api_namespace(),
self::ROBOTS_TXT,
[
'methods' => WP_REST_Server::CREATABLE, // POST method.
'callback' => [ $this, 'update_robots_txt' ],
'permission_callback' => [ $this, 'validate_permission' ],
'args' => [
'robots_txt_content' => [
'required' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_textarea_field',
],
],
'role_capability' => 'global_setting',
]
);
}
/**
* Update the robots.txt content.
*
* @param \WP_REST_Request<array<string, mixed>> $request Request object.
* @return void
*/
public function update_robots_txt( $request ) {
$robots_content = $request->get_param( 'robots_txt_content' );
$robots_content = sanitize_textarea_field( $robots_content );
update_option( SURERANK_ROBOTS_TXT_CONTENT, $robots_content );
Send_Json::success(
[
'success' => true,
'data' => [
'robots_txt_content' => $robots_content,
],
]
);
}
}