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/clone/wp-conte.../plugins/wordpres.../src/integrat.../watchers
File: primary-term-watcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Watchers;
[2] Fix | Delete
[3] Fix | Delete
use WP_Term;
[4] Fix | Delete
use WPSEO_Meta;
[5] Fix | Delete
use WPSEO_Primary_Term;
[6] Fix | Delete
use Yoast\WP\SEO\Builders\Primary_Term_Builder;
[7] Fix | Delete
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Primary_Term_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Helpers\Site_Helper;
[10] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[11] Fix | Delete
use Yoast\WP\SEO\Repositories\Primary_Term_Repository;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Primary Term watcher.
[15] Fix | Delete
*
[16] Fix | Delete
* Watches Posts to save the primary term when set.
[17] Fix | Delete
*/
[18] Fix | Delete
class Primary_Term_Watcher implements Integration_Interface {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The primary term repository.
[22] Fix | Delete
*
[23] Fix | Delete
* @var Primary_Term_Repository
[24] Fix | Delete
*/
[25] Fix | Delete
protected $repository;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Represents the site helper.
[29] Fix | Delete
*
[30] Fix | Delete
* @var Site_Helper
[31] Fix | Delete
*/
[32] Fix | Delete
protected $site;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* The primary term helper.
[36] Fix | Delete
*
[37] Fix | Delete
* @var Primary_Term_Helper
[38] Fix | Delete
*/
[39] Fix | Delete
protected $primary_term;
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* The primary term builder.
[43] Fix | Delete
*
[44] Fix | Delete
* @var Primary_Term_Builder
[45] Fix | Delete
*/
[46] Fix | Delete
protected $primary_term_builder;
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[50] Fix | Delete
*
[51] Fix | Delete
* @return array
[52] Fix | Delete
*/
[53] Fix | Delete
public static function get_conditionals() {
[54] Fix | Delete
return [ Migrations_Conditional::class ];
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Primary_Term_Watcher constructor.
[59] Fix | Delete
*
[60] Fix | Delete
* @codeCoverageIgnore It sets dependencies.
[61] Fix | Delete
*
[62] Fix | Delete
* @param Primary_Term_Repository $repository The primary term repository.
[63] Fix | Delete
* @param Site_Helper $site The site helper.
[64] Fix | Delete
* @param Primary_Term_Helper $primary_term The primary term helper.
[65] Fix | Delete
* @param Primary_Term_Builder $primary_term_builder The primary term builder.
[66] Fix | Delete
*/
[67] Fix | Delete
public function __construct(
[68] Fix | Delete
Primary_Term_Repository $repository,
[69] Fix | Delete
Site_Helper $site,
[70] Fix | Delete
Primary_Term_Helper $primary_term,
[71] Fix | Delete
Primary_Term_Builder $primary_term_builder
[72] Fix | Delete
) {
[73] Fix | Delete
$this->repository = $repository;
[74] Fix | Delete
$this->site = $site;
[75] Fix | Delete
$this->primary_term = $primary_term;
[76] Fix | Delete
$this->primary_term_builder = $primary_term_builder;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Initializes the integration.
[81] Fix | Delete
*
[82] Fix | Delete
* This is the place to register hooks and filters.
[83] Fix | Delete
*
[84] Fix | Delete
* @return void
[85] Fix | Delete
*/
[86] Fix | Delete
public function register_hooks() {
[87] Fix | Delete
\add_action( 'save_post', [ $this, 'save_primary_terms' ], \PHP_INT_MAX );
[88] Fix | Delete
\add_action( 'delete_post', [ $this, 'delete_primary_terms' ] );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Saves all selected primary terms.
[93] Fix | Delete
*
[94] Fix | Delete
* @param int $post_id Post ID to save primary terms for.
[95] Fix | Delete
*
[96] Fix | Delete
* @return void
[97] Fix | Delete
*/
[98] Fix | Delete
public function save_primary_terms( $post_id ) {
[99] Fix | Delete
// Bail if this is a multisite installation and the site has been switched.
[100] Fix | Delete
if ( $this->site->is_multisite_and_switched() ) {
[101] Fix | Delete
return;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
$taxonomies = $this->primary_term->get_primary_term_taxonomies( $post_id );
[105] Fix | Delete
[106] Fix | Delete
foreach ( $taxonomies as $taxonomy ) {
[107] Fix | Delete
$this->save_primary_term( $post_id, $taxonomy );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
$this->primary_term_builder->build( $post_id );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Saves the primary term for a specific taxonomy.
[115] Fix | Delete
*
[116] Fix | Delete
* @param int $post_id Post ID to save primary term for.
[117] Fix | Delete
* @param WP_Term $taxonomy Taxonomy to save primary term for.
[118] Fix | Delete
*
[119] Fix | Delete
* @return void
[120] Fix | Delete
*/
[121] Fix | Delete
protected function save_primary_term( $post_id, $taxonomy ) {
[122] Fix | Delete
if ( isset( $_POST[ WPSEO_Meta::$form_prefix . 'primary_' . $taxonomy->name . '_term' ] ) && \is_string( $_POST[ WPSEO_Meta::$form_prefix . 'primary_' . $taxonomy->name . '_term' ] ) ) {
[123] Fix | Delete
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are casting to an integer.
[124] Fix | Delete
$primary_term_id = (int) \wp_unslash( $_POST[ WPSEO_Meta::$form_prefix . 'primary_' . $taxonomy->name . '_term' ] );
[125] Fix | Delete
[126] Fix | Delete
if ( $primary_term_id <= 0 ) {
[127] Fix | Delete
$primary_term = '';
[128] Fix | Delete
}
[129] Fix | Delete
else {
[130] Fix | Delete
$primary_term = (string) $primary_term_id;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
// We accept an empty string here because we need to save that if no terms are selected.
[134] Fix | Delete
if ( \check_admin_referer( 'save-primary-term', WPSEO_Meta::$form_prefix . 'primary_' . $taxonomy->name . '_nonce' ) !== null ) {
[135] Fix | Delete
$primary_term_object = new WPSEO_Primary_Term( $taxonomy->name, $post_id );
[136] Fix | Delete
$primary_term_object->set_primary_term( $primary_term );
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Deletes primary terms for a post.
[143] Fix | Delete
*
[144] Fix | Delete
* @param int $post_id The post to delete the terms of.
[145] Fix | Delete
*
[146] Fix | Delete
* @return void
[147] Fix | Delete
*/
[148] Fix | Delete
public function delete_primary_terms( $post_id ) {
[149] Fix | Delete
foreach ( $this->primary_term->get_primary_term_taxonomies( $post_id ) as $taxonomy ) {
[150] Fix | Delete
$primary_term_indexable = $this->repository->find_by_post_id_and_taxonomy( $post_id, $taxonomy->name, false );
[151] Fix | Delete
[152] Fix | Delete
if ( ! $primary_term_indexable ) {
[153] Fix | Delete
continue;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
$primary_term_indexable->delete();
[157] Fix | Delete
}
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function