HEX
Server: Apache/2.2.22
System: Linux server1.blueharbor.com 3.10.0-1160.90.1.vz7.200.7 #1 SMP Wed Jul 12 12:00:44 MSK 2023 x86_64
User: locglobe (1004)
PHP: 5.6.37
Disabled: NONE
Upload Files
File: //proc/self/cwd/wp-content/plugins/wordpress-seo/admin/links/class-link-reindex-post-endpoint.php
<?php
/**
 * @package WPSEO\Admin\Links\Reindex
 */

/**
 * Class WPSEO_Link_Reindex_Post_Endpoint
 */
class WPSEO_Link_Reindex_Post_Endpoint {

	const REST_NAMESPACE = 'yoast/v1';
	const ENDPOINT_QUERY = 'reindex_posts';

	const CAPABILITY_RETRIEVE = 'edit_posts';

	/** @var WPSEO_Link_Reindex_Post_Service */
	protected $service;

	/**
	 * WPSEO_Link_Reindex_Post_Endpoint constructor.
	 *
	 * @param WPSEO_Link_Reindex_Post_Service $service The service to handle the requests to the endpoint.
	 */
	public function __construct( WPSEO_Link_Reindex_Post_Service $service ) {
		$this->service = $service;
	}

	/**
	 * Register the REST endpoint to WordPress.
	 */
	public function register() {
		register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_QUERY, array(
			'methods'             => 'GET',
			'callback'            => array(
				$this->service,
				'reindex',
			),
			'permission_callback' => array(
				$this,
				'can_retrieve_data',
			),
		) );
	}

	/**
	 * Determines if the current user is allowed to use this endpoint.
	 *
	 * @return bool
	 */
	public function can_retrieve_data() {
		return current_user_can( self::CAPABILITY_RETRIEVE );
	}
}