Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call _load_textdomain_just_in_time correctly #21742

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c00450a
fix: dashboard problem/notification button styling
igorschoester Oct 21, 2024
ae350df
refactor: remove unneeded wrappers
igorschoester Oct 21, 2024
02622a6
feat!: add @tailwindcss/container-queries plugin
igorschoester Oct 21, 2024
c2abb20
feat: add container-queries dep
igorschoester Oct 21, 2024
d7ab0c1
fix: look at container width instead of screen width
igorschoester Oct 21, 2024
87cd0b8
fix: unset WP styles
igorschoester Oct 21, 2024
fdfbfe7
feat: center button text
igorschoester Oct 21, 2024
4c70f8b
fix: adjust spacing to match design
igorschoester Oct 21, 2024
5b3a8ec
fix: update snapshots
igorschoester Oct 22, 2024
56207fc
Bump version to 23.8-RC2
Oct 23, 2024
9f6762b
Request only necessary option and populate options cache only for the…
leonidasmi Oct 23, 2024
4fdc7e4
Move checking if attachments are disable inside the 'wpseo_accessible…
leonidasmi Oct 23, 2024
fe28c6d
Stop removing the upgrade notice since it's never added
leonidasmi Oct 23, 2024
684bde4
Move checking if we strip the category base inside the hooked functio…
leonidasmi Oct 23, 2024
2eee0a5
Make setting an option straight to the specific groupt it belongs to …
leonidasmi Oct 24, 2024
d89e221
Fix BC of class rewrite change
leonidasmi Oct 24, 2024
30138f5
Fix PHPCS
leonidasmi Oct 24, 2024
aa40fe4
Fix unit tests
leonidasmi Oct 24, 2024
b28111a
Get options related to posts asking only the wpseo option
leonidasmi Oct 25, 2024
ccc2372
Merge branch 'trunk' into 1871-wp-67-function-load_plugin_textdomain-…
leonidasmi Oct 25, 2024
927084c
Move enqueuing explanation assets in a later hook
leonidasmi Oct 29, 2024
7cc305a
Restore adding the WPSEO_Sitemaps instance in the global object
leonidasmi Oct 29, 2024
b9fd9a3
Check only for option key existence before priming cache
leonidasmi Oct 29, 2024
3c3bfbb
Use previous default value for enable_xml_sitemap option
leonidasmi Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion admin/class-admin-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private function register_premium_upsell_admin_block() {
* @return void
*/
private function load_xml_sitemaps_admin() {
if ( WPSEO_Options::get( 'enable_xml_sitemap', false ) ) {
if ( WPSEO_Options::get( 'enable_xml_sitemap', false, [ 'wpseo' ] ) ) {
new WPSEO_Sitemaps_Admin();
}
}
Expand Down
29 changes: 8 additions & 21 deletions admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ public function __construct() {
WPSEO_Options::maybe_set_multisite_defaults( false );
}

if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) {
add_action( 'created_category', [ $this, 'schedule_rewrite_flush' ] );
add_action( 'edited_category', [ $this, 'schedule_rewrite_flush' ] );
add_action( 'delete_category', [ $this, 'schedule_rewrite_flush' ] );
}
add_action( 'created_category', [ $this, 'schedule_rewrite_flush' ] );
add_action( 'edited_category', [ $this, 'schedule_rewrite_flush' ] );
add_action( 'delete_category', [ $this, 'schedule_rewrite_flush' ] );

if ( WPSEO_Options::get( 'disable-attachment' ) === true ) {
add_filter( 'wpseo_accessible_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );
}
add_filter( 'wpseo_accessible_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );

add_filter( 'plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
add_filter( 'network_admin_plugin_action_links_' . WPSEO_BASENAME, [ $this, 'add_action_link' ], 10, 2 );
Expand All @@ -75,8 +71,6 @@ public function __construct() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
}

$this->set_upsell_notice();

$this->initialize_cornerstone_content();

if ( WPSEO_Utils::is_plugin_network_active() ) {
Expand Down Expand Up @@ -119,6 +113,10 @@ public function __construct() {
* @return void
*/
public function schedule_rewrite_flush() {
if ( WPSEO_Options::get( 'stripcategorybase' ) !== true ) {
return;
}

// Bail if this is a multisite installation and the site has been switched.
if ( is_multisite() && ms_is_switched() ) {
return;
Expand Down Expand Up @@ -367,17 +365,6 @@ private function localize_admin_global_script() {
);
}

/**
* Sets the upsell notice.
*
* @return void
*/
protected function set_upsell_notice() {
$upsell = new WPSEO_Product_Upsell_Notice();
$upsell->dismiss_notice_listener();
$upsell->initialize();
}

/**
* Whether we are on the admin dashboard page.
*
Expand Down
10 changes: 8 additions & 2 deletions admin/filters/class-abstract-post-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function register_hooks() {
add_action( 'restrict_manage_posts', [ $this, 'render_hidden_input' ] );
}

if ( $this->is_filter_active() && $this->get_explanation() !== null ) {
if ( $this->is_filter_active() ) {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_explanation_assets' ] );
}
}
Expand All @@ -83,13 +83,19 @@ public function add_filter_links() {
* @return void
*/
public function enqueue_explanation_assets() {
$explanation = $this->get_explanation();

if ( $explanation === null ) {
return;
}

$asset_manager = new WPSEO_Admin_Asset_Manager();
$asset_manager->enqueue_script( 'filter-explanation' );
$asset_manager->enqueue_style( 'filter-explanation' );
$asset_manager->localize_script(
'filter-explanation',
'yoastFilterExplanation',
[ 'text' => $this->get_explanation() ]
[ 'text' => $explanation ]
);
}

Expand Down
4 changes: 2 additions & 2 deletions admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function __construct() {
$this->editor = new WPSEO_Metabox_Editor();
$this->editor->register_hooks();

$this->social_is_enabled = WPSEO_Options::get( 'opengraph', false ) || WPSEO_Options::get( 'twitter', false );
$this->is_advanced_metadata_enabled = WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta' ) === false;
$this->social_is_enabled = WPSEO_Options::get( 'opengraph', false, [ 'wpseo_social' ] ) || WPSEO_Options::get( 'twitter', false, [ 'wpseo_social' ] );
$this->is_advanced_metadata_enabled = WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta', null, [ 'wpseo' ] ) === false;

$this->seo_analysis = new WPSEO_Metabox_Analysis_SEO();
$this->readability_analysis = new WPSEO_Metabox_Analysis_Readability();
Expand Down
4 changes: 3 additions & 1 deletion inc/class-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static function is_post_type_indexable( $post_type_name ) {
* @return array The filtered array.
*/
public static function filter_attachment_post_type( array $post_types ) {
unset( $post_types['attachment'] );
if ( WPSEO_Options::get( 'disable-attachment' ) === true ) {
unset( $post_types['attachment'] );
}

return $post_types;
}
Expand Down
29 changes: 27 additions & 2 deletions inc/class-rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
add_filter( 'query_vars', [ $this, 'query_vars' ] );
add_filter( 'term_link', [ $this, 'no_category_base' ], 10, 3 );
add_filter( 'request', [ $this, 'request' ] );
add_filter( 'category_rewrite_rules', [ $this, 'category_rewrite_rules' ] );
add_filter( 'category_rewrite_rules', [ $this, 'category_rewrite_rules_wrapper' ] );

add_action( 'created_category', [ $this, 'schedule_flush' ] );
add_action( 'edited_category', [ $this, 'schedule_flush' ] );
Expand All @@ -32,7 +32,9 @@ public function __construct() {
* @return void
*/
public function schedule_flush() {
add_action( 'shutdown', 'flush_rewrite_rules' );
if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) {
add_action( 'shutdown', 'flush_rewrite_rules' );
}
}

/**
Expand All @@ -45,6 +47,10 @@ public function schedule_flush() {
* @return string
*/
public function no_category_base( $link, $term, $taxonomy ) {
if ( WPSEO_Options::get( 'stripcategorybase' ) !== true ) {
return $link;
}

if ( $taxonomy !== 'category' ) {
return $link;
}
Expand Down Expand Up @@ -91,6 +97,10 @@ public function query_vars( $query_vars ) {
* @return array<string> The query vars.
*/
public function request( $query_vars ) {
if ( WPSEO_Options::get( 'stripcategorybase' ) !== true ) {
return $query_vars;
}

if ( ! isset( $query_vars['wpseo_category_redirect'] ) ) {
return $query_vars;
}
Expand All @@ -99,6 +109,21 @@ public function request( $query_vars ) {
return [];
}

/**
* Wrapper for the category_rewrite_rules() below, so we can add the $rules param in a BC way.
*
* @param array<string> $rules Rewrite rules generated for the current permastruct, keyed by their regex pattern.
*
* @return array<string> The category rewrite rules.
*/
public function category_rewrite_rules_wrapper( $rules ) {
if ( WPSEO_Options::get( 'stripcategorybase' ) !== true ) {
return $rules;
}

return $this->category_rewrite_rules();
}

/**
* This function taken and only slightly adapted from WP No Category Base plugin by Saurabh Gupta.
*
Expand Down
8 changes: 2 additions & 6 deletions inc/class-upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ public function __construct() {
add_action( 'init', [ $this, 'upgrade_125' ] );
}

// Since 3.7.
$upsell_notice = new WPSEO_Product_Upsell_Notice();
$upsell_notice->set_upgrade_notice();

/**
* Filter: 'wpseo_run_upgrade' - Runs the upgrade hook which are dependent on Yoast SEO.
*
Expand Down Expand Up @@ -154,9 +150,9 @@ protected function add_upgrade_history( $current_version, $new_version ) {
*/
protected function finish_up( $previous_version = null ) {
if ( $previous_version ) {
WPSEO_Options::set( 'previous_version', $previous_version );
WPSEO_Options::set( 'previous_version', $previous_version, 'wpseo' );
}
WPSEO_Options::set( 'version', WPSEO_VERSION );
WPSEO_Options::set( 'version', WPSEO_VERSION, 'wpseo' );

// Just flush rewrites, always, to at least make them work after an upgrade.
add_action( 'shutdown', 'flush_rewrite_rules' );
Expand Down
2 changes: 1 addition & 1 deletion inc/class-wpseo-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class WPSEO_Meta {
*/
public static function init() {
foreach ( self::$social_networks as $option => $network ) {
if ( WPSEO_Options::get( $option, false ) === true ) {
if ( WPSEO_Options::get( $option, false, [ 'wpseo_social' ] ) === true ) {
foreach ( self::$social_fields as $box => $type ) {
self::$meta_fields['social'][ $network . '-' . $box ] = [
'type' => $type,
Expand Down
2 changes: 1 addition & 1 deletion inc/options/class-wpseo-option-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function get_instance() {
* @return void
*/
public function translate_defaults() {
self::$twitter_card_types['summary_large_image'] = __( 'Summary with large image', 'wordpress-seo' );
self::$twitter_card_types['summary_large_image'] = 'Summary with large image';
}

/**
Expand Down
42 changes: 26 additions & 16 deletions inc/options/class-wpseo-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ public static function get_option_names() {
/**
* Retrieve all the options for the SEO plugin in one go.
*
* @param array<string> $specific_options The option groups of the option you want to get.
*
* @return array Array combining the values of all the options.
*/
public static function get_all() {
static::$option_values = static::get_options( static::get_option_names() );
public static function get_all( $specific_options = [] ) {
$option_names = ( empty( $specific_options ) ) ? static::get_option_names() : $specific_options;
static::$option_values = static::get_options( $option_names );

return static::$option_values;
}
Expand Down Expand Up @@ -269,14 +272,15 @@ public static function get_option( $option_name ) {
/**
* Retrieve a single field from any option for the SEO plugin. Keys are always unique.
*
* @param string $key The key it should return.
* @param mixed $default_value The default value that should be returned if the key isn't set.
* @param string $key The key it should return.
* @param mixed $default_value The default value that should be returned if the key isn't set.
* @param array<string> $option_groups The option groups to retrieve the option from.
*
* @return mixed Returns value if found, $default_value if not.
*/
public static function get( $key, $default_value = null ) {
if ( static::$option_values === null ) {
static::prime_cache();
public static function get( $key, $default_value = null, $option_groups = [] ) {
if ( ! isset( static::$option_values[ $key ] ) ) {
static::prime_cache( $option_groups );
}
if ( isset( static::$option_values[ $key ] ) ) {
return static::$option_values[ $key ];
Expand All @@ -297,23 +301,26 @@ public static function clear_cache() {
/**
* Primes our cache.
*
* @param array<string> $option_groups The option groups to prime the cache with.
*
* @return void
*/
private static function prime_cache() {
static::$option_values = static::get_all();
private static function prime_cache( $option_groups = [] ) {
static::$option_values = static::get_all( $option_groups );
static::$option_values = static::add_ms_option( static::$option_values );
}

/**
* Retrieve a single field from an option for the SEO plugin.
*
* @param string $key The key to set.
* @param mixed $value The value to set.
* @param string $key The key to set.
* @param mixed $value The value to set.
* @param string $option_group The lookup table which represents the option_group where the key is stored.
*
* @return mixed|null Returns value if found, $default if not.
*/
public static function set( $key, $value ) {
$lookup_table = static::get_lookup_table();
public static function set( $key, $value, $option_group = '' ) {
$lookup_table = static::get_lookup_table( $option_group );

if ( isset( $lookup_table[ $key ] ) ) {
return static::save_option( $lookup_table[ $key ], $key, $value );
Expand Down Expand Up @@ -562,12 +569,15 @@ protected static function is_multisite() {
/**
* Retrieves a lookup table to find in which option_group a key is stored.
*
* @param string $option_group The option_group where the key is stored.
*
* @return array The lookup table.
*/
private static function get_lookup_table() {
$lookup_table = [];
private static function get_lookup_table( $option_group = '' ) {
$lookup_table = [];
$option_groups = ( $option_group === '' ) ? static::$options : [ $option_group => static::$options[ $option_group ] ];

foreach ( array_keys( static::$options ) as $option_name ) {
foreach ( array_keys( $option_groups ) as $option_name ) {
$full_option = static::get_option( $option_name );
foreach ( $full_option as $key => $value ) {
$lookup_table[ $key ] = $option_name;
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/options-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public function get( $key, $default_value = null ) {
/**
* Sets a single field to the options.
*
* @param string $key The key to set.
* @param mixed $value The value to set.
* @param string $key The key to set.
* @param mixed $value The value to set.
* @param string $option_group The lookup table which represents the option_group where the key is stored.
*
* @return mixed|null Returns value if found.
*/
public function set( $key, $value ) {
return WPSEO_Options::set( $key, $value );
public function set( $key, $value, $option_group = '' ) {
return WPSEO_Options::set( $key, $value, $option_group );
}

/**
Expand Down
Loading