-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Co-authored-by: Dusty Reagan <[email protected]>
- Loading branch information
1 parent
507cf65
commit 19b851f
Showing
7 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/add-admin-interface-style-to-settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Settings: Add Admin Interface Style options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ts/packages/jetpack-mu-wpcom/src/features/wpcom-admin-interface/wpcom-admin-interface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
5 changes: 5 additions & 0 deletions
5
projects/plugins/mu-wpcom-plugin/changelog/add-admin-interface-style-to-settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: changed | ||
Comment: Updated composer.lock. | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.