HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/hcv/wp-content/plugins/wordpress-seo-premium/src/routes/link-suggestions-route.php
<?php

namespace Yoast\WP\SEO\Premium\Routes;

use WP_REST_Request;
use WP_REST_Response;
use Yoast\WP\SEO\Conditionals\No_Conditionals;
use Yoast\WP\SEO\Main;
use Yoast\WP\SEO\Premium\Actions\Link_Suggestions_Action;
use Yoast\WP\SEO\Routes\Route_Interface;

/**
 * Registers the route for the link suggestions retrieval.
 */
class Link_Suggestions_Route implements Route_Interface {

	use No_Conditionals;

	/**
	 * Represents the endpoint.
	 *
	 * @var string
	 */
	const ENDPOINT_QUERY = 'link_suggestions';

	/**
	 * Instance of the Link_Suggestions_Action.
	 *
	 * @var Link_Suggestions_Action
	 */
	protected $link_suggestions_action;

	/**
	 * Link_Suggestions_Route constructor.
	 *
	 * @param Link_Suggestions_Action $link_suggestions_action The action to handle the requests to the endpoint.
	 */
	public function __construct( Link_Suggestions_Action $link_suggestions_action ) {
		$this->link_suggestions_action = $link_suggestions_action;
	}

	/**
	 * Registers routes with WordPress.
	 *
	 * @return void
	 */
	public function register_routes() {
		$route_args = [
			'methods'             => 'GET',
			'args'                => [
				'prominent_words' => [
					'required'    => true,
					'type'        => 'object',
					'description' => 'Stems of prominent words and their term frequencies we want link suggestions based on',
				],
				'object_id'       => [
					'required'    => true,
					'type'        => 'integer',
					'description' => 'The object id of the current indexable.',
				],
				'object_type'     => [
					'required'    => true,
					'type'        => 'string',
					'description' => 'The object type of the current indexable.',
				],
				'limit'           => [
					'required'    => false,
					'default'     => 5,
					'type'        => 'integer',
					'description' => 'The maximum number of link suggestions to retrieve',
				],
			],
			'callback'            => [ $this, 'run_get_suggestions_action' ],
			'permission_callback' => [ $this, 'can_retrieve_data' ],
		];
		\register_rest_route( Main::API_V1_NAMESPACE, self::ENDPOINT_QUERY, $route_args );
	}

	/**
	 * Runs the get suggestions action..
	 *
	 * @param WP_REST_Request $request The request object.
	 *
	 * @return WP_REST_Response The response for the query of link suggestions.
	 */
	public function run_get_suggestions_action( WP_REST_Request $request ) {
		$prominent_words = $request->get_param( 'prominent_words' );
		$limit           = $request->get_param( 'limit' );
		$object_id       = $request->get_param( 'object_id' );
		$object_type     = $request->get_param( 'object_type' );
		$post_type       = $request->get_param( 'post_type' );

		return new WP_REST_Response(
			$this->link_suggestions_action->get_suggestions(
				$prominent_words,
				$limit,
				$object_id,
				$object_type,
				true,
				$post_type
			)
		);
	}

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