slimline_tinymce_output_wp_editor() - slimline/tinymce GitHub Wiki
Main function of the plugin; adds TinyMCE to the edit page for terms and users.
/**
* Replaces default taxonomy and profile description textareas with an instance of
* the TinyMCE editor.
*
* @param object|string $object The term or user object being edited or the name of
* the taxonomy if on an add term screen.
* @link https://github.com/slimline/tinymce/wiki/slimline_tinymce_output_wp_editor()
* @since 0.1.0
*/
function slimline_tinymce_output_wp_editor( $object ) {
/**
* End the buffering started in slimline_tinymce_ob_start and get buffer contents
*/
$form_fields = ob_get_clean();
/**
* Set up wp_editor parameters based on which screen we are on.
*
* @link https://developer.wordpress.org/reference/functions/current_filter/
* Documentation of `current_filter` function
*/
if ( strpos( current_filter(), 'add' ) ) {
$description_id = 'tag-description';
$description_text = ''; // empty since it has not been set yet
} else { // if ( strpos( current_filter(), 'add' ) )
$description_id = 'description';
if ( $object instanceof WP_User ) {
$description_text = get_the_author_meta( 'description', $object->ID );
} else { // if ( $object instanceof WP_User )
$description_text = get_term_field( 'description', $object->term_id, $object->taxonomy, 'raw' );
} // if ( $object instanceof WP_User )
} // if ( strpos( current_filter(), 'add' ) )
/**
* Filter whether or not to show the media buttons
*
* @param bool Whether or not to include the TinyMCE media buttons. By default
* this is TRUE if the user can upload files, FALSE if not.
* @link https://codex.wordpress.org/Roles_and_Capabilities#upload_files
* Description of `upload_files` capability
* @since 0.3.0
*/
$media_buttons = apply_filters( 'slimline_tinymce_media_buttons', current_user_can( 'upload_files' ) );
/**
* Filter wp_editor args
*
* @param array Arguments for the wp_editor function. By default this will
* contain only the media_buttons argument filtered previously.
* @link https://developer.wordpress.org/reference/classes/_wp_editors/editor/
* Description of editor arguments
* @since 0.3.0
*/
$wp_editor_args = apply_filters( 'slimline_tinymce_editor_args', array( 'media_buttons' => $media_buttons ) );
/**
* Use 'description' as the textarea name for the editor or descriptions will not save properly
*/
$wp_editor_args[ 'textarea_name' ] = 'description';
/**
* Use the output buffer to get the wp_editor markup
*
* We are buffering the contents because wp_editor is an echo-only function and
* we need to return it as a string so we can do a preg_replace later.
*/
ob_start();
/**
* create the WordPress Editor
*
* @link https://developer.wordpress.org/reference/functions/wp_editor/
* Documentation of `wp_editor` function
*/
wp_editor( $description_text, $description_id, $wp_editor_args );
/**
* stop buffering and retrieve the markup
*/
$wp_editor = ob_get_clean();
/**
* Replace the description textarea with the editor instance
*/
echo preg_replace( '#<textarea name="description"([^>]+)>(.*)</textarea>#is', $wp_editor, $form_fields );
}
Fires on {$taxonomy}_add_form_fields
at priority 10 (when adding terms), {$taxonomy}_edit_form_fields
at priority 10 (for editing terms), edit_user_profile
at priority 10 (for add/editing other users) and show_user_profile
at priority 10 (for editing a user's own profile).
- Since 0.1.0