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-post-meta-watcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Watchers;
[2] Fix | Delete
[3] Fix | Delete
use WPSEO_Meta;
[4] Fix | Delete
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
[5] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* WordPress post meta watcher.
[9] Fix | Delete
*/
[10] Fix | Delete
class Indexable_Post_Meta_Watcher implements Integration_Interface {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* The post watcher.
[14] Fix | Delete
*
[15] Fix | Delete
* @var Indexable_Post_Watcher
[16] Fix | Delete
*/
[17] Fix | Delete
protected $post_watcher;
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* An array of post IDs that need to be updated.
[21] Fix | Delete
*
[22] Fix | Delete
* @var array<int>
[23] Fix | Delete
*/
[24] Fix | Delete
protected $post_ids_to_update = [];
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[28] Fix | Delete
*
[29] Fix | Delete
* @return string[]
[30] Fix | Delete
*/
[31] Fix | Delete
public static function get_conditionals() {
[32] Fix | Delete
return [ Migrations_Conditional::class ];
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Indexable_Postmeta_Watcher constructor.
[37] Fix | Delete
*
[38] Fix | Delete
* @param Indexable_Post_Watcher $post_watcher The post watcher.
[39] Fix | Delete
*/
[40] Fix | Delete
public function __construct( Indexable_Post_Watcher $post_watcher ) {
[41] Fix | Delete
$this->post_watcher = $post_watcher;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Initializes the integration.
[46] Fix | Delete
*
[47] Fix | Delete
* This is the place to register hooks and filters.
[48] Fix | Delete
*
[49] Fix | Delete
* @return void
[50] Fix | Delete
*/
[51] Fix | Delete
public function register_hooks() {
[52] Fix | Delete
// Register all posts whose meta have changed.
[53] Fix | Delete
\add_action( 'added_post_meta', [ $this, 'add_post_id' ], 10, 3 );
[54] Fix | Delete
\add_action( 'updated_post_meta', [ $this, 'add_post_id' ], 10, 3 );
[55] Fix | Delete
\add_action( 'deleted_post_meta', [ $this, 'add_post_id' ], 10, 3 );
[56] Fix | Delete
[57] Fix | Delete
// Remove posts that get saved as they are handled by the Indexable_Post_Watcher.
[58] Fix | Delete
\add_action( 'wp_insert_post', [ $this, 'remove_post_id' ] );
[59] Fix | Delete
\add_action( 'delete_post', [ $this, 'remove_post_id' ] );
[60] Fix | Delete
\add_action( 'edit_attachment', [ $this, 'remove_post_id' ] );
[61] Fix | Delete
\add_action( 'add_attachment', [ $this, 'remove_post_id' ] );
[62] Fix | Delete
\add_action( 'delete_attachment', [ $this, 'remove_post_id' ] );
[63] Fix | Delete
[64] Fix | Delete
// Update indexables of all registered posts.
[65] Fix | Delete
\register_shutdown_function( [ $this, 'update_indexables' ] );
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Adds a post id to the array of posts to update.
[70] Fix | Delete
*
[71] Fix | Delete
* @param int|string $meta_id The meta ID.
[72] Fix | Delete
* @param int|string $post_id The post ID.
[73] Fix | Delete
* @param string $meta_key The meta key.
[74] Fix | Delete
*
[75] Fix | Delete
* @return void
[76] Fix | Delete
*/
[77] Fix | Delete
public function add_post_id( $meta_id, $post_id, $meta_key ) {
[78] Fix | Delete
// Only register changes to our own meta.
[79] Fix | Delete
if ( \is_string( $meta_key ) && \strpos( $meta_key, WPSEO_Meta::$meta_prefix ) !== 0 ) {
[80] Fix | Delete
return;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( ! \in_array( $post_id, $this->post_ids_to_update, true ) ) {
[84] Fix | Delete
$this->post_ids_to_update[] = (int) $post_id;
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* Removes a post id from the array of posts to update.
[90] Fix | Delete
*
[91] Fix | Delete
* @param int|string $post_id The post ID.
[92] Fix | Delete
*
[93] Fix | Delete
* @return void
[94] Fix | Delete
*/
[95] Fix | Delete
public function remove_post_id( $post_id ) {
[96] Fix | Delete
$this->post_ids_to_update = \array_diff( $this->post_ids_to_update, [ (int) $post_id ] );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Updates all indexables changed during the request.
[101] Fix | Delete
*
[102] Fix | Delete
* @return void
[103] Fix | Delete
*/
[104] Fix | Delete
public function update_indexables() {
[105] Fix | Delete
foreach ( $this->post_ids_to_update as $post_id ) {
[106] Fix | Delete
$this->post_watcher->build_indexable( $post_id );
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function