Skip to content

Commit

Permalink
Admin-UI: Avoid loading l10n too early in admin (#35279)
Browse files Browse the repository at this point in the history
When on a plan with anti-spam, the Akismet menu is being added during
the 'plugins_loaded' action, which is before the user has been
determined and so it loads the l10n in the site language for the
plugin's text domain.

Delay that addition until the 'admin_menu' action (at the same time as
when we remove Akismet's copy of the menu) to avoid triggering the l10n
so early.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/7699587618
  • Loading branch information
anomiex authored and matticbot committed Jan 29, 2024
1 parent e1288a9 commit f0c5295
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 102 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ext-openssl": "*",
"automattic/jetpack-a8c-mc-stats": "^2.0.0",
"automattic/jetpack-abtest": "^2.0.0",
"automattic/jetpack-admin-ui": "^0.3.1",
"automattic/jetpack-admin-ui": "^0.3.2-alpha",
"automattic/jetpack-assets": "^2.0.4",
"automattic/jetpack-autoloader": "^3.0.2",
"automattic/jetpack-backup": "^3.1.0",
Expand Down
8 changes: 8 additions & 0 deletions jetpack_vendor/automattic/jetpack-admin-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.2-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Fixed
- Wait until 'admin_menu' action to call `add_menu()`, to avoid triggering the l10n load too early.

## [0.3.1] - 2023-11-24

## [0.3.0] - 2023-11-20
Expand Down Expand Up @@ -132,6 +139,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixing menu visibility issues.

[0.3.2-alpha]: https://github.com/Automattic/jetpack-admin-ui/compare/0.3.1...0.3.2-alpha
[0.3.1]: https://github.com/Automattic/jetpack-admin-ui/compare/0.3.0...0.3.1
[0.3.0]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.25...0.3.0
[0.2.25]: https://github.com/Automattic/jetpack-admin-ui/compare/0.2.24...0.2.25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class Admin_Menu {

const PACKAGE_VERSION = '0.3.1';
const PACKAGE_VERSION = '0.3.2-alpha';

/**
* Whether this class has been initialized
Expand Down Expand Up @@ -50,18 +50,18 @@ public static function init() {
*/
private static function handle_akismet_menu() {
if ( class_exists( 'Akismet_Admin' ) ) {
// Prevent Akismet from adding a menu item.
add_action(
'admin_menu',
function () {
// Prevent Akismet from adding a menu item.
remove_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 );

// Add an Anti-spam menu item for Jetpack.
self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
},
4
);

// Add an Anti-spam menu item for Jetpack.
self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );

}
}

Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'packages' => array(
'jetpack-admin-ui' => array(
'path' => 'jetpack_vendor/automattic/jetpack-admin-ui',
'ver' => '0.3.1',
'ver' => '0.3.2-alpha1706547209',
),
'jetpack-assets' => array(
'path' => 'jetpack_vendor/automattic/jetpack-assets',
Expand Down
Loading

0 comments on commit f0c5295

Please sign in to comment.