Skip to content

Commit

Permalink
WordPress 6.7 compat: Removes early i18n calls to fix notices. (#40474)
Browse files Browse the repository at this point in the history
* Move admin menu initialization to the init hook.

* Changelogs.

* Added Config callbacks for package options.

* Removed the i18n call from deprecation notices for early calls.

* Changelog.

* Update projects/plugins/jetpack/functions.global.php

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>

---------

Co-authored-by: Brad Jorsch <anomiex@users.noreply.github.com>
  • Loading branch information
zinigor and anomiex authored Dec 9, 2024
1 parent d4db551 commit c2f3354
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Added a mechanism to use callbacks for package options.
4 changes: 4 additions & 0 deletions projects/packages/connection/src/identity-crisis/class-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ function ( $c1, $c2 ) {
continue;
}

if ( isset( $consumer['customContent'] ) && is_callable( $consumer['customContent'] ) ) {
$consumer['customContent'] = call_user_func( $consumer['customContent'] );
}

if ( isset( $_SERVER['REQUEST_URI'] ) && str_starts_with( filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ) ), $consumer['admin_page'] ) && strlen( $consumer['admin_page'] ) > $consumer_url_length ) {
$consumer_chosen = $consumer;
$consumer_url_length = strlen( $consumer['admin_page'] );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: compat

WordPress 6.7 Compatibility: Fixed notices caused by translation calls happening too early in the load order.
6 changes: 4 additions & 2 deletions projects/plugins/jetpack/functions.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ function jetpack_deprecated_function( $function, $replacement, $version ) { // p
) {
error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
sprintf(
/* Translators: 1. Function name. 2. Jetpack version number. */
__( 'The %1$s function will be removed from the Jetpack plugin in version %2$s.', 'jetpack' ),
doing_action( 'after_setup_theme' ) || did_action( 'after_setup_theme' ) ?
/* Translators: 1. Function name. 2. Jetpack version number. */
__( 'The %1$s function will be removed from the Jetpack plugin in version %2$s.', 'jetpack' )
: 'The %1$s function will be removed from the Jetpack plugin in version %2$s.',
$function,
$removed_version
)
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/social/changelog/move-admin-menu-to-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Moved the admin menu initialization to the init hook.
33 changes: 21 additions & 12 deletions projects/plugins/social/src/class-jetpack-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ public function __construct( $connection_manager = null ) {
// Set up the REST authentication hooks.
Connection_Rest_Authentication::init();

$page_suffix = Admin_Menu::add_menu(
__( 'Jetpack Social', 'jetpack-social' ),
_x( 'Social', 'The Jetpack Social product name, without the Jetpack prefix', 'jetpack-social' ),
'manage_options',
'jetpack-social',
array( $this, 'plugin_settings_page' ),
4
);

add_action( 'load-' . $page_suffix, array( $this, 'admin_init' ) );

// Init Jetpack packages
add_action(
'plugins_loaded',
Expand Down Expand Up @@ -93,6 +82,8 @@ function () {
1
);

add_action( 'init', array( $this, 'do_init' ) );

// Activate the module as the plugin is activated
add_action( 'admin_init', array( $this, 'do_plugin_activation_activities' ) );
add_action( 'activated_plugin', array( $this, 'redirect_after_activation' ) );
Expand All @@ -105,7 +96,6 @@ function () {
My_Jetpack_Initializer::init();
}
);
add_action( 'init', array( new Automattic\Jetpack\Social\Note(), 'init' ) );

$this->manager = $connection_manager ? $connection_manager : new Connection_Manager();

Expand All @@ -130,6 +120,25 @@ function () {
add_filter( 'jetpack_social_admin_script_data', array( $this, 'set_social_admin_script_data' ) );
}

/**
* Initialize the parts of the plugin that have to be initialized later than
* plugins_loaded is firing. This includes translated strings.
*/
public function do_init() {
$page_suffix = Admin_Menu::add_menu(
__( 'Jetpack Social', 'jetpack-social' ),
_x( 'Social', 'The Jetpack Social product name, without the Jetpack prefix', 'jetpack-social' ),
'manage_options',
'jetpack-social',
array( $this, 'plugin_settings_page' ),
4
);

add_action( 'load-' . $page_suffix, array( $this, 'admin_init' ) );

( new Automattic\Jetpack\Social\Note() )->init();
}

/**
* Initialize the admin resources.
*/
Expand Down

0 comments on commit c2f3354

Please sign in to comment.