From 19b851fe61b341536fe4226901df935d8fa2982f Mon Sep 17 00:00:00 2001 From: Gabriel Demichelis Date: Wed, 8 May 2024 19:21:10 -0300 Subject: [PATCH] Add Admin Interface Style options to Settings > General (#37273) * Add Admin interface style to settings page * Enable on Simple Sites with Early flag --------- Co-authored-by: arthur Co-authored-by: Dusty Reagan --- .../add-admin-interface-style-to-settings | 4 ++ .../packages/jetpack-mu-wpcom/composer.json | 2 +- .../packages/jetpack-mu-wpcom/package.json | 2 +- .../src/class-jetpack-mu-wpcom.php | 12 +++- .../wpcom-admin-interface.php | 70 +++++++++++++++++++ .../add-admin-interface-style-to-settings | 5 ++ .../plugins/mu-wpcom-plugin/composer.lock | 4 +- 7 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-admin-interface-style-to-settings create mode 100644 projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php create mode 100644 projects/plugins/mu-wpcom-plugin/changelog/add-admin-interface-style-to-settings diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-admin-interface-style-to-settings b/projects/packages/jetpack-mu-wpcom/changelog/add-admin-interface-style-to-settings new file mode 100644 index 0000000000000..965133d87434c --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-admin-interface-style-to-settings @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Settings: Add Admin Interface Style options. diff --git a/projects/packages/jetpack-mu-wpcom/composer.json b/projects/packages/jetpack-mu-wpcom/composer.json index 2db2934ced503..07e016b598eeb 100644 --- a/projects/packages/jetpack-mu-wpcom/composer.json +++ b/projects/packages/jetpack-mu-wpcom/composer.json @@ -56,7 +56,7 @@ }, "autotagger": true, "branch-alias": { - "dev-trunk": "5.28.x-dev" + "dev-trunk": "5.29.x-dev" }, "textdomain": "jetpack-mu-wpcom", "version-constants": { diff --git a/projects/packages/jetpack-mu-wpcom/package.json b/projects/packages/jetpack-mu-wpcom/package.json index f1a6ba02a1df8..e10a48e4b4ffa 100644 --- a/projects/packages/jetpack-mu-wpcom/package.json +++ b/projects/packages/jetpack-mu-wpcom/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@automattic/jetpack-mu-wpcom", - "version": "5.28.1-alpha", + "version": "5.29.0-alpha", "description": "Enhances your site with features powered by WordPress.com", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme", "bugs": { diff --git a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php index 87489ef6c8d66..56acddecbe8b2 100644 --- a/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php +++ b/projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php @@ -13,7 +13,7 @@ * Jetpack_Mu_Wpcom main class. */ class Jetpack_Mu_Wpcom { - const PACKAGE_VERSION = '5.28.1-alpha'; + const PACKAGE_VERSION = '5.29.0-alpha'; const PKG_DIR = __DIR__ . '/../'; const BASE_DIR = __DIR__ . '/'; const BASE_FILE = __FILE__; @@ -41,6 +41,7 @@ public static function init() { add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_rest_api_endpoints' ) ); add_action( 'plugins_loaded', array( __CLASS__, 'load_block_theme_previews' ) ); add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_command_palette' ) ); + add_action( 'plugins_loaded', array( __CLASS__, 'load_wpcom_admin_interface' ) ); // This feature runs only on simple sites. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { @@ -290,4 +291,13 @@ public static function load_wpcom_simple_odyssey_stats() { require_once __DIR__ . '/features/wpcom-simple-odyssey-stats/wpcom-simple-odyssey-stats.php'; } } + + /** + * Load WPCOM Admin Interface. + * + * @return void + */ + public static function load_wpcom_admin_interface() { + require_once __DIR__ . '/features/wpcom-admin-interface/wpcom-admin-interface.php'; + } } diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php new file mode 100644 index 0000000000000..7e3693fc209f1 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php @@ -0,0 +1,70 @@ + 'esc_attr' ) ); +} + +/** + * Display the wpcom_admin_interface setting on the General settings page. + */ +function wpcom_admin_interface_display() { + $value = get_option( 'wpcom_admin_interface' ); + + echo ''; + echo '
'; + echo '

' . esc_html__( 'Use WP-Admin to manage your site.', 'jetpack-mu-wpcom' ) . '


'; + echo '

' . esc_html__( 'Use WordPress.com’s legacy dashboard to manage your site.', 'jetpack-mu-wpcom' ) . '


'; + echo '
'; +} + +if ( ! empty( get_option( 'wpcom_classic_early_release' ) ) || ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) { + add_action( 'admin_init', 'wpcomsh_wpcom_admin_interface_settings_field' ); +} + +/** + * Update the wpcom_admin_interface option on wpcom as it's the persistent data. + * + * @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. + */ +function wpcom_admin_interface_pre_update_option( $new_value, $old_value ) { + if ( $new_value === $old_value ) { + return $new_value; + } + + if ( ! class_exists( 'Jetpack_Options' ) || ! class_exists( 'Automattic\Jetpack\Connection\Client' ) || ! class_exists( 'Automattic\Jetpack\Status\Host' ) ) { + return $new_value; + } + + if ( ( new Automattic\Jetpack\Status\Host() )->is_wpcom_simple() ) { + return $new_value; + } + + $blog_id = Jetpack_Options::get_option( 'id' ); + Automattic\Jetpack\Connection\Client::wpcom_json_api_request_as_user( + "/sites/$blog_id/hosting/admin-interface", + 'v2', + array( 'method' => 'POST' ), + array( 'interface' => $new_value ) + ); + + return $new_value; +} +add_filter( 'pre_update_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_update_option', 10, 2 ); diff --git a/projects/plugins/mu-wpcom-plugin/changelog/add-admin-interface-style-to-settings b/projects/plugins/mu-wpcom-plugin/changelog/add-admin-interface-style-to-settings new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/mu-wpcom-plugin/changelog/add-admin-interface-style-to-settings @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/mu-wpcom-plugin/composer.lock b/projects/plugins/mu-wpcom-plugin/composer.lock index 0a3b6d6c6b9e5..20dca73dc4bdb 100644 --- a/projects/plugins/mu-wpcom-plugin/composer.lock +++ b/projects/plugins/mu-wpcom-plugin/composer.lock @@ -688,7 +688,7 @@ "dist": { "type": "path", "url": "../../packages/jetpack-mu-wpcom", - "reference": "a2b95ed2cade4352f52bffc659c1da7b5de1d759" + "reference": "5f2878749d5270c40add7437c39d563c2e5f9981" }, "require": { "automattic/jetpack-assets": "@dev", @@ -716,7 +716,7 @@ }, "autotagger": true, "branch-alias": { - "dev-trunk": "5.28.x-dev" + "dev-trunk": "5.29.x-dev" }, "textdomain": "jetpack-mu-wpcom", "version-constants": {