Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/routes
File: indexing-route.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Routes;
[2] Fix | Delete
[3] Fix | Delete
use Exception;
[4] Fix | Delete
use WP_Error;
[5] Fix | Delete
use WP_REST_Response;
[6] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_General_Indexation_Action;
[7] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Indexing_Complete_Action;
[8] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Indexation_Action;
[9] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Post_Type_Archive_Indexation_Action;
[10] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexable_Term_Indexation_Action;
[11] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexation_Action_Interface;
[12] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexing_Complete_Action;
[13] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Indexing_Prepare_Action;
[14] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action;
[15] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Term_Link_Indexing_Action;
[16] Fix | Delete
use Yoast\WP\SEO\Conditionals\No_Conditionals;
[17] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexing_Helper;
[18] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[19] Fix | Delete
use Yoast\WP\SEO\Main;
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Indexing_Route class.
[23] Fix | Delete
*
[24] Fix | Delete
* Indexing route for indexables.
[25] Fix | Delete
*/
[26] Fix | Delete
class Indexing_Route extends Abstract_Indexation_Route {
[27] Fix | Delete
[28] Fix | Delete
use No_Conditionals;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* The indexing complete route constant.
[32] Fix | Delete
*
[33] Fix | Delete
* @var string
[34] Fix | Delete
*/
[35] Fix | Delete
const COMPLETE_ROUTE = 'indexing/complete';
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* The full indexing complete route constant.
[39] Fix | Delete
*
[40] Fix | Delete
* @var string
[41] Fix | Delete
*/
[42] Fix | Delete
const FULL_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::COMPLETE_ROUTE;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* The indexables complete route constant.
[46] Fix | Delete
*
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
const INDEXABLES_COMPLETE_ROUTE = 'indexing/indexables-complete';
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* The full indexing complete route constant.
[53] Fix | Delete
*
[54] Fix | Delete
* @var string
[55] Fix | Delete
*/
[56] Fix | Delete
const FULL_INDEXABLES_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::INDEXABLES_COMPLETE_ROUTE;
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* The indexing prepare route constant.
[60] Fix | Delete
*
[61] Fix | Delete
* @var string
[62] Fix | Delete
*/
[63] Fix | Delete
const PREPARE_ROUTE = 'indexing/prepare';
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* The full indexing prepare route constant.
[67] Fix | Delete
*
[68] Fix | Delete
* @var string
[69] Fix | Delete
*/
[70] Fix | Delete
const FULL_PREPARE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::PREPARE_ROUTE;
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* The posts route constant.
[74] Fix | Delete
*
[75] Fix | Delete
* @var string
[76] Fix | Delete
*/
[77] Fix | Delete
const POSTS_ROUTE = 'indexing/posts';
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* The full posts route constant.
[81] Fix | Delete
*
[82] Fix | Delete
* @var string
[83] Fix | Delete
*/
[84] Fix | Delete
const FULL_POSTS_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POSTS_ROUTE;
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* The terms route constant.
[88] Fix | Delete
*
[89] Fix | Delete
* @var string
[90] Fix | Delete
*/
[91] Fix | Delete
const TERMS_ROUTE = 'indexing/terms';
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* The full terms route constant.
[95] Fix | Delete
*
[96] Fix | Delete
* @var string
[97] Fix | Delete
*/
[98] Fix | Delete
const FULL_TERMS_ROUTE = Main::API_V1_NAMESPACE . '/' . self::TERMS_ROUTE;
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* The terms route constant.
[102] Fix | Delete
*
[103] Fix | Delete
* @var string
[104] Fix | Delete
*/
[105] Fix | Delete
const POST_TYPE_ARCHIVES_ROUTE = 'indexing/post-type-archives';
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* The full terms route constant.
[109] Fix | Delete
*
[110] Fix | Delete
* @var string
[111] Fix | Delete
*/
[112] Fix | Delete
const FULL_POST_TYPE_ARCHIVES_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POST_TYPE_ARCHIVES_ROUTE;
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* The general route constant.
[116] Fix | Delete
*
[117] Fix | Delete
* @var string
[118] Fix | Delete
*/
[119] Fix | Delete
const GENERAL_ROUTE = 'indexing/general';
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* The full general route constant.
[123] Fix | Delete
*
[124] Fix | Delete
* @var string
[125] Fix | Delete
*/
[126] Fix | Delete
const FULL_GENERAL_ROUTE = Main::API_V1_NAMESPACE . '/' . self::GENERAL_ROUTE;
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* The posts route constant.
[130] Fix | Delete
*
[131] Fix | Delete
* @var string
[132] Fix | Delete
*/
[133] Fix | Delete
const POST_LINKS_INDEXING_ROUTE = 'link-indexing/posts';
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* The full posts route constant.
[137] Fix | Delete
*
[138] Fix | Delete
* @var string
[139] Fix | Delete
*/
[140] Fix | Delete
const FULL_POST_LINKS_INDEXING_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POST_LINKS_INDEXING_ROUTE;
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* The terms route constant.
[144] Fix | Delete
*
[145] Fix | Delete
* @var string
[146] Fix | Delete
*/
[147] Fix | Delete
const TERM_LINKS_INDEXING_ROUTE = 'link-indexing/terms';
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* The full terms route constant.
[151] Fix | Delete
*
[152] Fix | Delete
* @var string
[153] Fix | Delete
*/
[154] Fix | Delete
const FULL_TERM_LINKS_INDEXING_ROUTE = Main::API_V1_NAMESPACE . '/' . self::TERM_LINKS_INDEXING_ROUTE;
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* The post indexing action.
[158] Fix | Delete
*
[159] Fix | Delete
* @var Indexable_Post_Indexation_Action
[160] Fix | Delete
*/
[161] Fix | Delete
protected $post_indexation_action;
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* The term indexing action.
[165] Fix | Delete
*
[166] Fix | Delete
* @var Indexable_Term_Indexation_Action
[167] Fix | Delete
*/
[168] Fix | Delete
protected $term_indexation_action;
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* The post type archive indexing action.
[172] Fix | Delete
*
[173] Fix | Delete
* @var Indexable_Post_Type_Archive_Indexation_Action
[174] Fix | Delete
*/
[175] Fix | Delete
protected $post_type_archive_indexation_action;
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Represents the general indexing action.
[179] Fix | Delete
*
[180] Fix | Delete
* @var Indexable_General_Indexation_Action
[181] Fix | Delete
*/
[182] Fix | Delete
protected $general_indexation_action;
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* The prepare indexing action.
[186] Fix | Delete
*
[187] Fix | Delete
* @var Indexing_Prepare_Action
[188] Fix | Delete
*/
[189] Fix | Delete
protected $prepare_indexing_action;
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* The indexable indexing complete action.
[193] Fix | Delete
*
[194] Fix | Delete
* @var Indexable_Indexing_Complete_Action
[195] Fix | Delete
*/
[196] Fix | Delete
protected $indexable_indexing_complete_action;
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* The indexing complete action.
[200] Fix | Delete
*
[201] Fix | Delete
* @var Indexing_Complete_Action
[202] Fix | Delete
*/
[203] Fix | Delete
protected $indexing_complete_action;
[204] Fix | Delete
[205] Fix | Delete
/**
[206] Fix | Delete
* The post link indexing action.
[207] Fix | Delete
*
[208] Fix | Delete
* @var Post_Link_Indexing_Action
[209] Fix | Delete
*/
[210] Fix | Delete
protected $post_link_indexing_action;
[211] Fix | Delete
[212] Fix | Delete
/**
[213] Fix | Delete
* The term link indexing action.
[214] Fix | Delete
*
[215] Fix | Delete
* @var Term_Link_Indexing_Action
[216] Fix | Delete
*/
[217] Fix | Delete
protected $term_link_indexing_action;
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* The options helper.
[221] Fix | Delete
*
[222] Fix | Delete
* @var Options_Helper
[223] Fix | Delete
*/
[224] Fix | Delete
protected $options_helper;
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* The indexing helper.
[228] Fix | Delete
*
[229] Fix | Delete
* @var Indexing_Helper
[230] Fix | Delete
*/
[231] Fix | Delete
protected $indexing_helper;
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* Indexing_Route constructor.
[235] Fix | Delete
*
[236] Fix | Delete
* @param Indexable_Post_Indexation_Action $post_indexation_action The post indexing action.
[237] Fix | Delete
* @param Indexable_Term_Indexation_Action $term_indexation_action The term indexing action.
[238] Fix | Delete
* @param Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation_action The post type archive indexing action.
[239] Fix | Delete
* @param Indexable_General_Indexation_Action $general_indexation_action The general indexing action.
[240] Fix | Delete
* @param Indexable_Indexing_Complete_Action $indexable_indexing_complete_action The complete indexing action.
[241] Fix | Delete
* @param Indexing_Complete_Action $indexing_complete_action The complete indexing action.
[242] Fix | Delete
* @param Indexing_Prepare_Action $prepare_indexing_action The prepare indexing action.
[243] Fix | Delete
* @param Post_Link_Indexing_Action $post_link_indexing_action The post link indexing action.
[244] Fix | Delete
* @param Term_Link_Indexing_Action $term_link_indexing_action The term link indexing action.
[245] Fix | Delete
* @param Options_Helper $options_helper The options helper.
[246] Fix | Delete
* @param Indexing_Helper $indexing_helper The indexing helper.
[247] Fix | Delete
*/
[248] Fix | Delete
public function __construct(
[249] Fix | Delete
Indexable_Post_Indexation_Action $post_indexation_action,
[250] Fix | Delete
Indexable_Term_Indexation_Action $term_indexation_action,
[251] Fix | Delete
Indexable_Post_Type_Archive_Indexation_Action $post_type_archive_indexation_action,
[252] Fix | Delete
Indexable_General_Indexation_Action $general_indexation_action,
[253] Fix | Delete
Indexable_Indexing_Complete_Action $indexable_indexing_complete_action,
[254] Fix | Delete
Indexing_Complete_Action $indexing_complete_action,
[255] Fix | Delete
Indexing_Prepare_Action $prepare_indexing_action,
[256] Fix | Delete
Post_Link_Indexing_Action $post_link_indexing_action,
[257] Fix | Delete
Term_Link_Indexing_Action $term_link_indexing_action,
[258] Fix | Delete
Options_Helper $options_helper,
[259] Fix | Delete
Indexing_Helper $indexing_helper
[260] Fix | Delete
) {
[261] Fix | Delete
$this->post_indexation_action = $post_indexation_action;
[262] Fix | Delete
$this->term_indexation_action = $term_indexation_action;
[263] Fix | Delete
$this->post_type_archive_indexation_action = $post_type_archive_indexation_action;
[264] Fix | Delete
$this->general_indexation_action = $general_indexation_action;
[265] Fix | Delete
$this->indexable_indexing_complete_action = $indexable_indexing_complete_action;
[266] Fix | Delete
$this->indexing_complete_action = $indexing_complete_action;
[267] Fix | Delete
$this->prepare_indexing_action = $prepare_indexing_action;
[268] Fix | Delete
$this->post_link_indexing_action = $post_link_indexing_action;
[269] Fix | Delete
$this->term_link_indexing_action = $term_link_indexing_action;
[270] Fix | Delete
$this->options_helper = $options_helper;
[271] Fix | Delete
$this->post_link_indexing_action = $post_link_indexing_action;
[272] Fix | Delete
$this->term_link_indexing_action = $term_link_indexing_action;
[273] Fix | Delete
$this->indexing_helper = $indexing_helper;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Registers the routes used to index indexables.
[278] Fix | Delete
*/
[279] Fix | Delete
public function register_routes() {
[280] Fix | Delete
$route_args = [
[281] Fix | Delete
'methods' => 'POST',
[282] Fix | Delete
'callback' => [ $this, 'index_posts' ],
[283] Fix | Delete
'permission_callback' => [ $this, 'can_index' ],
[284] Fix | Delete
];
[285] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::POSTS_ROUTE, $route_args );
[286] Fix | Delete
[287] Fix | Delete
$route_args['callback'] = [ $this, 'index_terms' ];
[288] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::TERMS_ROUTE, $route_args );
[289] Fix | Delete
[290] Fix | Delete
$route_args['callback'] = [ $this, 'index_post_type_archives' ];
[291] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::POST_TYPE_ARCHIVES_ROUTE, $route_args );
[292] Fix | Delete
[293] Fix | Delete
$route_args['callback'] = [ $this, 'index_general' ];
[294] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::GENERAL_ROUTE, $route_args );
[295] Fix | Delete
[296] Fix | Delete
$route_args['callback'] = [ $this, 'prepare' ];
[297] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::PREPARE_ROUTE, $route_args );
[298] Fix | Delete
[299] Fix | Delete
$route_args['callback'] = [ $this, 'indexables_complete' ];
[300] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::INDEXABLES_COMPLETE_ROUTE, $route_args );
[301] Fix | Delete
[302] Fix | Delete
$route_args['callback'] = [ $this, 'complete' ];
[303] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::COMPLETE_ROUTE, $route_args );
[304] Fix | Delete
[305] Fix | Delete
$route_args['callback'] = [ $this, 'index_post_links' ];
[306] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::POST_LINKS_INDEXING_ROUTE, $route_args );
[307] Fix | Delete
[308] Fix | Delete
$route_args['callback'] = [ $this, 'index_term_links' ];
[309] Fix | Delete
\register_rest_route( Main::API_V1_NAMESPACE, self::TERM_LINKS_INDEXING_ROUTE, $route_args );
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Indexes a number of unindexed posts.
[314] Fix | Delete
*
[315] Fix | Delete
* @return WP_REST_Response The response.
[316] Fix | Delete
*/
[317] Fix | Delete
public function index_posts() {
[318] Fix | Delete
return $this->run_indexation_action( $this->post_indexation_action, self::FULL_POSTS_ROUTE );
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Indexes a number of unindexed terms.
[323] Fix | Delete
*
[324] Fix | Delete
* @return WP_REST_Response The response.
[325] Fix | Delete
*/
[326] Fix | Delete
public function index_terms() {
[327] Fix | Delete
return $this->run_indexation_action( $this->term_indexation_action, self::FULL_TERMS_ROUTE );
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Indexes a number of unindexed post type archive pages.
[332] Fix | Delete
*
[333] Fix | Delete
* @return WP_REST_Response The response.
[334] Fix | Delete
*/
[335] Fix | Delete
public function index_post_type_archives() {
[336] Fix | Delete
return $this->run_indexation_action( $this->post_type_archive_indexation_action, self::FULL_POST_TYPE_ARCHIVES_ROUTE );
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
/**
[340] Fix | Delete
* Indexes a number of unindexed general items.
[341] Fix | Delete
*
[342] Fix | Delete
* @return WP_REST_Response The response.
[343] Fix | Delete
*/
[344] Fix | Delete
public function index_general() {
[345] Fix | Delete
return $this->run_indexation_action( $this->general_indexation_action, self::FULL_GENERAL_ROUTE );
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
/**
[349] Fix | Delete
* Indexes a number of posts for post links.
[350] Fix | Delete
*
[351] Fix | Delete
* @return WP_REST_Response The response.
[352] Fix | Delete
*/
[353] Fix | Delete
public function index_post_links() {
[354] Fix | Delete
return $this->run_indexation_action( $this->post_link_indexing_action, self::FULL_POST_LINKS_INDEXING_ROUTE );
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* Indexes a number of terms for term links.
[359] Fix | Delete
*
[360] Fix | Delete
* @return WP_REST_Response The response.
[361] Fix | Delete
*/
[362] Fix | Delete
public function index_term_links() {
[363] Fix | Delete
return $this->run_indexation_action( $this->term_link_indexing_action, self::FULL_TERM_LINKS_INDEXING_ROUTE );
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
/**
[367] Fix | Delete
* Prepares the indexation.
[368] Fix | Delete
*
[369] Fix | Delete
* @return WP_REST_Response The response.
[370] Fix | Delete
*/
[371] Fix | Delete
public function prepare() {
[372] Fix | Delete
$this->prepare_indexing_action->prepare();
[373] Fix | Delete
[374] Fix | Delete
return $this->respond_with( [], false );
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
/**
[378] Fix | Delete
* Completes the indexable indexation.
[379] Fix | Delete
*
[380] Fix | Delete
* @return WP_REST_Response The response.
[381] Fix | Delete
*/
[382] Fix | Delete
public function indexables_complete() {
[383] Fix | Delete
$this->indexable_indexing_complete_action->complete();
[384] Fix | Delete
[385] Fix | Delete
return $this->respond_with( [], false );
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
/**
[389] Fix | Delete
* Completes the indexation.
[390] Fix | Delete
*
[391] Fix | Delete
* @return WP_REST_Response The response.
[392] Fix | Delete
*/
[393] Fix | Delete
public function complete() {
[394] Fix | Delete
$this->indexing_complete_action->complete();
[395] Fix | Delete
[396] Fix | Delete
return $this->respond_with( [], false );
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Whether or not the current user is allowed to index.
[401] Fix | Delete
*
[402] Fix | Delete
* @return bool Whether or not the current user is allowed to index.
[403] Fix | Delete
*/
[404] Fix | Delete
public function can_index() {
[405] Fix | Delete
return \current_user_can( 'edit_posts' );
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
/**
[409] Fix | Delete
* Runs an indexing action and returns the response.
[410] Fix | Delete
*
[411] Fix | Delete
* @param Indexation_Action_Interface $indexation_action The indexing action.
[412] Fix | Delete
* @param string $url The url of the indexing route.
[413] Fix | Delete
*
[414] Fix | Delete
* @return WP_REST_Response|WP_Error The response, or an error when running the indexing action failed.
[415] Fix | Delete
*/
[416] Fix | Delete
protected function run_indexation_action( Indexation_Action_Interface $indexation_action, $url ) {
[417] Fix | Delete
try {
[418] Fix | Delete
return parent::run_indexation_action( $indexation_action, $url );
[419] Fix | Delete
} catch ( Exception $exception ) {
[420] Fix | Delete
$this->indexing_helper->indexing_failed();
[421] Fix | Delete
[422] Fix | Delete
return new WP_Error(
[423] Fix | Delete
'wpseo_error_indexing',
[424] Fix | Delete
$exception->getMessage(),
[425] Fix | Delete
[ 'stackTrace' => $exception->getTraceAsString() ]
[426] Fix | Delete
);
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function