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/actions/importin.../aioseo
File: aioseo-cleanup-action.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
[2] Fix | Delete
namespace Yoast\WP\SEO\Actions\Importing\Aioseo;
[3] Fix | Delete
[4] Fix | Delete
use wpdb;
[5] Fix | Delete
use Yoast\WP\SEO\Actions\Importing\Abstract_Aioseo_Importing_Action;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Importing action for cleaning up AIOSEO data.
[10] Fix | Delete
*/
[11] Fix | Delete
class Aioseo_Cleanup_Action extends Abstract_Aioseo_Importing_Action {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The plugin of the action.
[15] Fix | Delete
*/
[16] Fix | Delete
public const PLUGIN = 'aioseo';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* The type of the action.
[20] Fix | Delete
*/
[21] Fix | Delete
public const TYPE = 'cleanup';
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* The AIOSEO meta_keys to be cleaned up.
[25] Fix | Delete
*
[26] Fix | Delete
* @var array
[27] Fix | Delete
*/
[28] Fix | Delete
protected $aioseo_postmeta_keys = [
[29] Fix | Delete
'_aioseo_title',
[30] Fix | Delete
'_aioseo_description',
[31] Fix | Delete
'_aioseo_og_title',
[32] Fix | Delete
'_aioseo_og_description',
[33] Fix | Delete
'_aioseo_twitter_title',
[34] Fix | Delete
'_aioseo_twitter_description',
[35] Fix | Delete
];
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* The WordPress database instance.
[39] Fix | Delete
*
[40] Fix | Delete
* @var wpdb
[41] Fix | Delete
*/
[42] Fix | Delete
protected $wpdb;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Class constructor.
[46] Fix | Delete
*
[47] Fix | Delete
* @param wpdb $wpdb The WordPress database instance.
[48] Fix | Delete
* @param Options_Helper $options The options helper.
[49] Fix | Delete
*/
[50] Fix | Delete
public function __construct(
[51] Fix | Delete
wpdb $wpdb,
[52] Fix | Delete
Options_Helper $options
[53] Fix | Delete
) {
[54] Fix | Delete
$this->wpdb = $wpdb;
[55] Fix | Delete
$this->options = $options;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Retrieves the postmeta along with the db prefix.
[60] Fix | Delete
*
[61] Fix | Delete
* @return string The postmeta table name along with the db prefix.
[62] Fix | Delete
*/
[63] Fix | Delete
protected function get_postmeta_table() {
[64] Fix | Delete
return $this->wpdb->prefix . 'postmeta';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Just checks if the cleanup has been completed in the past.
[69] Fix | Delete
*
[70] Fix | Delete
* @return int The total number of unimported objects.
[71] Fix | Delete
*/
[72] Fix | Delete
public function get_total_unindexed() {
[73] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[74] Fix | Delete
return 0;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
return ( ! $this->get_completed() ) ? 1 : 0;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Just checks if the cleanup has been completed in the past.
[82] Fix | Delete
*
[83] Fix | Delete
* @param int $limit The maximum number of unimported objects to be returned.
[84] Fix | Delete
*
[85] Fix | Delete
* @return int|false The limited number of unindexed posts. False if the query fails.
[86] Fix | Delete
*/
[87] Fix | Delete
public function get_limited_unindexed_count( $limit ) {
[88] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[89] Fix | Delete
return 0;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
return ( ! $this->get_completed() ) ? 1 : 0;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Cleans up AIOSEO data.
[97] Fix | Delete
*
[98] Fix | Delete
* @return Indexable[]|false An array of created indexables or false if aioseo data was not found.
[99] Fix | Delete
*/
[100] Fix | Delete
public function index() {
[101] Fix | Delete
if ( $this->get_completed() ) {
[102] Fix | Delete
return [];
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: There is no unescaped user input.
[106] Fix | Delete
$meta_data = $this->wpdb->query( $this->cleanup_postmeta_query() );
[107] Fix | Delete
$aioseo_table_truncate_done = $this->wpdb->query( $this->truncate_query() );
[108] Fix | Delete
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
[109] Fix | Delete
[110] Fix | Delete
if ( $meta_data === false && $aioseo_table_truncate_done === false ) {
[111] Fix | Delete
return false;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$this->set_completed( true );
[115] Fix | Delete
[116] Fix | Delete
return [
[117] Fix | Delete
'metadata_cleanup' => $meta_data,
[118] Fix | Delete
'indexables_cleanup' => $aioseo_table_truncate_done,
[119] Fix | Delete
];
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Creates a DELETE query string for deleting AIOSEO postmeta data.
[124] Fix | Delete
*
[125] Fix | Delete
* @return string The query to use for importing or counting the number of items to import.
[126] Fix | Delete
*/
[127] Fix | Delete
public function cleanup_postmeta_query() {
[128] Fix | Delete
$table = $this->get_postmeta_table();
[129] Fix | Delete
$meta_keys_to_delete = $this->aioseo_postmeta_keys;
[130] Fix | Delete
[131] Fix | Delete
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input.
[132] Fix | Delete
return $this->wpdb->prepare(
[133] Fix | Delete
"DELETE FROM {$table} WHERE meta_key IN (" . \implode( ', ', \array_fill( 0, \count( $meta_keys_to_delete ), '%s' ) ) . ')',
[134] Fix | Delete
$meta_keys_to_delete
[135] Fix | Delete
);
[136] Fix | Delete
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Creates a TRUNCATE query string for emptying the AIOSEO indexable table, if it exists.
[141] Fix | Delete
*
[142] Fix | Delete
* @return string The query to use for importing or counting the number of items to import.
[143] Fix | Delete
*/
[144] Fix | Delete
public function truncate_query() {
[145] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[146] Fix | Delete
// If the table doesn't exist, we need a string that will amount to a quick query that doesn't return false when ran.
[147] Fix | Delete
return 'SELECT 1';
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
$table = $this->aioseo_helper->get_table();
[151] Fix | Delete
[152] Fix | Delete
return "TRUNCATE TABLE {$table}";
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Used nowhere. Exists to comply with the interface.
[157] Fix | Delete
*
[158] Fix | Delete
* @return int The limit.
[159] Fix | Delete
*/
[160] Fix | Delete
public function get_limit() {
[161] Fix | Delete
/**
[162] Fix | Delete
* Filter 'wpseo_aioseo_cleanup_limit' - Allow filtering the number of posts indexed during each indexing pass.
[163] Fix | Delete
*
[164] Fix | Delete
* @param int $max_posts The maximum number of posts cleaned up.
[165] Fix | Delete
*/
[166] Fix | Delete
$limit = \apply_filters( 'wpseo_aioseo_cleanup_limit', 25 );
[167] Fix | Delete
[168] Fix | Delete
if ( ! \is_int( $limit ) || $limit < 1 ) {
[169] Fix | Delete
$limit = 25;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
return $limit;
[173] Fix | Delete
}
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function