_WP_Editors Class Reference

The _WP_Editors class facilitates adding the WordPress editor (TinyMCE and Quicktags) to pages. This is a private/internal class – use the public API functions like wp_editor() instead of calling methods directly.

File: wp-includes/class-wp-editor.php
Since: 3.3.0

Class Definition

php
#[AllowDynamicProperties]
final class _WP_Editors {
    public static $mce_locale;
    
    private static $mce_settings = array();
    private static $qt_settings  = array();
    private static $plugins      = array();
    private static $qt_buttons   = array();
    private static $ext_plugins;
    private static $baseurl;
    private static $first_init;
    private static $this_tinymce       = false;
    private static $this_quicktags     = false;
    private static $has_tinymce        = false;
    private static $has_quicktags      = false;
    private static $has_medialib       = false;
    private static $editor_buttons_css = true;
    private static $drag_drop_upload   = false;
    private static $translation;
    private static $tinymce_scripts_printed = false;
    private static $link_dialog_printed     = false;
}

Static Methods

parse_settings()

Parse default arguments for an editor instance.

php
public static function parse_settings( string $editor_id, array $settings ): array

Parameters:

ParameterTypeDescription
$editor_idstringHTML ID for the textarea and TinyMCE/Quicktags instances. Should not contain square brackets.
$settingsarrayArray of editor arguments (see below).

Settings Array:

KeyTypeDefaultDescription
wpautopbooltrue (or false if post has blocks)Whether to use wpautop()
media_buttonsbooltrueShow Add Media button
default_editorstring''Default editor: tinymce or html
drag_drop_uploadboolfalseEnable drag & drop uploading
textarea_namestring$editor_idName attribute for textarea
textarea_rowsint20Number of textarea rows
tabindexstring/int''Tabindex value
tabfocus_elementsstring':prev,:next'Tab focus navigation elements
editor_cssstring''Extra CSS with <style> tags
editor_classstring''Extra CSS classes for textarea
teenyboolfalseUse minimal editor config
_content_editor_dfwboolfalseDistraction-free writing mode
tinymcebool/arraytrueEnable TinyMCE or pass settings
quicktagsbool/arraytrueEnable Quicktags or pass settings
editor_heightintFixed height in pixels (50-5000)

Returns: array – Parsed arguments array.

Since: 3.3.0

Hooks:

  • wp_editor_settings – Filter settings before parsing

editor()

Outputs the HTML for a single instance of the editor.

php
public static function editor( string $content, string $editor_id, array $settings = array() ): void

Parameters:

ParameterTypeDescription
$contentstringInitial content for the editor
$editor_idstringHTML ID for the textarea and TinyMCE/Quicktags instances
$settingsarraySee parse_settings() for description

Since: 3.3.0

Hooks:

  • media_buttons – Action after default media buttons are displayed
  • the_editor – Filter the editor HTML markup
  • the_editor_content – Filter the default editor content

Example:

php
_WP_Editors::editor( 'Hello World', 'my_editor', array(
    'textarea_rows' => 10,
    'media_buttons' => false,
) );

editor_settings()

Configure TinyMCE and Quicktags settings for an editor instance.

php
public static function editor_settings( string $editor_id, array $set ): void

Parameters:

ParameterTypeDescription
$editor_idstringUnique editor identifier, e.g. ‘content’
$setarrayArray of editor arguments

Since: 3.3.0

Hooks:

  • quicktags_settings – Filter Quicktags settings
  • teeny_mce_plugins – Filter teenyMCE plugins list
  • mce_external_plugins – Filter external TinyMCE plugins
  • tiny_mce_plugins – Filter default TinyMCE plugins
  • mce_external_languages – Filter translations for external plugins
  • mce_css – Filter stylesheets loaded in TinyMCE
  • teeny_mce_buttons – Filter teeny toolbar buttons
  • mce_buttons – Filter first toolbar row
  • mce_buttons_2 – Filter second toolbar row
  • mce_buttons_3 – Filter third toolbar row
  • mce_buttons_4 – Filter fourth toolbar row
  • teeny_mce_before_init – Filter teenyMCE config before init
  • tiny_mce_before_init – Filter TinyMCE config before init

enqueue_scripts()

Enqueue editor scripts based on what’s needed.

php
public static function enqueue_scripts( bool $default_scripts = false ): void

Parameters:

ParameterTypeDefaultDescription
$default_scriptsboolfalseWhether to enqueue default scripts

Since: 3.3.0

Enqueued Scripts:

  • editor – If TinyMCE is used
  • quicktags – If Quicktags is used
  • wplink – If wplink plugin or link button is used
  • jquery-ui-autocomplete – For link search
  • media-upload – If media library is used
  • wp-embed – For embed support

Hooks:

  • wp_enqueue_editor – Fires when editor scripts/styles are enqueued

enqueue_default_editor()

Enqueue all editor scripts for post-page-load initialization.

php
public static function enqueue_default_editor(): void

Since: 4.8.0

Description:

Use this when you need to initialize the editor after the page has loaded. This enqueues all necessary scripts and adds the print_default_editor_scripts action to output configuration.

Example:

php
// In your plugin/theme
add_action( 'wp_enqueue_scripts', function() {
    wp_enqueue_editor();
} );

Print all editor scripts and default settings for post-page-load initialization.

php
public static function print_default_editor_scripts(): void

Since: 4.8.0

Hooks:

  • print_default_editor_scripts – Fires after all scripts and settings are printed

Output:

Outputs a JavaScript object window.wp.editor.getDefaultSettings() that returns default TinyMCE and Quicktags configuration.


get_mce_locale()

Returns the TinyMCE locale code.

