rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -455,7 +455,6 @@ class WPSEO_Addon_Manager {
return;
}
foreach ( $this->addon_details as $slug => $addon_info ) {
$notification = $this->create_notification( $addon_info['name'], $addon_info['short_link_activation'] );
@@ -499,13 +498,14 @@ class WPSEO_Addon_Manager {
return new Yoast_Notification(
sprintf(
/* translators: %1$s expands to a strong tag, %2$s expands to the product name, %3$s expands to a closing strong tag, %4$s expands to an a tag. %5$s expands to MyYoast with a closing a tag, %6$s expands to the product name */
__( '%1$s %2$s isn\'t working as expected %3$s and you are not receiving updates or support! Make sure to %4$s activate your product subscription in %5$s to unlock all the features of %6$s.', 'wordpress-seo' ),
/* translators: %1$s expands to a strong tag, %2$s expands to the product name, %3$s expands to a closing strong tag, %4$s expands to an a tag. %5$s expands to MyYoast, %6$s expands to a closing a tag, %7$s expands to the product name */
__( '%1$s %2$s isn\'t working as expected %3$s and you are not receiving updates or support! Make sure to %4$s activate your product subscription in %5$s%6$s to unlock all the features of %7$s.', 'wordpress-seo' ),
'<strong>',
$product_name,
'</strong>',
'<a href="' . WPSEO_Shortlinker::get( $short_link ) . '" target="_blank">',
' MyYoast</a>',
'MyYoast',
'</a>',
$product_name
),
$notification_options

View File

@@ -99,12 +99,18 @@ class WPSEO_Post_Type {
return WPSEO_Options::get( 'display-metabox-pt-' . $post_type, false );
}
/* ********************* DEPRECATED METHODS ********************* */
/**
* Removes the notification related to the post types which have been made public.
*
* @deprecated 20.10
* @codeCoverageIgnore
*
* @return void
*/
public static function remove_post_types_made_public_notification() {
_deprecated_function( __METHOD__, 'Yoast SEO 20.10', 'Content_Type_Visibility_Dismiss_Notifications::dismiss_notifications' );
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification_by_id( 'post-types-made-public' );
}
@@ -112,9 +118,13 @@ class WPSEO_Post_Type {
/**
* Removes the notification related to the taxonomies which have been made public.
*
* @deprecated 20.10
* @codeCoverageIgnore
*
* @return void
*/
public static function remove_taxonomies_made_public_notification() {
_deprecated_function( __METHOD__, 'Yoast SEO 20.10', 'Content_Type_Visibility_Dismiss_Notifications::dismiss_notifications' );
$notification_center = Yoast_Notification_Center::get();
$notification_center->remove_notification_by_id( 'taxonomies-made-public' );
}

View File

@@ -441,7 +441,6 @@ class WPSEO_Upgrade {
// Move one XML sitemap setting, then delete the option.
$this->save_option_setting( $wpseo_xml, 'enablexmlsitemap', 'enable_xml_sitemap' );
// Move the RSS settings to the search appearance settings, then delete the RSS option.
$this->save_option_setting( $wpseo_rss, 'rssbefore' );
$this->save_option_setting( $wpseo_rss, 'rssafter' );
@@ -1427,8 +1426,8 @@ class WPSEO_Upgrade {
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: Too hard to fix.
if ( empty( $included_post_types ) ) {
$delete_query =
"DELETE FROM $indexable_table
$delete_query = "
DELETE FROM $indexable_table
WHERE object_type = 'post'
AND object_sub_type IS NOT NULL";
}
@@ -1509,8 +1508,8 @@ class WPSEO_Upgrade {
$indexable_table = Model::get_table_name( 'Indexable' );
$query =
"SELECT
$query = "
SELECT
MAX(id) as newest_id,
object_id,
object_type
@@ -1574,7 +1573,7 @@ class WPSEO_Upgrade {
// 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.
$delete_query = $wpdb->query(
$wpdb->query(
"DELETE FROM $indexable_table
WHERE post_status = 'unindexed'
AND object_type NOT IN ( 'home-page', 'date-archive', 'post-type-archive', 'system-page' )

View File

@@ -7,6 +7,7 @@
use Yoast\WP\SEO\Helpers\Product_Helper;
use Yoast\WP\SEO\Helpers\Score_Icon_Helper;
use Yoast\WP\SEO\Integrations\Support_Integration;
use Yoast\WP\SEO\Models\Indexable;
use Yoast\WP\SEO\Presenters\Admin\Premium_Badge_Presenter;
use Yoast\WP\SEO\Repositories\Indexable_Repository;
@@ -541,6 +542,13 @@ class WPSEO_Admin_Bar_Menu implements WPSEO_WordPress_Integration {
'title' => __( 'Help', 'wordpress-seo' ),
'meta' => [ 'tabindex' => '0' ],
];
if ( current_user_can( Support_Integration::CAPABILITY ) ) {
$menu_args['href'] = admin_url( 'admin.php?page=' . Support_Integration::PAGE );
$wp_admin_bar->add_menu( $menu_args );
return;
}
$wp_admin_bar->add_menu( $menu_args );
$submenu_items = [

View File

@@ -202,7 +202,7 @@ class WPSEO_Image_Utils {
* Find the right version of an image based on size.
*
* @param int $attachment_id Attachment ID.
* @param string|array $size Size name, or array of width and height in pixels (e.g [800,400]).
* @param string|array $size Size name, or array of width and height in pixels (e.g [800,400]).
*
* @return array|false Returns an array with image data on success, false on failure.
*/

View File

@@ -383,8 +383,6 @@ class WPSEO_Meta {
unset( $field_defs['bctitle'] );
}
global $post;
if ( empty( $post->ID ) || ( ! empty( $post->ID ) && self::get_value( 'redirect', $post->ID ) === '' ) ) {
unset( $field_defs['redirect'] );
}
@@ -455,7 +453,6 @@ class WPSEO_Meta {
}
break;
case ( $field_def['type'] === 'select' || $field_def['type'] === 'radio' ):
// Only allow value if it's one of the predefined options.
if ( isset( $field_def['options'][ $meta_value ] ) ) {
@@ -463,12 +460,10 @@ class WPSEO_Meta {
}
break;
case ( $field_def['type'] === 'hidden' && $meta_key === self::$meta_prefix . 'meta-robots-adv' ):
$clean = self::validate_meta_robots_adv( $meta_value );
break;
case ( $field_def['type'] === 'url' || $meta_key === self::$meta_prefix . 'canonical' ):
// Validate as url(-part).
$url = WPSEO_Utils::sanitize_url( $meta_value );
@@ -477,7 +472,6 @@ class WPSEO_Meta {
}
break;
case ( $field_def['type'] === 'upload' && in_array( $meta_key, [ self::$meta_prefix . 'opengraph-image', self::$meta_prefix . 'twitter-image' ], true ) ):
// Validate as url.
$url = WPSEO_Utils::sanitize_url( $meta_value, [ 'http', 'https', 'ftp', 'ftps' ] );
@@ -518,7 +512,6 @@ class WPSEO_Meta {
$clean = $meta_value;
break;
case ( $field_def['type'] === 'text' ):
default:
if ( is_string( $meta_value ) ) {
@@ -1029,12 +1022,7 @@ class WPSEO_Meta {
->find_array();
// Get object_id from each subarray in $post_ids.
$post_ids = array_map(
function( $row ) {
return $row['object_id'];
},
$post_ids
);
$post_ids = ( is_array( $post_ids ) ) ? array_column( $post_ids, 'object_id' ) : [];
/*
* If Premium is installed, get the additional keywords as well.
@@ -1081,12 +1069,7 @@ class WPSEO_Meta {
->find_array();
// Get object_sub_type from each subarray in $post_ids.
$post_types = array_map(
function( $row ) {
return $row['object_sub_type'];
},
$post_types
);
$post_types = array_column( $post_types, 'object_sub_type' );
}
else {
$post_types = [];

View File

@@ -222,6 +222,33 @@ class WPSEO_Rank {
return $labels[ $this->rank ];
}
/**
* Gets the drop down labels for the inclusive language score.
*
* @return string The inclusive language rank label.
*/
public function get_drop_down_inclusive_language_labels() {
$labels = [
self::BAD => sprintf(
/* translators: %s expands to the inclusive language score */
__( 'Inclusive language: %s', 'wordpress-seo' ),
__( 'Needs improvement', 'wordpress-seo' )
),
self::OK => sprintf(
/* translators: %s expands to the inclusive language score */
__( 'Inclusive language: %s', 'wordpress-seo' ),
__( 'Potentially non-inclusive', 'wordpress-seo' )
),
self::GOOD => sprintf(
/* translators: %s expands to the inclusive language score */
__( 'Inclusive language: %s', 'wordpress-seo' ),
__( 'Good', 'wordpress-seo' )
),
];
return $labels[ $this->rank ];
}
/**
* Get the starting score for this rank.
*
@@ -289,6 +316,15 @@ class WPSEO_Rank {
return array_map( [ 'WPSEO_Rank', 'create_rank' ], [ self::BAD, self::OK, self::GOOD ] );
}
/**
* Returns a list of all possible Inclusive Language Ranks.
*
* @return WPSEO_Rank[]
*/
public static function get_all_inclusive_language_ranks() {
return array_map( [ 'WPSEO_Rank', 'create_rank' ], [ self::BAD, self::OK, self::GOOD ] );
}
/**
* Converts a numeric rank into a WPSEO_Rank object, for use in functional array_* functions.
*

View File

@@ -106,6 +106,7 @@ class WPSEO_Option_MS extends WPSEO_Option {
"{$allow_prefix}remove_feed_global_comments" => true,
"{$allow_prefix}remove_feed_post_comments" => true,
"{$allow_prefix}enable_index_now" => true,
"{$allow_prefix}enable_ai_generator" => true,
"{$allow_prefix}remove_feed_authors" => true,
"{$allow_prefix}remove_feed_categories" => true,
"{$allow_prefix}remove_feed_tags" => true,
@@ -212,7 +213,6 @@ class WPSEO_Option_MS extends WPSEO_Option {
}
break;
case 'defaultblog':
if ( isset( $dirty[ $key ] ) && ( $dirty[ $key ] !== '' && $dirty[ $key ] !== '-' ) ) {
$int = WPSEO_Utils::validate_int( $dirty[ $key ] );

View File

@@ -331,7 +331,6 @@ class WPSEO_Option_Social extends WPSEO_Option {
}
unset( $old_option );
return $option_value;
}
}

View File

@@ -93,6 +93,14 @@ class WPSEO_Option_Titles extends WPSEO_Option {
'open_graph_frontpage_image' => '', // Text field.
'open_graph_frontpage_image_id' => 0,
'publishing_principles_id' => 0,
'ownership_funding_info_id' => 0,
'actionable_feedback_policy_id' => 0,
'corrections_policy_id' => 0,
'ethics_policy_id' => 0,
'diversity_policy_id' => 0,
'diversity_staffing_report_id' => 0,
/*
* Uses enrich_defaults to add more along the lines of:
* - 'title-' . $pt->name => ''; // Text field.
@@ -579,6 +587,13 @@ class WPSEO_Option_Titles extends WPSEO_Option {
case 'person_logo_id':
case 'social-image-id-':
case 'open_graph_frontpage_image_id':
case 'publishing_principles_id':
case 'ownership_funding_info_id':
case 'actionable_feedback_policy_id':
case 'corrections_policy_id':
case 'ethics_policy_id':
case 'diversity_policy_id':
case 'diversity_staffing_report_id':
if ( isset( $dirty[ $key ] ) ) {
$int = WPSEO_Utils::validate_int( $dirty[ $key ] );
if ( $int !== false && $int >= 0 ) {
@@ -592,7 +607,6 @@ class WPSEO_Option_Titles extends WPSEO_Option {
}
}
break;
/* Separator field - Radio. */
case 'separator':
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
@@ -764,13 +778,11 @@ class WPSEO_Option_Titles extends WPSEO_Option {
}
unset( $old_option );
// Fix wrongness created by buggy version 1.2.2.
if ( isset( $option_value['title-home'] ) && $option_value['title-home'] === '%%sitename%% - %%sitedesc%% - 12345' ) {
$option_value['title-home-wpseo'] = '%%sitename%% - %%sitedesc%%';
}
/*
* Renaming these options to avoid ever overwritting these if a (bloody stupid) user /
* programmer would use any of the following as a custom post type or custom taxonomy:
@@ -799,7 +811,6 @@ class WPSEO_Option_Titles extends WPSEO_Option {
}
unset( $rename, $old, $new );
/*
* {@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.}}
@@ -953,11 +964,11 @@ class WPSEO_Option_Titles extends WPSEO_Option {
'label' => __( 'Dash', 'wordpress-seo' ),
],
'sc-ndash' => [
'option' => '&ndash;',
'option' => '&#8211;',
'label' => __( 'En dash', 'wordpress-seo' ),
],
'sc-mdash' => [
'option' => '&mdash;',
'option' => '&#8212;',
'label' => __( 'Em dash', 'wordpress-seo' ),
],
'sc-colon' => [
@@ -965,11 +976,11 @@ class WPSEO_Option_Titles extends WPSEO_Option {
'label' => __( 'Colon', 'wordpress-seo' ),
],
'sc-middot' => [
'option' => '&middot;',
'option' => '&#183;',
'label' => __( 'Middle dot', 'wordpress-seo' ),
],
'sc-bull' => [
'option' => '&bull;',
'option' => '&#8226;',
'label' => __( 'Bullet', 'wordpress-seo' ),
],
'sc-star' => [
@@ -989,19 +1000,19 @@ class WPSEO_Option_Titles extends WPSEO_Option {
'label' => __( 'Small tilde', 'wordpress-seo' ),
],
'sc-laquo' => [
'option' => '&laquo;',
'option' => '&#171;',
'label' => __( 'Left angle quotation mark', 'wordpress-seo' ),
],
'sc-raquo' => [
'option' => '&raquo;',
'option' => '&#187;',
'label' => __( 'Right angle quotation mark', 'wordpress-seo' ),
],
'sc-lt' => [
'option' => '&lt;',
'option' => '&#062;',
'label' => __( 'Less than sign', 'wordpress-seo' ),
],
'sc-gt' => [
'option' => '&gt;',
'option' => '&#060;',
'label' => __( 'Greater than sign', 'wordpress-seo' ),
],
];

View File

@@ -58,6 +58,7 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
'enable_xml_sitemap' => true,
'enable_text_link_counter' => true,
'enable_index_now' => true,
'enable_ai_generator' => false,
'show_onboarding_notice' => false,
'first_activated_on' => false,
'myyoast-oauth' => [
@@ -88,7 +89,6 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
'configuration_finished_steps' => [],
'dismiss_configuration_workout_notice' => false,
'dismiss_premium_deactivated_notice' => false,
'dismiss_old_premium_version_notice' => '',
'importing_completed' => [],
'wincher_integration_active' => true,
'wincher_tokens' => [],
@@ -126,6 +126,7 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
'search_character_limit' => 50,
'deny_search_crawling' => false,
'deny_wp_json_crawling' => false,
'deny_adsbot_crawling' => false,
'redirect_search_pretty_urls' => false,
'least_readability_ignore_list' => [],
'least_seo_score_ignore_list' => [],
@@ -136,6 +137,9 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
'last_known_public_post_types' => [],
'last_known_public_taxonomies' => [],
'last_known_no_unindexed' => [],
'new_post_types' => [],
'new_taxonomies' => [],
'show_new_content_type_notification' => false,
];
/**
@@ -325,7 +329,6 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
case 'wincher_website_id':
case 'clean_permalinks_extra_variables':
case 'indexables_overview_state':
case 'dismiss_old_premium_version_notice':
if ( isset( $dirty[ $key ] ) ) {
$clean[ $key ] = $dirty[ $key ];
}
@@ -409,6 +412,8 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
case 'indexables_page_reading_list':
case 'last_known_public_post_types':
case 'last_known_public_taxonomies':
case 'new_post_types':
case 'new_taxonomies':
$clean[ $key ] = $old[ $key ];
if ( isset( $dirty[ $key ] ) ) {
@@ -505,8 +510,10 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
* 'search_cleanup_emoji'
* 'search_cleanup_patterns'
* 'deny_wp_json_crawling'
* 'deny_adsbot_crawling'
* 'redirect_search_pretty_urls'
* 'should_redirect_after_install_free'
* 'show_new_content_type_notification'
* and most of the feature variables.
*/
default:
@@ -553,6 +560,7 @@ class WPSEO_Option_Wpseo extends WPSEO_Option {
'remove_feed_global_comments' => false,
'remove_feed_post_comments' => false,
'enable_index_now' => false,
'enable_ai_generator' => false,
'remove_feed_authors' => false,
'remove_feed_categories' => false,
'remove_feed_tags' => false,

View File

@@ -149,7 +149,6 @@ abstract class WPSEO_Option {
$this->add_default_filters(); // Return defaults if option not set.
$this->add_option_filters(); // Merge with defaults if option *is* set.
if ( $this->multisite_only !== true ) {
/**
* The option validation routines remove the default filters to prevent failing
@@ -181,7 +180,6 @@ abstract class WPSEO_Option {
add_action( 'update_site_option_' . $this->option_name, [ 'WPSEO_Options', 'clear_cache' ], 1, 0 );
}
/*
* Make sure the option will always get validated, independently of register_setting()
* (only available on back-end).
@@ -194,7 +192,6 @@ abstract class WPSEO_Option {
/* Register our option for the admin pages */
add_action( 'admin_init', [ $this, 'register_setting' ] );
/* Set option group name if not given */
if ( ! isset( $this->group_name ) || $this->group_name === '' ) {
$this->group_name = 'yoast_' . $this->option_name . '_options';

View File

@@ -59,7 +59,7 @@ class WPSEO_Options {
protected function __construct() {
$this->register_hooks();
foreach ( static::$options as $option_name => $option_class ) {
foreach ( static::$options as $option_class ) {
static::register_option( call_user_func( [ $option_class, 'get_instance' ] ) );
}
}
@@ -559,7 +559,6 @@ class WPSEO_Options {
private static function get_lookup_table() {
$lookup_table = [];
foreach ( array_keys( static::$options ) as $option_name ) {
$full_option = static::get_option( $option_name );
foreach ( $full_option as $key => $value ) {

View File

@@ -409,7 +409,6 @@ class WPSEO_Taxonomy_Meta extends WPSEO_Option {
return $tax_meta;
}
if ( isset( $tax_meta[ 'wpseo_' . $meta ] ) ) {
return $tax_meta[ 'wpseo_' . $meta ];
}
@@ -477,7 +476,6 @@ class WPSEO_Taxonomy_Meta extends WPSEO_Option {
public static function get_keyword_usage( $keyword, $current_term_id, $current_taxonomy ) {
$tax_meta = self::get_tax_meta();
$found = [];
// @todo Check for terms of all taxonomies, not only the current taxonomy.
foreach ( $tax_meta as $taxonomy_name => $terms ) {

View File

@@ -457,7 +457,7 @@ class WPSEO_Sitemap_Image_Parser {
);
$gallery_attachments = [];
foreach ( $attachments as $key => $val ) {
foreach ( $attachments as $val ) {
$gallery_attachments[ $val->ID ] = $val;
}

View File

@@ -232,7 +232,7 @@ class WPSEO_Sitemaps_Renderer {
$output .= "\t\t\t<image:loc>" . $this->encode_and_escape( $img['src'] ) . "</image:loc>\n";
$output .= "\t\t</image:image>\n";
}
unset( $img, $title, $alt );
unset( $img );
$output .= "\t</url>\n";

View File

@@ -5,6 +5,8 @@
* @package WPSEO\XML_Sitemaps
*/
use Yoast\WP\SEO\Conditionals\Deactivating_Yoast_Seo_Conditional;
/**
* Rewrite setup and handling for sitemaps functionality.
*/
@@ -14,6 +16,10 @@ class WPSEO_Sitemaps_Router {
* Sets up init logic.
*/
public function __construct() {
// If we add rewrite rules during the plugin's deactivation, the flush_rewrite_rules that we perform afterwards won't properly flush those new rules.
if ( YoastSEO()->classes->get( Deactivating_Yoast_Seo_Conditional::class )->is_met() ) {
return;
}
add_action( 'init', [ $this, 'init' ], 1 );
add_filter( 'redirect_canonical', [ $this, 'redirect_canonical' ] );
@@ -24,7 +30,6 @@ class WPSEO_Sitemaps_Router {
* Sets up rewrite rules.
*/
public function init() {
global $wp;
$wp->add_query_var( 'sitemap' );

View File

@@ -540,26 +540,6 @@ class WPSEO_Sitemaps {
return YoastSEO()->helpers->date->format( self::get_last_modified_gmt( $post_types ) );
}
// phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Argument is kept for documentation purposes.
/**
* Notify search engines of the updated sitemap.
*
* @deprecated 19.2
*
* @codeCoverageIgnore
*
* @param string|null $url Optional URL to make the ping for.
*/
public static function ping_search_engines( $url = null ) {
_deprecated_function( __METHOD__, 'Yoast SEO 19.2', 'WPSEO_Sitemaps_Admin::ping_search_engines' );
$admin = new WPSEO_Sitemaps_Admin();
$admin->ping_search_engines();
}
// phpcs:enable
/**
* Get the maximum number of entries per XML sitemap.
*

View File

@@ -246,10 +246,11 @@ class WPSEO_Taxonomy_Sitemap_Provider implements WPSEO_Sitemap_Provider {
continue;
}
$url['loc'] = WPSEO_Taxonomy_Meta::get_term_meta( $term, $term->taxonomy, 'canonical' );
$canonical = WPSEO_Taxonomy_Meta::get_term_meta( $term, $term->taxonomy, 'canonical' );
$url['loc'] = get_term_link( $term, $term->taxonomy );
if ( ! is_string( $url['loc'] ) || $url['loc'] === '' ) {
$url['loc'] = get_term_link( $term, $term->taxonomy );
if ( is_string( $canonical ) && $canonical !== '' && $canonical !== $url['loc'] ) {
continue;
}
$url['mod'] = $wpdb->get_var( $wpdb->prepare( $sql, $term->taxonomy, $term->term_id ) );

View File

@@ -5,16 +5,3 @@
* @package WPSEO\Deprecated
*/
if ( ! function_exists( 'wpseo_cli_init' ) ) {
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
/**
* Initialize the WP-CLI integration.
*
* @deprecated 19.6.1
* @codeCoverageIgnore
*/
function wpseo_cli_init() {
_deprecated_function( __FUNCTION__, 'Yoast SEO 19.6.1' );
}
}