Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow site administrators to change the default editor for other users. #104

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions classic-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 @@ -198,7 +200,7 @@ public static function remove_gutenberg_hooks( $remove = 'all' ) {

}

private static function get_settings( $refresh = 'no' ) {
private static function get_settings( $refresh = 'no', $user_id = 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 @@ -270,7 +272,8 @@ 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', $user_id );

if ( $user_options === 'block' || $user_options === 'classic' ) {
$editor = $user_options;
Expand Down Expand Up @@ -402,8 +405,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( $user_id = 0 ) {
$settings = self::get_settings( 'refresh', $user_id );

?>
<div class="classic-editor-options">
Expand Down Expand Up @@ -446,13 +449,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 @@ -465,7 +466,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