auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -552,9 +552,12 @@ class WPSEO_Addon_Manager {
* @return stdClass The converted subscription.
*/
protected function convert_subscription_to_plugin( $subscription, $yoast_free_data = null, $plugin_info = false, $plugin_file = '' ) {
// We need to replace h2's and h3's with h4's because the styling expects that.
$changelog = str_replace( '</h2', '</h4', str_replace( '<h2', '<h4', $subscription->product->changelog ) );
$changelog = str_replace( '</h3', '</h4', str_replace( '<h3', '<h4', $changelog ) );
$changelog = '';
if ( isset( $subscription->product->changelog ) ) {
// We need to replace h2's and h3's with h4's because the styling expects that.
$changelog = str_replace( '</h2', '</h4', str_replace( '<h2', '<h4', $subscription->product->changelog ) );
$changelog = str_replace( '</h3', '</h4', str_replace( '<h3', '<h4', $changelog ) );
}
// If we're running this because we want to just show the plugin info in the version details modal, we can fallback to the Yoast Free constants, since that modal will not be accessible anyway in the event that the new Free version increases those constants.
$defaults = [
@@ -563,7 +566,7 @@ class WPSEO_Addon_Manager {
];
return (object) [
'new_version' => $subscription->product->version,
'new_version' => ( $subscription->product->version ?? '' ),
'name' => $subscription->product->name,
'slug' => $subscription->product->slug,
'plugin' => $plugin_file,

View File

@@ -33,7 +33,7 @@ class WPSEO_Upgrade_History {
/**
* Retrieves the content of the history items currently stored.
*
* @return array The contents of the history option.
* @return array<array<string>> The contents of the history option.
*/
public function get() {
$data = get_option( $this->get_option_name(), [] );
@@ -47,9 +47,9 @@ class WPSEO_Upgrade_History {
/**
* Adds a new history entry in the storage.
*
* @param string $old_version The version we are upgrading from.
* @param string $new_version The version we are upgrading to.
* @param array $option_names The options that need to be stored.
* @param string $old_version The version we are upgrading from.
* @param string $new_version The version we are upgrading to.
* @param array<string> $option_names The options that need to be stored.
*
* @return void
*/
@@ -76,23 +76,24 @@ class WPSEO_Upgrade_History {
/**
* Retrieves the data for the specified option names from the database.
*
* @param array $option_names The option names to retrieve.
* @param array<string> $option_names The option names to retrieve.
*
* @return array
* @return array<int|string|bool|float,array<string|int|bool|float>> The retrieved data.
*/
protected function get_options_data( array $option_names ) {
$wpdb = $this->get_wpdb();
$sql = $wpdb->prepare(
'
SELECT option_value, option_name FROM ' . $wpdb->options . ' WHERE
option_name IN ( ' . implode( ',', array_fill( 0, count( $option_names ), '%s' ) ) . ' )
',
$option_names
$results = $wpdb->get_results(
$wpdb->prepare(
'
SELECT %i, %i FROM ' . $wpdb->options . ' WHERE
%i IN ( ' . implode( ',', array_fill( 0, count( $option_names ), '%s' ) ) . ' )
',
array_merge( [ 'option_value', 'option_name', 'option_name' ], $option_names )
),
ARRAY_A
);
$results = $wpdb->get_results( $sql, ARRAY_A );
$data = [];
foreach ( $results as $result ) {
$data[ $result['option_name'] ] = maybe_unserialize( $result['option_value'] );
@@ -104,7 +105,7 @@ class WPSEO_Upgrade_History {
/**
* Stores the new history state.
*
* @param array $data The data to store.
* @param array<array<string>> $data The data to store.
*
* @return void
*/

View File

@@ -90,6 +90,7 @@ class WPSEO_Upgrade {
'20.5-RC0' => 'upgrade_205',
'20.7-RC0' => 'upgrade_207',
'20.8-RC0' => 'upgrade_208',
'22.6-RC0' => 'upgrade_226',
];
array_walk( $routines, [ $this, 'run_upgrade_routine' ], $version );
@@ -252,6 +253,8 @@ class WPSEO_Upgrade {
* @return void
*/
public function upgrade_23_query() {
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Reason: executed only during the upgrade routine.
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Reason: executed only during the upgrade routine.
$wp_query = new WP_Query( 'post_type=any&meta_key=_yoast_wpseo_sitemap-include&meta_value=never&order=ASC' );
if ( ! empty( $wp_query->posts ) ) {
@@ -304,11 +307,18 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function upgrade_36() {
protected function upgrade_36() {
global $wpdb;
// Between 3.2 and 3.4 the sitemap options were saved with autoloading enabled.
$wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "wpseo_sitemap_%" AND autoload = "yes"' );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
'DELETE FROM %i WHERE %i LIKE %s AND autoload IN ("on", "yes")',
[ $wpdb->options, 'option_name', 'wpseo_sitemap_%' ]
)
);
}
/**
@@ -345,6 +355,8 @@ class WPSEO_Upgrade {
global $wpdb;
// The meta key has to be private, so prefix it.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
'UPDATE ' . $wpdb->postmeta . ' SET meta_key = %s WHERE meta_key = "yst_is_cornerstone"',
@@ -358,7 +370,7 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function upgrade_49() {
protected function upgrade_49() {
global $wpdb;
/*
@@ -371,15 +383,16 @@ class WPSEO_Upgrade {
$meta_key = $wpdb->get_blog_prefix() . Yoast_Notification_Center::STORAGE_KEY;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$usermetas = $wpdb->get_results(
$wpdb->prepare(
'
SELECT user_id, meta_value
FROM ' . $wpdb->usermeta . '
WHERE meta_key = %s AND meta_value LIKE %s
SELECT %i, %i
FROM %i
WHERE %i = %s AND %i LIKE %s
',
$meta_key,
'%wpseo-dismiss-about%'
[ 'user_id', 'meta_value', $wpdb->usermeta, 'meta_key', $meta_key, 'meta_value', '%wpseo-dismiss-about%' ]
),
ARRAY_A
);
@@ -423,11 +436,19 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function upgrade_50() {
protected function upgrade_50() {
global $wpdb;
// Deletes the post meta value, which might created in the RC.
$wpdb->query( 'DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key = "_yst_content_links_processed"' );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = '_yst_content_links_processed'",
[ $wpdb->postmeta, 'meta_key' ]
)
);
}
/**
@@ -520,6 +541,8 @@ class WPSEO_Upgrade {
// Moves the user meta for excluding from the XML sitemap to a noindex.
global $wpdb;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query( "UPDATE $wpdb->usermeta SET meta_key = 'wpseo_noindex_author' WHERE meta_key = 'wpseo_excludeauthorsitemap'" );
}
@@ -549,6 +572,8 @@ class WPSEO_Upgrade {
private function upgrade_73() {
global $wpdb;
// We've moved the cornerstone checkbox to our proper namespace.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '_yoast_wpseo_is_cornerstone' WHERE meta_key = '_yst_is_cornerstone'" );
// Remove the previous Whip dismissed message, as this is a new one regarding PHP 5.2.
@@ -560,7 +585,7 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function upgrade_74() {
protected function upgrade_74() {
$this->remove_sitemap_validators();
}
@@ -612,7 +637,7 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function upgrade_90() {
protected function upgrade_90() {
global $wpdb;
// Invalidate all sitemap cache transients.
@@ -621,7 +646,15 @@ class WPSEO_Upgrade {
// Removes all scheduled tasks for hitting the sitemap index.
wp_clear_scheduled_hook( 'wpseo_hit_sitemap_index' );
$wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "wpseo_sitemap_%"' );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
'DELETE FROM %i
WHERE %i LIKE %s',
[ $wpdb->options, 'option_name', 'wpseo_sitemap_%' ]
)
);
}
/**
@@ -698,7 +731,15 @@ class WPSEO_Upgrade {
}
global $wpdb;
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'wp_yoast_promo_hide_premium_upsell_admin_block'" );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
'DELETE FROM %i
WHERE %i = %s',
[ $wpdb->usermeta, 'meta_key', 'wp_yoast_promo_hide_premium_upsell_admin_block' ]
)
);
// Removes the WordPress update notification, because it is no longer necessary when WordPress 5.3 is released.
$center = Yoast_Notification_Center::get();
@@ -1096,6 +1137,19 @@ class WPSEO_Upgrade {
}
}
/**
* Performs the 22.6 upgrade routine.
* Schedules another cleanup scheduled action, but starting from the last cleanup action we just added (if there aren't any running cleanups already).
*
* @return void
*/
private function upgrade_226() {
if ( get_option( Cleanup_Integration::CURRENT_TASK_OPTION ) === false ) {
$cleanup_integration = YoastSEO()->classes->get( Cleanup_Integration::class );
$cleanup_integration->start_cron_job( 'clean_selected_empty_usermeta', DAY_IN_SECONDS );
}
}
/**
* Sets the home_url option for the 15.1 upgrade routine.
*
@@ -1150,19 +1204,20 @@ class WPSEO_Upgrade {
return;
}
$indexable_table = Model::get_table_name( 'Indexable' );
$replacements = array_merge( [ Model::get_table_name( 'Indexable' ), 'object_type', 'object_sub_type' ], $private_taxonomies );
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$query = $wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: Too hard to fix.
"DELETE FROM $indexable_table
WHERE object_type = 'term'
AND object_sub_type IN ("
. implode( ', ', array_fill( 0, count( $private_taxonomies ), '%s' ) )
. ')',
$private_taxonomies
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = 'term'
AND %i IN ("
. implode( ', ', array_fill( 0, count( $private_taxonomies ), '%s' ) )
. ')',
$replacements
)
);
$wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$wpdb->show_errors = $show_errors;
}
@@ -1180,9 +1235,14 @@ class WPSEO_Upgrade {
$wpdb->show_errors = false;
// Reset the permalinks of the attachments in the indexable table.
$indexable_table = Model::get_table_name( 'Indexable' );
$query = "UPDATE $indexable_table SET permalink = NULL WHERE object_type = 'post' AND object_sub_type = 'attachment'";
$wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Reason: There is no user input.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"UPDATE %i SET %i = NULL WHERE %i = 'post' AND %i = 'attachment'",
[ Model::get_table_name( 'Indexable' ), 'permalink', 'object_type', 'object_sub_type' ]
)
);
$wpdb->show_errors = $show_errors;
}
@@ -1254,7 +1314,14 @@ class WPSEO_Upgrade {
global $wpdb;
// Remove all sitemap validators.
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'wpseo_sitemap%validator%'" );
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
'DELETE FROM %i WHERE %i LIKE %s',
[ $wpdb->options, 'option_name', 'wpseo_sitemap%validator%' ]
)
);
}
/**
@@ -1262,14 +1329,22 @@ class WPSEO_Upgrade {
*
* @param string $option_name Option to retrieve.
*
* @return array|mixed The content of the option if exists, otherwise an empty array.
* @return int|string|bool|float|array<string|int|bool|float> The content of the option if exists, otherwise an empty array.
*/
protected function get_option_from_database( $option_name ) {
global $wpdb;
// Load option directly from the database, to avoid filtering and sanitization.
$sql = $wpdb->prepare( 'SELECT option_value FROM ' . $wpdb->options . ' WHERE option_name = %s', $option_name );
$results = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is is already prepared.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$results = $wpdb->get_results(
$wpdb->prepare(
'SELECT %i FROM %i WHERE %i = %s',
[ 'option_value', $wpdb->options, 'option_name', $option_name ]
),
ARRAY_A
);
if ( ! empty( $results ) ) {
return maybe_unserialize( $results[0]['option_value'] );
}
@@ -1302,9 +1377,9 @@ class WPSEO_Upgrade {
/**
* Saves an option setting to where it should be stored.
*
* @param array $source_data The option containing the value to be migrated.
* @param string $source_setting Name of the key in the "from" option.
* @param string|null $target_setting Name of the key in the "to" option.
* @param int|string|bool|float|array<string|int|bool|float> $source_data The option containing the value to be migrated.
* @param string $source_setting Name of the key in the "from" option.
* @param string|null $target_setting Name of the key in the "to" option.
*
* @return void
*/
@@ -1513,29 +1588,31 @@ class WPSEO_Upgrade {
$included_post_types = YoastSEO()->helpers->post_type->get_indexable_post_types();
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: Too hard to fix.
if ( empty( $included_post_types ) ) {
$delete_query = "
DELETE FROM $indexable_table
WHERE object_type = 'post'
AND object_sub_type IS NOT NULL";
}
else {
$delete_query = $wpdb->prepare(
"DELETE FROM $indexable_table
WHERE object_type = 'post'
AND object_sub_type IS NOT NULL
AND object_sub_type NOT IN ( " . implode( ', ', array_fill( 0, count( $included_post_types ), '%s' ) ) . ' )',
$included_post_types
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = 'post'
AND %i IS NOT NULL",
[ $indexable_table, 'object_type', 'object_sub_type' ]
)
);
}
else {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = 'post'
AND %i IS NOT NULL
AND %i NOT IN ( " . implode( ', ', array_fill( 0, count( $included_post_types ), '%s' ) ) . ' )',
array_merge( [ $indexable_table, 'object_type', 'object_sub_type', 'object_sub_type' ], $included_post_types )
)
);
}
// phpcs:enable
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$wpdb->query( $delete_query );
// phpcs:enable
$wpdb->show_errors = $show_errors;
}
@@ -1557,28 +1634,31 @@ class WPSEO_Upgrade {
$included_taxonomies = YoastSEO()->helpers->taxonomy->get_indexable_taxonomies();
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: Too hard to fix.
if ( empty( $included_taxonomies ) ) {
$delete_query = "DELETE FROM $indexable_table
WHERE object_type = 'term'
AND object_sub_type IS NOT NULL";
}
else {
$delete_query = $wpdb->prepare(
"DELETE FROM $indexable_table
WHERE object_type = 'term'
AND object_sub_type IS NOT NULL
AND object_sub_type NOT IN ( " . implode( ', ', array_fill( 0, count( $included_taxonomies ), '%s' ) ) . ' )',
$included_taxonomies
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = 'term'
AND %i IS NOT NULL",
[ $indexable_table, 'object_type', 'object_sub_type' ]
)
);
}
else {
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = 'term'
AND %i IS NOT NULL
AND %i NOT IN ( " . implode( ', ', array_fill( 0, count( $included_taxonomies ), '%s' ) ) . ' )',
array_merge( [ $indexable_table, 'object_type', 'object_sub_type', 'object_sub_type' ], $included_taxonomies )
)
);
}
// phpcs:enable
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$wpdb->query( $delete_query );
// phpcs:enable
$wpdb->show_errors = $show_errors;
}
@@ -1588,22 +1668,24 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function deduplicate_unindexed_indexable_rows() {
protected function deduplicate_unindexed_indexable_rows() {
global $wpdb;
// If migrations haven't been completed successfully the following may give false errors. So suppress them.
$show_errors = $wpdb->show_errors;
$wpdb->show_errors = false;
$indexable_table = Model::get_table_name( 'Indexable' );
$query = "
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$duplicates = $wpdb->get_results(
$wpdb->prepare(
"
SELECT
MAX(id) as newest_id,
object_id,
object_type
FROM
$indexable_table
%i
WHERE
post_status = 'unindexed'
AND object_type IN ( 'term', 'post', 'user' )
@@ -1611,13 +1693,11 @@ class WPSEO_Upgrade {
object_id,
object_type
HAVING
count(*) > 1";
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$duplicates = $wpdb->get_results( $query, ARRAY_A );
// phpcs:enable
count(*) > 1",
[ Model::get_table_name( 'Indexable' ) ]
),
ARRAY_A
);
if ( empty( $duplicates ) ) {
$wpdb->show_errors = $show_errors;
@@ -1650,25 +1730,24 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function clean_unindexed_indexable_rows_with_no_object_id() {
protected function clean_unindexed_indexable_rows_with_no_object_id() {
global $wpdb;
// If migrations haven't been completed successfully the following may give false errors. So suppress them.
$show_errors = $wpdb->show_errors;
$wpdb->show_errors = false;
$indexable_table = Model::get_table_name( 'Indexable' );
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: No user input, just a table name.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
$wpdb->query(
"DELETE FROM $indexable_table
WHERE post_status = 'unindexed'
AND object_type NOT IN ( 'home-page', 'date-archive', 'post-type-archive', 'system-page' )
AND object_id IS NULL"
$wpdb->prepare(
"DELETE FROM %i
WHERE %i = 'unindexed'
AND %i NOT IN ( 'home-page', 'date-archive', 'post-type-archive', 'system-page' )
AND %i IS NULL",
[ Model::get_table_name( 'Indexable' ), 'post_status', 'object_type', 'object_id' ]
)
);
// phpcs:enable
$wpdb->show_errors = $show_errors;
}
@@ -1678,7 +1757,7 @@ class WPSEO_Upgrade {
*
* @return void
*/
private function remove_indexable_rows_for_disabled_authors_archive() {
protected function remove_indexable_rows_for_disabled_authors_archive() {
global $wpdb;
if ( ! YoastSEO()->helpers->author_archive->are_disabled() ) {
@@ -1689,16 +1768,14 @@ class WPSEO_Upgrade {
$show_errors = $wpdb->show_errors;
$wpdb->show_errors = false;
$indexable_table = Model::get_table_name( 'Indexable' );
$delete_query = "DELETE FROM $indexable_table WHERE object_type = 'user'";
// phpcs:enable
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
$wpdb->query( $delete_query );
// phpcs:enable
$wpdb->query(
$wpdb->prepare(
"DELETE FROM %i WHERE %i = 'user'",
[ Model::get_table_name( 'Indexable' ), 'object_type' ]
)
);
$wpdb->show_errors = $show_errors;
}
@@ -1706,15 +1783,13 @@ class WPSEO_Upgrade {
/**
* Creates a query for de-duplicating indexables for a particular type.
*
* @param string $object_type The object type to deduplicate.
* @param array $duplicates The result of the duplicate query.
* @param wpdb $wpdb The wpdb object.
* @param string $object_type The object type to deduplicate.
* @param string|array<array<int,int,string>> $duplicates The result of the duplicate query.
* @param wpdb $wpdb The wpdb object.
*
* @return string The query that removes all but one duplicate for each object of the object type.
*/
private function get_indexable_deduplication_query_for_type( $object_type, $duplicates, $wpdb ) {
$indexable_table = Model::get_table_name( 'Indexable' );
protected function get_indexable_deduplication_query_for_type( $object_type, $duplicates, $wpdb ) {
$filtered_duplicates = array_filter(
$duplicates,
static function ( $duplicate ) use ( $object_type ) {
@@ -1729,18 +1804,20 @@ class WPSEO_Upgrade {
$object_ids = wp_list_pluck( $filtered_duplicates, 'object_id' );
$newest_indexable_ids = wp_list_pluck( $filtered_duplicates, 'newest_id' );
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: Too hard to fix.
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Reason: we're passing an array instead.
$replacements = array_merge( [ Model::get_table_name( 'Indexable' ), 'object_id' ], array_values( $object_ids ), array_values( $newest_indexable_ids ) );
$replacements[] = $object_type;
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
return $wpdb->prepare(
"DELETE FROM
$indexable_table
'DELETE FROM
%i
WHERE
object_id IN ( " . implode( ', ', array_fill( 0, count( $filtered_duplicates ), '%d' ) ) . ' )
%i IN ( ' . implode( ', ', array_fill( 0, count( $filtered_duplicates ), '%d' ) ) . ' )
AND id NOT IN ( ' . implode( ', ', array_fill( 0, count( $filtered_duplicates ), '%d' ) ) . ' )
AND object_type = %s',
array_merge( array_values( $object_ids ), array_values( $newest_indexable_ids ), [ $object_type ] )
$replacements
);
// phpcs:enable
}
/**

View File

@@ -450,11 +450,6 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
'title' => __( 'Google Page Speed Test', 'wordpress-seo' ),
'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . $encoded_url,
],
[
'id' => 'wpseo-google-mobile-friendly',
'title' => __( 'Mobile-Friendly Test', 'wordpress-seo' ),
'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . $encoded_url,
],
];
$this->add_submenu_items( $submenu_items, $wp_admin_bar, self::ANALYSIS_SUBMENU_IDENTIFIER );
@@ -595,7 +590,7 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
if ( YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2023-promotion' ) ) {
$sale_percentage = sprintf(
'<span class="admin-bar-premium-promotion">%1$s</span>',
__( '-30%', 'wordpress-seo' )
esc_html__( '-30%', 'wordpress-seo' )
);
}
$wp_admin_bar->add_menu(
@@ -605,8 +600,8 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
// Circumvent an issue in the WP admin bar API in order to pass `data` attributes. See https://core.trac.wordpress.org/ticket/38636.
'title' => sprintf(
'<a href="%1$s" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2" style="padding:0;">%2$s &raquo; %3$s</a>',
$this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium' ),
__( 'Get Yoast SEO Premium', 'wordpress-seo' ),
esc_url( $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium' ) ),
esc_html__( 'Get Yoast SEO Premium', 'wordpress-seo' ),
$sale_percentage
),
'meta' => [
@@ -903,7 +898,8 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
* @return bool True if capabilities are sufficient, false otherwise.
*/
protected function can_manage_options() {
return is_network_admin() && current_user_can( 'wpseo_manage_network_options' ) || ! is_network_admin() && WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' );
return ( is_network_admin() && current_user_can( 'wpseo_manage_network_options' ) )
|| ( ! is_network_admin() && WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ) );
}
/**

View File

@@ -830,7 +830,7 @@ class WPSEO_Option_Titles extends WPSEO_Option {
* {@internal This clean-up action can only be done effectively once the taxonomies
* and post_types have been registered, i.e. at the end of the init action.}}
*/
if ( isset( $original ) && current_filter() === 'wpseo_double_clean_titles' || did_action( 'wpseo_double_clean_titles' ) > 0 ) {
if ( ( isset( $original ) && current_filter() === 'wpseo_double_clean_titles' ) || did_action( 'wpseo_double_clean_titles' ) > 0 ) {
$rename = [
'title-' => 'title-tax-',
'metadesc-' => 'metadesc-tax-',

View File

@@ -194,7 +194,7 @@ class WPSEO_Sitemaps_Cache_Validator {
$wpdb->query(
$wpdb->prepare(
//phpcs:disable WordPress.DB.PreparedSQLPlaceholders -- %i placeholder is still not recognized.
'DELETE FROM %i WHERE ' . implode( ' OR', array_fill( 0, count( $where ), '%s' ) ),
'DELETE FROM %i WHERE ' . implode( ' OR ', array_fill( 0, count( $where ), '%s' ) ),
array_merge( [ $wpdb->options ], $where )
)
);