slimline_add_user_tinymce() - slimline/tinymce GitHub Wiki
Adds TinyMCE hooks for user pages.
Developers can control when to add TinyMCE to user profiles using the slimline_add_user_tinymce
filter. By default TinyMCE will be added for any user who can manage other users.
Source
/**
* Init TinyMCE hooks for user pages.
*
* Adds the action hooks for replacing the bio / user description textarea with a
* TinyMCE editor. Using a separate function allows us to dynamically add the hooks
* based on user capabilities.
*
* @link https://github.com/slimline/tinymce/wiki/slimline_add_user_tinymce()
* @since 0.2.0
*/
function slimline_add_user_tinymce() {
/**
* Filter which users are allowed to use TinyMCE for user bios
*
* By default, only users who can contribute to the site are allowed to use HTML
* in user bios.
*
* @param bool Whether or not the current user is allowed to use the TinyMCE
* Editor for user bios. Defaults to TRUE is the user can also edit
* posts, FALSE if they cannot.
* @link https://codex.wordpress.org/Roles_and_Capabilities#edit_posts
* Description of `edit_posts` capability
* @since 0.3.0
*/
$add_user_tinymce = apply_filters( 'slimline_add_user_tinymce', current_user_can( 'edit_posts' ) );
if ( $add_user_tinymce ) {
/**
* Remove default user description filter.
*
* The default wp_filter_kses for user descriptions strips most HTML content,
* rendering the TinyMCE editor useless. We will add the same HTML filter as
* is used with posts later.
*
* @link https://developer.wordpress.org/reference/hooks/pre_user_description/
* Documentation of `pre_user_description` filter
*/
remove_filter( 'pre_user_description', 'wp_filter_kses' );
/**
* Replace default description textarea with a TinyMCE editor
*
* @link https://developer.wordpress.org/reference/hooks/edit_user_profile/
* Documentation of `edit_user_profile` hook
*/
add_action( 'edit_user_profile', 'slimline_tinymce_output_wp_editor', 0 );
/**
* Begin output buffering for profile description
*
* We force passing 0 parameters to prevent setting ob_start's callback
* parameter.
*
* @link https://developer.wordpress.org/reference/hooks/personal_options/
* Documentation of `personal_options` hook
*/
add_action( 'personal_options', 'ob_start', 1000, 0 );
/**
* Replace default description textarea with a TinyMCE editor
*
* @link https://developer.wordpress.org/reference/hooks/show_user_profile/
* Documentation of `show_user_profile` hook
*/
add_action( 'show_user_profile', 'slimline_tinymce_output_wp_editor', 0 );
/**
* Add posts HTML filter to user descriptions.
*
* @link https://developer.wordpress.org/reference/hooks/pre_user_description/
* Documentation of `pre_user_description` filter
*/
add_filter( 'pre_user_description', 'slimline_wp_filter_kses' );
} // if ( $add_user_tinymce )
}
Hook
Fires on load-profile.php
at priority 10 (for user editing their own profile) and load-user-edit.php
(for users editing another user's profile).
Changelog
- Since 0.2.0