Skip to content

Commit

Permalink
Update/redirect simple classic wpcom admin interface option update (#…
Browse files Browse the repository at this point in the history
…37921)

* Simple Classic: Redirect to Default interface after switching wpcom_admin_interface

* changelog

* Fix phan issues
  • Loading branch information
candy02058912 committed Jun 20, 2024
1 parent 06252e4 commit ae322cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Simple Classic: Redirect to Default interface after switching wpcom_admin_interface
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ function wpcom_admin_interface_display() {
// The option should always be available on atomic sites.
! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ||
// The option will be shown if the simple site has already changed to Classic which means they should have already passed the experiment gate.
// We can remove the redirection in wpcom_admin_interface_pre_update_option for simple sites after the experiment is finished.
( function_exists( 'wpcom_is_nav_redesign_enabled' ) && wpcom_is_nav_redesign_enabled() ) ) {
add_action( 'admin_init', 'wpcomsh_wpcom_admin_interface_settings_field' );
}

/**
* Track the wpcom_admin_interface_changed event.
*
* @param array $value The new value.
* @param string $value The new value.
* @return void
*/
function wpcom_admin_interface_track_changed_event( $value ) {
Expand All @@ -64,9 +65,9 @@ function wpcom_admin_interface_track_changed_event( $value ) {
* @access private
* @since 4.20.0
*
* @param array $new_value The new settings value.
* @param array $old_value The old settings value.
* @return array The value to update.
* @param string $new_value The new settings value.
* @param string $old_value The old settings value.
* @return string The value to update.
*/
function wpcom_admin_interface_pre_update_option( $new_value, $old_value ) {
if ( $new_value === $old_value ) {
Expand All @@ -83,6 +84,22 @@ function wpcom_admin_interface_pre_update_option( $new_value, $old_value ) {
}

if ( ( new Automattic\Jetpack\Status\Host() )->is_wpcom_simple() ) {
if ( 'calypso' === $new_value ) {
// Fixes https://github.com/Automattic/dotcom-forge/issues/7760.
// We can remove this code if the related code in wpcom_admin_interface_display is removed.
add_action(
'update_option_wpcom_admin_interface',
/**
* Redirects to the WordPress.com home page when the admin interface is changed to Calypso.
*
* @return never
*/
function () {
wp_safe_redirect( 'https://wordpress.com/home/' . wpcom_get_site_slug() );
exit;
}
);
}
return $new_value;
}

Expand Down

0 comments on commit ae322cb

Please sign in to comment.