Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../src/integrat.../watchers
File: indexable-permalink-watcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Watchers;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
[4] Fix | Delete
use Yoast\WP\SEO\Config\Indexing_Reasons;
[5] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexable_Helper;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Post_Type_Helper;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Taxonomy_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* WordPress Permalink structure watcher.
[13] Fix | Delete
*
[14] Fix | Delete
* Handles updates to the permalink_structure for the Indexables table.
[15] Fix | Delete
*/
[16] Fix | Delete
class Indexable_Permalink_Watcher implements Integration_Interface {
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Represents the options helper.
[20] Fix | Delete
*
[21] Fix | Delete
* @var Options_Helper
[22] Fix | Delete
*/
[23] Fix | Delete
protected $options_helper;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The taxonomy helper.
[27] Fix | Delete
*
[28] Fix | Delete
* @var Taxonomy_Helper
[29] Fix | Delete
*/
[30] Fix | Delete
protected $taxonomy_helper;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The post type helper.
[34] Fix | Delete
*
[35] Fix | Delete
* @var Post_Type_Helper
[36] Fix | Delete
*/
[37] Fix | Delete
private $post_type;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The indexable helper.
[41] Fix | Delete
*
[42] Fix | Delete
* @var Indexable_Helper
[43] Fix | Delete
*/
[44] Fix | Delete
protected $indexable_helper;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[48] Fix | Delete
*
[49] Fix | Delete
* @return array
[50] Fix | Delete
*/
[51] Fix | Delete
public static function get_conditionals() {
[52] Fix | Delete
return [ Migrations_Conditional::class ];
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Indexable_Permalink_Watcher constructor.
[57] Fix | Delete
*
[58] Fix | Delete
* @param Post_Type_Helper $post_type The post type helper.
[59] Fix | Delete
* @param Options_Helper $options The options helper.
[60] Fix | Delete
* @param Indexable_Helper $indexable The indexable helper.
[61] Fix | Delete
* @param Taxonomy_Helper $taxonomy_helper The taxonomy helper.
[62] Fix | Delete
*/
[63] Fix | Delete
public function __construct( Post_Type_Helper $post_type, Options_Helper $options, Indexable_Helper $indexable, Taxonomy_Helper $taxonomy_helper ) {
[64] Fix | Delete
$this->post_type = $post_type;
[65] Fix | Delete
$this->options_helper = $options;
[66] Fix | Delete
$this->indexable_helper = $indexable;
[67] Fix | Delete
$this->taxonomy_helper = $taxonomy_helper;
[68] Fix | Delete
[69] Fix | Delete
$this->schedule_cron();
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Registers the hooks.
[74] Fix | Delete
*
[75] Fix | Delete
* @return void
[76] Fix | Delete
*/
[77] Fix | Delete
public function register_hooks() {
[78] Fix | Delete
\add_action( 'update_option_permalink_structure', [ $this, 'reset_permalinks' ] );
[79] Fix | Delete
\add_action( 'update_option_category_base', [ $this, 'reset_permalinks_term' ], 10, 3 );
[80] Fix | Delete
\add_action( 'update_option_tag_base', [ $this, 'reset_permalinks_term' ], 10, 3 );
[81] Fix | Delete
\add_action( 'wpseo_permalink_structure_check', [ $this, 'force_reset_permalinks' ] );
[82] Fix | Delete
\add_action( 'wpseo_deactivate', [ $this, 'unschedule_cron' ] );
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Resets the permalinks for everything that is related to the permalink structure.
[87] Fix | Delete
*
[88] Fix | Delete
* @return void
[89] Fix | Delete
*/
[90] Fix | Delete
public function reset_permalinks() {
[91] Fix | Delete
[92] Fix | Delete
$post_types = $this->get_post_types();
[93] Fix | Delete
foreach ( $post_types as $post_type ) {
[94] Fix | Delete
$this->reset_permalinks_post_type( $post_type );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
$taxonomies = $this->get_taxonomies_for_post_types( $post_types );
[98] Fix | Delete
foreach ( $taxonomies as $taxonomy ) {
[99] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'term', $taxonomy );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'user' );
[103] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'date-archive' );
[104] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'system-page' );
[105] Fix | Delete
[106] Fix | Delete
// Always update `permalink_structure` in the wpseo option.
[107] Fix | Delete
$this->options_helper->set( 'permalink_structure', \get_option( 'permalink_structure' ) );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Resets the permalink for the given post type.
[112] Fix | Delete
*
[113] Fix | Delete
* @param string $post_type The post type to reset.
[114] Fix | Delete
*
[115] Fix | Delete
* @return void
[116] Fix | Delete
*/
[117] Fix | Delete
public function reset_permalinks_post_type( $post_type ) {
[118] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'post', $post_type );
[119] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'post-type-archive', $post_type );
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Resets the term indexables when the base has been changed.
[124] Fix | Delete
*
[125] Fix | Delete
* @param string $old_value Unused. The old option value.
[126] Fix | Delete
* @param string $new_value Unused. The new option value.
[127] Fix | Delete
* @param string $type The option name.
[128] Fix | Delete
*
[129] Fix | Delete
* @return void
[130] Fix | Delete
*/
[131] Fix | Delete
public function reset_permalinks_term( $old_value, $new_value, $type ) {
[132] Fix | Delete
$subtype = $type;
[133] Fix | Delete
[134] Fix | Delete
$reason = Indexing_Reasons::REASON_PERMALINK_SETTINGS;
[135] Fix | Delete
[136] Fix | Delete
// When the subtype contains _base, just strip it.
[137] Fix | Delete
if ( \strstr( $subtype, '_base' ) ) {
[138] Fix | Delete
$subtype = \substr( $type, 0, -5 );
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
if ( $subtype === 'tag' ) {
[142] Fix | Delete
$subtype = 'post_tag';
[143] Fix | Delete
$reason = Indexing_Reasons::REASON_TAG_BASE_PREFIX;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
if ( $subtype === 'category' ) {
[147] Fix | Delete
$reason = Indexing_Reasons::REASON_CATEGORY_BASE_PREFIX;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'term', $subtype, $reason );
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Resets the permalink indexables automatically, if necessary.
[155] Fix | Delete
*
[156] Fix | Delete
* @return bool Whether the reset request ran.
[157] Fix | Delete
*/
[158] Fix | Delete
public function force_reset_permalinks() {
[159] Fix | Delete
if ( \get_option( 'tag_base' ) !== $this->options_helper->get( 'tag_base_url' ) ) {
[160] Fix | Delete
$this->reset_permalinks_term( null, null, 'tag_base' );
[161] Fix | Delete
$this->options_helper->set( 'tag_base_url', \get_option( 'tag_base' ) );
[162] Fix | Delete
}
[163] Fix | Delete
if ( \get_option( 'category_base' ) !== $this->options_helper->get( 'category_base_url' ) ) {
[164] Fix | Delete
$this->reset_permalinks_term( null, null, 'category_base' );
[165] Fix | Delete
$this->options_helper->set( 'category_base_url', \get_option( 'category_base' ) );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( $this->should_reset_permalinks() ) {
[169] Fix | Delete
$this->reset_permalinks();
[170] Fix | Delete
[171] Fix | Delete
return true;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$this->reset_altered_custom_taxonomies();
[175] Fix | Delete
[176] Fix | Delete
return true;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Checks whether the permalinks should be reset after `permalink_structure` has changed.
[181] Fix | Delete
*
[182] Fix | Delete
* @return bool Whether the permalinks should be reset.
[183] Fix | Delete
*/
[184] Fix | Delete
public function should_reset_permalinks() {
[185] Fix | Delete
return \get_option( 'permalink_structure' ) !== $this->options_helper->get( 'permalink_structure' );
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* Resets custom taxonomies if their slugs have changed.
[190] Fix | Delete
*
[191] Fix | Delete
* @return void
[192] Fix | Delete
*/
[193] Fix | Delete
public function reset_altered_custom_taxonomies() {
[194] Fix | Delete
$taxonomies = $this->taxonomy_helper->get_custom_taxonomies();
[195] Fix | Delete
$custom_taxonomy_bases = $this->options_helper->get( 'custom_taxonomy_slugs', [] );
[196] Fix | Delete
$new_taxonomy_bases = [];
[197] Fix | Delete
[198] Fix | Delete
foreach ( $taxonomies as $taxonomy ) {
[199] Fix | Delete
$taxonomy_slug = $this->taxonomy_helper->get_taxonomy_slug( $taxonomy );
[200] Fix | Delete
[201] Fix | Delete
$new_taxonomy_bases[ $taxonomy ] = $taxonomy_slug;
[202] Fix | Delete
[203] Fix | Delete
if ( ! \array_key_exists( $taxonomy, $custom_taxonomy_bases ) ) {
[204] Fix | Delete
continue;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
if ( $taxonomy_slug !== $custom_taxonomy_bases[ $taxonomy ] ) {
[208] Fix | Delete
$this->indexable_helper->reset_permalink_indexables( 'term', $taxonomy );
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
$this->options_helper->set( 'custom_taxonomy_slugs', $new_taxonomy_bases );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Retrieves a list with the public post types.
[217] Fix | Delete
*
[218] Fix | Delete
* @return array The post types.
[219] Fix | Delete
*/
[220] Fix | Delete
protected function get_post_types() {
[221] Fix | Delete
/**
[222] Fix | Delete
* Filter: Gives the possibility to filter out post types.
[223] Fix | Delete
*
[224] Fix | Delete
* @param array $post_types The post type names.
[225] Fix | Delete
*
[226] Fix | Delete
* @return array The post types.
[227] Fix | Delete
*/
[228] Fix | Delete
$post_types = \apply_filters( 'wpseo_post_types_reset_permalinks', $this->post_type->get_public_post_types() );
[229] Fix | Delete
[230] Fix | Delete
return $post_types;
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
/**
[234] Fix | Delete
* Retrieves the taxonomies that belongs to the public post types.
[235] Fix | Delete
*
[236] Fix | Delete
* @param array $post_types The post types to get taxonomies for.
[237] Fix | Delete
*
[238] Fix | Delete
* @return array The retrieved taxonomies.
[239] Fix | Delete
*/
[240] Fix | Delete
protected function get_taxonomies_for_post_types( $post_types ) {
[241] Fix | Delete
$taxonomies = [];
[242] Fix | Delete
foreach ( $post_types as $post_type ) {
[243] Fix | Delete
$taxonomies[] = \get_object_taxonomies( $post_type, 'names' );
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$taxonomies = \array_merge( [], ...$taxonomies );
[247] Fix | Delete
$taxonomies = \array_unique( $taxonomies );
[248] Fix | Delete
[249] Fix | Delete
return $taxonomies;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Schedules the WP-Cron job to check the permalink_structure status.
[254] Fix | Delete
*
[255] Fix | Delete
* @return void
[256] Fix | Delete
*/
[257] Fix | Delete
protected function schedule_cron() {
[258] Fix | Delete
if ( \wp_next_scheduled( 'wpseo_permalink_structure_check' ) ) {
[259] Fix | Delete
return;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
\wp_schedule_event( \time(), 'daily', 'wpseo_permalink_structure_check' );
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/**
[266] Fix | Delete
* Unschedules the WP-Cron job to check the permalink_structure status.
[267] Fix | Delete
*
[268] Fix | Delete
* @return void
[269] Fix | Delete
*/
[270] Fix | Delete
public function unschedule_cron() {
[271] Fix | Delete
if ( ! \wp_next_scheduled( 'wpseo_permalink_structure_check' ) ) {
[272] Fix | Delete
return;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
\wp_clear_scheduled_hook( 'wpseo_permalink_structure_check' );
[276] Fix | Delete
}
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function