Skip to content

Commit

Permalink
Allow site administrators to change the default editor for other users.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Paris committed Oct 2, 2019
1 parent 2099a42 commit 58ddd01
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions classic-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public static function init_actions() {
if ( $settings['allow-users'] ) {
// User settings.
add_action( 'personal_options_update', array( __CLASS__, 'save_user_settings' ) );
add_action( 'edit_user_profile_update', array( __CLASS__, 'save_user_settings' ) );
add_action( 'profile_personal_options', array( __CLASS__, 'user_settings' ) );
add_action( 'edit_user_profile', array( __CLASS__, 'user_settings') );
}
}

Expand Down Expand Up @@ -190,7 +192,7 @@ public static function remove_gutenberg_hooks( $remove = 'all' ) {

}

private static function get_settings( $refresh = 'no' ) {
private static function get_settings( $refresh = 'no', $opts_for_user = 0) {
/**
* Can be used to override the plugin's settings. Always hides the settings UI when used (as users cannot change the settings).
*
Expand Down Expand Up @@ -262,13 +264,14 @@ private static function get_settings( $refresh = 'no' ) {

// Override the defaults with the user options.
if ( ( ! isset( $GLOBALS['pagenow'] ) || $GLOBALS['pagenow'] !== 'options-writing.php' ) && $allow_users ) {
$user_options = get_user_option( 'classic-editor-settings' );

$user_options = get_user_option( 'classic-editor-settings', $opts_for_user);

if ( $user_options === 'block' || $user_options === 'classic' ) {
$editor = $user_options;
}
}

self::$settings = array(
'editor' => $editor,
'hide-settings-ui' => false,
Expand Down Expand Up @@ -383,8 +386,8 @@ public static function validate_option_allow_users( $value ) {
return 'disallow';
}

public static function settings_1() {
$settings = self::get_settings( 'refresh' );
public static function settings_1( $opts_for_user=0 ) {
$settings = self::get_settings( 'refresh', $opts_for_user );

?>
<div class="classic-editor-options">
Expand Down Expand Up @@ -427,13 +430,11 @@ public static function settings_2() {
/**
* Shown on the Profile page when allowed by admin.
*/
public static function user_settings() {
public static function user_settings( $user ) {
global $user_can_edit;
$settings = self::get_settings( 'update' );

if (
! defined( 'IS_PROFILE_PAGE' ) ||
! IS_PROFILE_PAGE ||
! $user_can_edit ||
! $settings['allow-users']
) {
Expand All @@ -446,7 +447,7 @@ public static function user_settings() {
<th scope="row"><?php _e( 'Default Editor', 'classic-editor' ); ?></th>
<td>
<?php wp_nonce_field( 'allow-user-settings', 'classic-editor-user-settings' ); ?>
<?php self::settings_1(); ?>
<?php self::settings_1( $user->ID ); ?>
</td>
</tr>
</table>
Expand Down

0 comments on commit 58ddd01

Please sign in to comment.