no wp
This commit is contained in:
@@ -1,113 +0,0 @@
|
||||
<?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' );
|
||||
}
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Premium\Routes;
|
||||
|
||||
use Exception;
|
||||
use WP_Error;
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
use Yoast\WP\SEO\Actions\Indexing\Indexation_Action_Interface;
|
||||
use Yoast\WP\SEO\Conditionals\No_Conditionals;
|
||||
use Yoast\WP\SEO\Config\Indexing_Reasons;
|
||||
use Yoast\WP\SEO\Helpers\Indexing_Helper;
|
||||
use Yoast\WP\SEO\Main;
|
||||
use Yoast\WP\SEO\Premium\Actions\Prominent_Words\Complete_Action;
|
||||
use Yoast\WP\SEO\Premium\Actions\Prominent_Words\Content_Action;
|
||||
use Yoast\WP\SEO\Premium\Actions\Prominent_Words\Save_Action;
|
||||
use Yoast\WP\SEO\Routes\Abstract_Indexation_Route;
|
||||
|
||||
/**
|
||||
* Class Prominent_Words_Route.
|
||||
*/
|
||||
class Prominent_Words_Route extends Abstract_Indexation_Route {
|
||||
|
||||
use No_Conditionals;
|
||||
|
||||
/**
|
||||
* Feature namespace for the REST endpoint.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FEATURE_NAMESPACE = 'prominent_words';
|
||||
|
||||
/**
|
||||
* The get content route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const GET_CONTENT_ROUTE = self::FEATURE_NAMESPACE . '/get_content';
|
||||
|
||||
/**
|
||||
* The full content route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FULL_GET_CONTENT_ROUTE = Main::API_V1_NAMESPACE . '/' . self::GET_CONTENT_ROUTE;
|
||||
|
||||
/**
|
||||
* The route for saving the prominent words.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SAVE_ROUTE = self::FEATURE_NAMESPACE . '/save';
|
||||
|
||||
/**
|
||||
* The full namespaced route for saving the prominent words.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FULL_SAVE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::SAVE_ROUTE;
|
||||
|
||||
/**
|
||||
* The posts data route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const COMPLETE_ROUTE = self::FEATURE_NAMESPACE . '/complete';
|
||||
|
||||
/**
|
||||
* The full post data route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const FULL_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::COMPLETE_ROUTE;
|
||||
|
||||
/**
|
||||
* Represents that action that retrieves the content to index.
|
||||
*
|
||||
* @var Content_Action
|
||||
*/
|
||||
protected $content_action;
|
||||
|
||||
/**
|
||||
* The action to complete the prominent words indexing.
|
||||
*
|
||||
* @var Complete_Action
|
||||
*/
|
||||
protected $complete_action;
|
||||
|
||||
/**
|
||||
* The action for saving prominent words to an indexable.
|
||||
*
|
||||
* @var Save_Action
|
||||
*/
|
||||
protected $save_action;
|
||||
|
||||
/**
|
||||
* The indexing helper.
|
||||
*
|
||||
* @var Indexing_Helper
|
||||
*/
|
||||
protected $indexing_helper;
|
||||
|
||||
/**
|
||||
* Prominent_Words_Route constructor.
|
||||
*
|
||||
* @param Content_Action $content_action The content action.
|
||||
* @param Save_Action $save_action The save action.
|
||||
* @param Complete_Action $complete_action The complete action.
|
||||
* @param Indexing_Helper $indexing_helper The indexing helper.
|
||||
*/
|
||||
public function __construct(
|
||||
Content_Action $content_action,
|
||||
Save_Action $save_action,
|
||||
Complete_Action $complete_action,
|
||||
Indexing_Helper $indexing_helper
|
||||
) {
|
||||
$this->content_action = $content_action;
|
||||
$this->save_action = $save_action;
|
||||
$this->complete_action = $complete_action;
|
||||
$this->indexing_helper = $indexing_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers routes with WordPress.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_routes() {
|
||||
\register_rest_route(
|
||||
Main::API_V1_NAMESPACE,
|
||||
self::GET_CONTENT_ROUTE,
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [ $this, 'run_content_action' ],
|
||||
'permission_callback' => [ $this, 'can_retrieve_data' ],
|
||||
]
|
||||
);
|
||||
|
||||
\register_rest_route(
|
||||
Main::API_V1_NAMESPACE,
|
||||
self::COMPLETE_ROUTE,
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [ $this, 'run_complete_action' ],
|
||||
'permission_callback' => [ $this, 'can_retrieve_data' ],
|
||||
]
|
||||
);
|
||||
|
||||
$route_args = [
|
||||
'methods' => 'POST',
|
||||
'args' => [
|
||||
'data' => [
|
||||
'type' => 'array',
|
||||
'required' => false,
|
||||
'items' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'object_id' => [
|
||||
'type' => 'number',
|
||||
'required' => true,
|
||||
],
|
||||
'prominent_words' => [
|
||||
'type' => 'object',
|
||||
'required' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'callback' => [ $this, 'run_save_action' ],
|
||||
'permission_callback' => [ $this, 'can_retrieve_data' ],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, self::SAVE_ROUTE, $route_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the content that needs to be analyzed for prominent words.
|
||||
*
|
||||
* @return WP_REST_Response Response with the content that needs to be analyzed for prominent words.
|
||||
*/
|
||||
public function run_content_action() {
|
||||
return $this->run_indexation_action( $this->content_action, self::FULL_GET_CONTENT_ROUTE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the indexing of prominent words as completed.
|
||||
*
|
||||
* @return WP_REST_Response Response with empty data.
|
||||
*/
|
||||
public function run_complete_action() {
|
||||
$this->complete_action->complete();
|
||||
|
||||
return $this->respond_with( [], false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the prominent words for the indexables.
|
||||
*
|
||||
* The request should have the parameters:
|
||||
* - **data**: The data array containing:
|
||||
* - **object_id**: The ID of the object (post-id, term-id, etc.).
|
||||
* - **prominent_words**: The map of `'stem' => weight` key-value pairs,
|
||||
* e.g. the stems of the prominent words and their weights.
|
||||
* Leave this out when the indexable has no prominent words.
|
||||
*
|
||||
* @param WP_REST_Request $request The request to handle.
|
||||
*
|
||||
* @return WP_REST_Response The response to give.
|
||||
*/
|
||||
public function run_save_action( WP_REST_Request $request ) {
|
||||
$this->save_action->save( $request->get_param( 'data' ) );
|
||||
|
||||
return new WP_REST_Response(
|
||||
[ 'message' => 'The words have been successfully saved for the given indexables.' ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the current user is allowed to use this endpoint.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_retrieve_data() {
|
||||
return \current_user_can( 'edit_posts' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs an indexing action and returns the response.
|
||||
*
|
||||
* @param Indexation_Action_Interface $indexation_action The indexing action.
|
||||
* @param string $url The url of the indexing route.
|
||||
*
|
||||
* @return WP_REST_Response|WP_Error The response, or an error when running the indexing action failed.
|
||||
*/
|
||||
protected function run_indexation_action( Indexation_Action_Interface $indexation_action, $url ) {
|
||||
try {
|
||||
return parent::run_indexation_action( $indexation_action, $url );
|
||||
} catch ( Exception $exception ) {
|
||||
$this->indexing_helper->set_reason( Indexing_Reasons::REASON_INDEXING_FAILED );
|
||||
|
||||
return new WP_Error( 'wpseo_error_indexing', $exception->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,465 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Premium\Routes;
|
||||
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
use WPSEO_Meta;
|
||||
use WPSEO_Redirect;
|
||||
use WPSEO_Redirect_Manager;
|
||||
use WPSEO_Taxonomy_Meta;
|
||||
use Yoast\WP\SEO\Builders\Indexable_Term_Builder;
|
||||
use Yoast\WP\SEO\Conditionals\No_Conditionals;
|
||||
use Yoast\WP\SEO\Helpers\Post_Type_Helper;
|
||||
use Yoast\WP\SEO\Main;
|
||||
use Yoast\WP\SEO\Models\Indexable;
|
||||
use Yoast\WP\SEO\Premium\Actions\Link_Suggestions_Action;
|
||||
use Yoast\WP\SEO\Repositories\Indexable_Repository;
|
||||
use Yoast\WP\SEO\Routes\Route_Interface;
|
||||
use Yoast\WP\SEO\Routes\Workouts_Route as Base_Workouts_Route;
|
||||
|
||||
/**
|
||||
* Workouts_Route class.
|
||||
*/
|
||||
class Workouts_Route implements Route_Interface {
|
||||
|
||||
use No_Conditionals;
|
||||
|
||||
/**
|
||||
* Represents a noindex route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NOINDEX_ROUTE = '/noindex';
|
||||
|
||||
/**
|
||||
* Represents a remove and redirect route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const REMOVE_REDIRECT_ROUTE = '/remove_redirect';
|
||||
|
||||
/**
|
||||
* Represents a link suggestions route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const LINK_SUGGESTIONS_ROUTE = '/link_suggestions';
|
||||
|
||||
/**
|
||||
* Represents a cornerstones route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CORNERSTONE_DATA_ROUTE = '/cornerstone_data';
|
||||
|
||||
/**
|
||||
* Represents an enable cornerstone route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ENABLE_CORNERSTONE = '/enable_cornerstone';
|
||||
|
||||
/**
|
||||
* Represents a most linked route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MOST_LINKED_ROUTE = '/most_linked';
|
||||
|
||||
/**
|
||||
* Represents a last_updated route.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const LAST_UPDATED_ROUTE = '/last_updated';
|
||||
|
||||
/**
|
||||
* The indexable repository.
|
||||
*
|
||||
* @var Indexable_Repository
|
||||
*/
|
||||
private $indexable_repository;
|
||||
|
||||
/**
|
||||
* The link suggestions action.
|
||||
*
|
||||
* @var Link_Suggestions_Action
|
||||
*/
|
||||
private $link_suggestions_action;
|
||||
|
||||
/**
|
||||
* The link suggestions action.
|
||||
*
|
||||
* @var Indexable_Term_Builder
|
||||
*/
|
||||
private $indexable_term_builder;
|
||||
|
||||
/**
|
||||
* The post type helper.
|
||||
*
|
||||
* @var Post_Type_Helper
|
||||
*/
|
||||
private $post_type_helper;
|
||||
|
||||
/**
|
||||
* Workouts_Route constructor.
|
||||
*
|
||||
* @param Indexable_Repository $indexable_repository The indexable repository.
|
||||
* @param Link_Suggestions_Action $link_suggestions_action The link suggestions action.
|
||||
* @param Indexable_Term_Builder $indexable_term_builder The indexable term builder.
|
||||
* @param Post_Type_Helper $post_type_helper The post type helper.
|
||||
*/
|
||||
public function __construct(
|
||||
Indexable_Repository $indexable_repository,
|
||||
Link_Suggestions_Action $link_suggestions_action,
|
||||
Indexable_Term_Builder $indexable_term_builder,
|
||||
Post_Type_Helper $post_type_helper
|
||||
) {
|
||||
$this->indexable_repository = $indexable_repository;
|
||||
$this->link_suggestions_action = $link_suggestions_action;
|
||||
$this->indexable_term_builder = $indexable_term_builder;
|
||||
$this->post_type_helper = $post_type_helper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers routes with WordPress.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_routes() {
|
||||
$edit_others_posts = static function() {
|
||||
return \current_user_can( 'edit_others_posts' );
|
||||
};
|
||||
|
||||
$noindex_route = [
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [ $this, 'noindex' ],
|
||||
'permission_callback' => $edit_others_posts,
|
||||
'args' => [
|
||||
'object_id' => [
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
'object_type' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
'object_sub_type' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, Base_Workouts_Route::WORKOUTS_ROUTE . self::NOINDEX_ROUTE, $noindex_route );
|
||||
|
||||
$remove_redirect_route = [
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [ $this, 'remove_redirect' ],
|
||||
'permission_callback' => $edit_others_posts,
|
||||
'args' => [
|
||||
'object_id' => [
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
'object_type' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
'object_sub_type' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
'permalink' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
'redirect_url' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, Base_Workouts_Route::WORKOUTS_ROUTE . self::REMOVE_REDIRECT_ROUTE, $remove_redirect_route );
|
||||
|
||||
$suggestions_route = [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [ $this, 'get_link_suggestions' ],
|
||||
'permission_callback' => $edit_others_posts,
|
||||
'args' => [
|
||||
'indexableId' => [
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, Base_Workouts_Route::WORKOUTS_ROUTE . self::LINK_SUGGESTIONS_ROUTE, $suggestions_route );
|
||||
|
||||
$last_updated_route = [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [ $this, 'get_last_updated' ],
|
||||
'permission_callback' => $edit_others_posts,
|
||||
'args' => [
|
||||
'postId' => [
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, Base_Workouts_Route::WORKOUTS_ROUTE . self::LAST_UPDATED_ROUTE, $last_updated_route );
|
||||
|
||||
$cornerstone_data_route = [
|
||||
[
|
||||
'methods' => 'GET',
|
||||
'callback' => [ $this, 'get_cornerstone_data' ],
|
||||
'permission_callback' => $edit_others_posts,
|
||||
],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, Base_Workouts_Route::WORKOUTS_ROUTE . self::CORNERSTONE_DATA_ROUTE, $cornerstone_data_route );
|
||||
|
||||
$enable_cornerstone_route = [
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [ $this, 'enable_cornerstone' ],
|
||||
'permission_callback' => $edit_others_posts,
|
||||
'args' => [
|
||||
'object_id' => [
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
'object_type' => [
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, Base_Workouts_Route::WORKOUTS_ROUTE . self::ENABLE_CORNERSTONE, $enable_cornerstone_route );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets noindex on an indexable.
|
||||
*
|
||||
* @param WP_Rest_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response the configuration of the workouts.
|
||||
*/
|
||||
public function noindex( $request ) {
|
||||
if ( $request['object_type'] === 'post' ) {
|
||||
WPSEO_Meta::set_value( 'meta-robots-noindex', 1, $request['object_id'] );
|
||||
}
|
||||
elseif ( $request['object_type'] === 'term' ) {
|
||||
WPSEO_Taxonomy_Meta::set_value( $request['object_id'], $request['object_sub_type'], 'noindex', 'noindex' );
|
||||
// Rebuild the indexable as WPSEO_Taxonomy_Meta does not trigger any actions on which term indexables are rebuild.
|
||||
$indexable = $this->indexable_term_builder->build( $request['object_id'], $this->indexable_repository->find_by_id_and_type( $request['object_id'], $request['object_type'] ) );
|
||||
if ( \is_a( $indexable, Indexable::class ) ) {
|
||||
$indexable->save();
|
||||
}
|
||||
else {
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => false ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => true ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables cornerstone on an indexable.
|
||||
*
|
||||
* @param WP_Rest_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response the configuration of the workouts.
|
||||
*/
|
||||
public function enable_cornerstone( $request ) {
|
||||
if ( $request['object_type'] === 'post' ) {
|
||||
WPSEO_Meta::set_value( 'is_cornerstone', 1, $request['object_id'] );
|
||||
}
|
||||
elseif ( $request['object_type'] === 'term' ) {
|
||||
$term = \get_term( $request['object_id'] );
|
||||
WPSEO_Taxonomy_Meta::set_value( $request['object_id'], $term->taxonomy, 'is_cornerstone', '1' );
|
||||
// Rebuild the indexable as WPSEO_Taxonomy_Meta does not trigger any actions on which term indexables are rebuild.
|
||||
$indexable = $this->indexable_term_builder->build( $request['object_id'], $this->indexable_repository->find_by_id_and_type( $request['object_id'], $request['object_type'] ) );
|
||||
if ( \is_a( $indexable, Indexable::class ) ) {
|
||||
$indexable->save();
|
||||
}
|
||||
else {
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => false ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => true ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an indexable and redirects it.
|
||||
*
|
||||
* @param WP_Rest_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response the configuration of the workouts.
|
||||
*/
|
||||
public function remove_redirect( $request ) {
|
||||
if ( $request['object_type'] === 'post' ) {
|
||||
\add_filter( 'Yoast\WP\SEO\enable_notification_post_trash', '__return_false' );
|
||||
\wp_trash_post( $request['object_id'] );
|
||||
\remove_filter( 'Yoast\WP\SEO\enable_notification_post_trash', '__return_false' );
|
||||
}
|
||||
elseif ( $request['object_type'] === 'term' ) {
|
||||
\add_filter( 'Yoast\WP\SEO\enable_notification_term_delete', '__return_false' );
|
||||
\wp_delete_term( $request['object_id'], $request['object_sub_type'] );
|
||||
\remove_filter( 'Yoast\WP\SEO\enable_notification_term_delete', '__return_false' );
|
||||
}
|
||||
else {
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => false ]
|
||||
);
|
||||
}
|
||||
|
||||
$redirect = new WPSEO_Redirect(
|
||||
$request['permalink'],
|
||||
$request['redirect_url'],
|
||||
'301',
|
||||
'plain'
|
||||
);
|
||||
$redirect_manager = new WPSEO_Redirect_Manager( 'plain' );
|
||||
$redirect_manager->create_redirect( $redirect );
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => true ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets noindex on an indexable.
|
||||
*
|
||||
* @param WP_Rest_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response the configuration of the workouts.
|
||||
*/
|
||||
public function get_link_suggestions( $request ) {
|
||||
$suggestions = $this->link_suggestions_action->get_indexable_suggestions_for_indexable(
|
||||
$request['indexableId'],
|
||||
5,
|
||||
false
|
||||
);
|
||||
|
||||
foreach ( $suggestions as $index => $suggestion ) {
|
||||
$suggestions[ $index ]['edit_link'] = ( $suggestion['object_type'] === 'post' ) ? \get_edit_post_link( $suggestion['object_id'] ) : \get_edit_term_link( $suggestion['object_id'] );
|
||||
}
|
||||
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => $suggestions ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cornerstone indexables
|
||||
*
|
||||
* @return WP_REST_Response the configuration of the workouts.
|
||||
*/
|
||||
public function get_cornerstone_data() {
|
||||
$cornerstones = $this->indexable_repository->query()
|
||||
->where_raw( '( post_status= \'publish\' OR post_status IS NULL ) AND is_cornerstone = 1' )
|
||||
->where_in( 'object_type', [ 'term', 'post' ] )
|
||||
->where_in( 'object_sub_type', $this->get_public_sub_types() )
|
||||
->order_by_asc( 'breadcrumb_title' )
|
||||
->find_many();
|
||||
|
||||
$cornerstones = \array_map( [ $this->indexable_repository, 'ensure_permalink' ], $cornerstones );
|
||||
$cornerstones = \array_map( [ $this, 'map_subtypes_to_singular_name' ], $cornerstones );
|
||||
|
||||
$most_linked = $this->indexable_repository->query()
|
||||
->where_gt( 'incoming_link_count', 0 )
|
||||
->where_not_null( 'incoming_link_count' )
|
||||
->where_raw( '( post_status = \'publish\' OR post_status IS NULL )' )
|
||||
->where_in( 'object_sub_type', $this->get_public_sub_types() )
|
||||
->where_in( 'object_type', [ 'term', 'post' ] )
|
||||
->where_raw( '( is_robots_noindex = 0 OR is_robots_noindex IS NULL )' )
|
||||
->order_by_desc( 'incoming_link_count' )
|
||||
->limit( 20 )
|
||||
->find_many();
|
||||
$most_linked = \array_map( [ $this->indexable_repository, 'ensure_permalink' ], $most_linked );
|
||||
$most_linked = \array_map( [ $this, 'map_subtypes_to_singular_name' ], $most_linked );
|
||||
|
||||
return new WP_REST_Response(
|
||||
[
|
||||
'json' => [
|
||||
'cornerstones' => $cornerstones,
|
||||
'mostLinked' => $most_linked,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last updated for a particular post Id.
|
||||
*
|
||||
* @param WP_Rest_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response the configuration of the workouts.
|
||||
*/
|
||||
public function get_last_updated( $request ) {
|
||||
$post = \get_post( $request['postId'] );
|
||||
|
||||
return new WP_REST_Response(
|
||||
[ 'json' => $post->post_modified ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps an array of indexables and replaces the object_sub_type with the singular name of that type.
|
||||
*
|
||||
* @param Indexable $indexable An Indexable.
|
||||
*
|
||||
* @return Indexable The new Indexable with the edited object_sub_type.
|
||||
*/
|
||||
public function map_subtypes_to_singular_name( Indexable $indexable ) {
|
||||
if ( $indexable->object_type === 'post' ) {
|
||||
$post_type_labels = \get_post_type_labels( \get_post_type_object( \get_post_type( $indexable->object_id ) ) );
|
||||
$indexable->object_sub_type = $post_type_labels->singular_name;
|
||||
}
|
||||
else {
|
||||
$taxonomy_labels = \get_taxonomy_labels( \get_taxonomy( $indexable->object_sub_type ) );
|
||||
$indexable->object_sub_type = $taxonomy_labels->singular_name;
|
||||
}
|
||||
return $indexable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get public sub types.
|
||||
*
|
||||
* @return array The subtypes.
|
||||
*/
|
||||
protected function get_public_sub_types() {
|
||||
$object_sub_types = \array_values(
|
||||
\array_merge(
|
||||
$this->post_type_helper->get_public_post_types(),
|
||||
\get_taxonomies( [ 'public' => true ] )
|
||||
)
|
||||
);
|
||||
|
||||
$excluded_post_types = \apply_filters( 'wpseo_indexable_excluded_post_types', [ 'attachment' ] );
|
||||
$object_sub_types = \array_diff( $object_sub_types, $excluded_post_types );
|
||||
return $object_sub_types;
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Routes;
|
||||
|
||||
use WP_REST_Request;
|
||||
use WP_REST_Response;
|
||||
use Yoast\WP\SEO\Conditionals\Zapier_Enabled_Conditional;
|
||||
use Yoast\WP\SEO\Main;
|
||||
use Yoast\WP\SEO\Premium\Actions\Zapier_Action;
|
||||
|
||||
/**
|
||||
* Registers the route for the Zapier integration.
|
||||
*
|
||||
* @package Yoast\WP\SEO\Routes
|
||||
*/
|
||||
class Zapier_Route implements Route_Interface {
|
||||
|
||||
/**
|
||||
* The Zapier route prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ROUTE_PREFIX = 'zapier';
|
||||
|
||||
/**
|
||||
* The subscribe route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SUBSCRIBE_ROUTE = self::ROUTE_PREFIX . '/subscribe';
|
||||
|
||||
/**
|
||||
* The unsubscribe route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const UNSUBSCRIBE_ROUTE = self::ROUTE_PREFIX . '/unsubscribe';
|
||||
|
||||
/**
|
||||
* The check route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const CHECK_API_KEY_ROUTE = self::ROUTE_PREFIX . '/check';
|
||||
|
||||
/**
|
||||
* The perform list route constant.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PERFORM_LIST = self::ROUTE_PREFIX . '/list';
|
||||
|
||||
/**
|
||||
* Instance of the Zapier_Action.
|
||||
*
|
||||
* @var Zapier_Action
|
||||
*/
|
||||
protected $zapier_action;
|
||||
|
||||
/**
|
||||
* Zapier_Route constructor.
|
||||
*
|
||||
* @param Zapier_Action $zapier_action The action to handle the requests to the endpoint.
|
||||
*/
|
||||
public function __construct( Zapier_Action $zapier_action ) {
|
||||
$this->zapier_action = $zapier_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers routes with WordPress.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_routes() {
|
||||
$subscribe_route_args = [
|
||||
'methods' => 'POST',
|
||||
'args' => [
|
||||
'url' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => 'The callback URL to use.',
|
||||
],
|
||||
'api_key' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => 'The API key to validate.',
|
||||
],
|
||||
],
|
||||
'callback' => [ $this, 'subscribe' ],
|
||||
'permission_callback' => '__return_true',
|
||||
];
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, self::SUBSCRIBE_ROUTE, $subscribe_route_args );
|
||||
|
||||
$unsubscribe_route_args = [
|
||||
'methods' => 'DELETE',
|
||||
'args' => [
|
||||
'id' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => 'The ID of the subscription to unsubscribe.',
|
||||
],
|
||||
],
|
||||
'callback' => [ $this, 'unsubscribe' ],
|
||||
'permission_callback' => '__return_true',
|
||||
];
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, self::UNSUBSCRIBE_ROUTE, $unsubscribe_route_args );
|
||||
|
||||
$check_api_key_route_args = [
|
||||
'methods' => 'POST',
|
||||
'args' => [
|
||||
'api_key' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => 'The API key to validate.',
|
||||
],
|
||||
],
|
||||
'callback' => [ $this, 'check_api_key' ],
|
||||
'permission_callback' => '__return_true',
|
||||
];
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, self::CHECK_API_KEY_ROUTE, $check_api_key_route_args );
|
||||
|
||||
$perform_list_route_args = [
|
||||
'methods' => 'GET',
|
||||
'args' => [
|
||||
'api_key' => [
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => 'The API key to validate.',
|
||||
],
|
||||
],
|
||||
'callback' => [ $this, 'perform_list' ],
|
||||
'permission_callback' => '__return_true',
|
||||
];
|
||||
\register_rest_route( Main::API_V1_NAMESPACE, self::PERFORM_LIST, $perform_list_route_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the subscribe action.
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response The response of the subscribe action.
|
||||
*/
|
||||
public function subscribe( WP_REST_Request $request ) {
|
||||
$subscription = $this->zapier_action->subscribe( $request['url'], $request['api_key'] );
|
||||
$response = $subscription->data;
|
||||
|
||||
if ( empty( $response ) && \property_exists( $subscription, 'message' ) ) {
|
||||
$response = $subscription->message;
|
||||
}
|
||||
|
||||
return new WP_REST_Response( $response, $subscription->status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the unsubscribe action.
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response The response of the unsubscribe action.
|
||||
*/
|
||||
public function unsubscribe( WP_REST_Request $request ) {
|
||||
$subscription = $this->zapier_action->unsubscribe( $request['id'] );
|
||||
|
||||
return new WP_REST_Response( $subscription->message, $subscription->status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the check_api_key action.
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response The response of the check_api_key action.
|
||||
*/
|
||||
public function check_api_key( WP_REST_Request $request ) {
|
||||
$check = $this->zapier_action->check_api_key( $request['api_key'] );
|
||||
|
||||
return new WP_REST_Response( $check->message, $check->status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the check_api_key action.
|
||||
*
|
||||
* @param WP_REST_Request $request The request object.
|
||||
*
|
||||
* @return WP_REST_Response The response of the check_api_key action.
|
||||
*/
|
||||
public function perform_list( WP_REST_Request $request ) {
|
||||
$response = $this->zapier_action->perform_list( $request['api_key'] );
|
||||
|
||||
return new WP_REST_Response( $response->data, $response->status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the conditionals based in which these routes should be active.
|
||||
*
|
||||
* @return array The list of conditionals.
|
||||
*/
|
||||
public static function get_conditionals() {
|
||||
return [ Zapier_Enabled_Conditional::class ];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user