diff --git a/includes/plugins/class-co-authors-plus.php b/includes/plugins/class-co-authors-plus.php index 62d8a79b21..4887ceb8f3 100644 --- a/includes/plugins/class-co-authors-plus.php +++ b/includes/plugins/class-co-authors-plus.php @@ -37,6 +37,8 @@ public static function init() { add_filter( 'coauthors_edit_author_cap', [ __CLASS__, 'coauthors_edit_author_cap' ] ); add_action( 'admin_init', [ __CLASS__, 'setup_custom_role_and_capability' ] ); add_action( 'template_redirect', [ __CLASS__, 'prevent_myaccount_update' ] ); + add_action( 'edit_user_profile', [ __CLASS__, 'edit_user_profile' ] ); + add_action( 'wp_update_user', [ __CLASS__, 'edit_user_profile_update' ] ); } /** @@ -103,5 +105,61 @@ public static function setup_custom_role_and_capability() { \update_option( self::SETTINGS_VERSION_OPTION_NAME, $current_settings_version ); } + + /** + * Save custom fields. + * + * @param int $user_id User ID. + */ + public static function edit_user_profile_update( $user_id ) { + if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'update-user_' . $user_id ) ) { + return; + } + + if ( ! current_user_can( 'edit_user', $user_id ) ) { + return false; + } + + $user = get_userdata( $user_id ); + if ( ! empty( $_POST['newspack_cap_custom_cap_option'] ) ) { + $user->add_role( self::CONTRIBUTOR_NO_EDIT_ROLE_NAME ); + } else { + $user->remove_role( self::CONTRIBUTOR_NO_EDIT_ROLE_NAME ); + } + } + + /** + * Add user profile fields. + * + * @param WP_User $user The current WP_User object. + */ + public static function edit_user_profile( $user ) { + $current_status = user_can( $user->ID, self::CONTRIBUTOR_NO_EDIT_ROLE_NAME ); + ?> +
+ +

+ + + + + + + +
+