php
public static function get_mce_locale(): string

Returns: string – ISO 639-1 two-letter language code (e.g., ‘en’, ‘de’, ‘fr’).

Since: 4.8.0


get_baseurl()

Returns the TinyMCE base URL.

php
public static function get_baseurl(): string

Returns: string – URL to TinyMCE directory (e.g., https://example.com/wp-includes/js/tinymce).

Since: 4.8.0


wp_mce_translation()

Get TinyMCE translation strings as JSON or JavaScript.

php
public static function wp_mce_translation( string $mce_locale = '', bool $json_only = false ): string

Parameters:

ParameterTypeDefaultDescription
$mce_localestring''The locale for the editor
$json_onlyboolfalseReturn only JSON (no JS calls)

Returns: string – JSON encoded translation object or JS snippet with tinymce.addI18n() call.

Since: 3.9.0

Hooks:

  • wp_mce_translation – Filter translated strings

force_uncompressed_tinymce()

Force uncompressed TinyMCE when a custom theme is defined.

php
public static function force_uncompressed_tinymce(): void

Since: 5.0.0

Description:

The compressed TinyMCE file cannot handle custom themes, so this ensures WordPress uses uncompressed TinyMCE when needed.


Print the main TinyMCE scripts.

php
public static function print_tinymce_scripts(): void

Since: 4.8.0

Description:

Outputs the TinyMCE JavaScript and translation strings. Only runs once per page.


editor_js()

Print the TinyMCE configuration and initialization scripts.

php
public static function editor_js(): void

Since: 3.3.0

Output:

Generates the tinyMCEPreInit JavaScript object containing:

  • baseURL – TinyMCE base URL
  • suffix – Script suffix (.min in production)
  • mceInit – TinyMCE initialization settings per editor
  • qtInit – Quicktags initialization settings per editor
  • ref – Reference settings (plugins, theme, language)

Hooks:

  • before_wp_tiny_mce – Before TinyMCE settings are printed
  • wp_tiny_mce_init – After tinymce.js is loaded, before instances are created
  • after_wp_tiny_mce – After TinyMCE instances are created

wp_fullscreen_html()

Output HTML for distraction-free writing mode.

php
public static function wp_fullscreen_html(): void

Since: 3.2.0
Deprecated: 4.3.0


Perform post queries for internal linking.

php
public static function wp_link_query( array $args = array() ): array|false

Parameters:

ParameterTypeDescription
$argsarrayQuery arguments

Args:

KeyTypeDefaultDescription
pagenumint1Page number
sstringSearch keywords

Returns: array|false – Array of results or false if none.

Result Array:

php
array(
    array(
        'ID'        => 123,           // Post ID
        'title'     => 'Post Title',  // Escaped post title
        'permalink' => 'https://...',  // Post permalink
        'info'      => '2024/01/15',  // Date or post type label
    ),
    // ...
)

Since: 3.1.0

Hooks:

  • wp_link_query_args – Filter query arguments
  • wp_link_query – Filter query results

Output the dialog HTML for internal linking.

php
public static function wp_link_dialog(): void

Since: 3.1.0

Description:

Outputs the modal dialog used by the wplink TinyMCE plugin for inserting/editing links. Only outputs once per page.


Private Methods

_parse_init()

Parse initialization array to JavaScript object string.

php
private static function _parse_init( array $init ): string

Parameters:

ParameterTypeDescription
$initarrayInitialization settings

Returns: string – JavaScript object literal string.

Since: 3.3.0


default_settings()

Returns the default TinyMCE settings.

php
private static function default_settings(): array

Returns: array – Default TinyMCE configuration (excludes plugins, buttons, selector).

Since: 4.8.0

Default Settings Include:

  • theme – ‘modern’
  • skin – ‘lightgray’
  • language – User’s locale
  • formats – Alignment and strikethrough formats
  • relative_urls – false
  • browser_spellcheck – true
  • resize – ‘vertical’
  • menubar – false
  • branding – false
  • content_css – Dashicons and wp-content.css

get_translation()

Get the translation strings array.

php
private static function get_translation(): array

Returns: array – Translated strings for TinyMCE UI.

Since: 4.7.0

Description:

Returns an array of translated strings for TinyMCE’s interface. Strings may be simple strings or arrays with format array( 'Label', 'keyboard_shortcut' ).


Properties

PropertyTypeDescription
$mce_localestringTinyMCE locale code
$mce_settingsarrayTinyMCE settings per editor ID
$qt_settingsarrayQuicktags settings per editor ID
$pluginsarrayEnabled TinyMCE plugins
$qt_buttonsarrayEnabled Quicktags buttons
$ext_pluginsstringExternal plugin initialization code
$baseurlstringTinyMCE base URL
$first_initarrayFirst-run initialization settings
$this_tinymceboolCurrent instance uses TinyMCE
$this_quicktagsboolCurrent instance uses Quicktags
$has_tinymceboolAny instance uses TinyMCE
$has_quicktagsboolAny instance uses Quicktags
$has_medialibboolAny instance uses media library
$editor_buttons_cssboolWhether to print editor-buttons CSS
$drag_drop_uploadboolDrag & drop upload enabled
$translationarrayCached translation strings
$tinymce_scripts_printedboolTinyMCE scripts already output
$link_dialog_printedboolLink dialog already output

Usage Notes

  1. Don’t use directly – Use wp_editor() wrapper function instead
  2. One-time init – TinyMCE cannot be safely moved in DOM after initialization
  3. ID restrictions – Editor IDs cannot contain square brackets (deprecated since 3.9.0)
  4. Meta boxes – Avoid TinyMCE in meta boxes; use Quicktags only or use edit_form_advanced action