Skip to content

Commit

Permalink
Add Admin Interface Style options to Settings > General (#37273)
Browse files Browse the repository at this point in the history
* Add Admin interface style to settings page
* Enable on Simple Sites with Early flag

---------

Co-authored-by: arthur <[email protected]>
Co-authored-by: Dusty Reagan <[email protected]>
  • Loading branch information
3 people authored May 8, 2024
1 parent 507cf65 commit 19b851f
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Settings: Add Admin Interface Style options.
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Additional wpcom_admin_interface option on settings.
*
* @package automattic/jetpack-mu-wpcom
*/

/**
* Add the Admin Interface Style setting on the General settings page.
* This setting allows users to switch between the classic WP-Admin interface and the WordPress.com legacy dashboard.
* The setting is stored in the wpcom_admin_interface option.
* The setting is displayed only if the has the wp-admin interface selected.
*/
function wpcomsh_wpcom_admin_interface_settings_field() {
add_settings_field( 'wpcom_admin_interface', '', 'wpcom_admin_interface_display', 'general', 'default' );

register_setting( 'general', 'wpcom_admin_interface', array( 'sanitize_callback' => '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 '<tr valign="top"><th scope="row"><label for="wpcom_admin_interface">' . esc_html__( 'Admin Interface Style', 'jetpack-mu-wpcom' ) . '</label></th><td>';
echo '<fieldset>';
echo '<label><input type="radio" name="wpcom_admin_interface" value="wp-admin" ' . checked( 'wp-admin', $value, false ) . '/> <span>' . esc_html__( 'Classic style', 'jetpack-mu-wpcom' ) . '</span></label><p>' . esc_html__( 'Use WP-Admin to manage your site.', 'jetpack-mu-wpcom' ) . '</p><br>';
echo '<label><input type="radio" name="wpcom_admin_interface" value="calypso" ' . checked( 'calypso', $value, false ) . '/> <span>' . esc_html__( 'Default style', 'jetpack-mu-wpcom' ) . '</span></label><p>' . esc_html__( 'Use WordPress.com’s legacy dashboard to manage your site.', 'jetpack-mu-wpcom' ) . '</p><br>';
echo '</fieldset>';
}

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 );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19b851f

Please sign in to comment.