?> <h3 class="handle"><?php echo $mb->get_the_value() ? substr(strip_tags(html_entity_decode($mb->get_the_value())), 0, 30) : 'Textarea Content'; ?> </h3> <div class="group-inside"> <p class="warning update-warning"><?php _e('Sort order has been changed. Remember to save the post to save these changes.'); ?> </p> <?php // 'html' is used for the "Text" editor tab. if ('html' === wp_default_editor()) { add_filter('the_editor_content', 'wp_htmledit_pre'); $switch_class = 'html-active'; } else { add_filter('the_editor_content', 'wp_richedit_pre'); $switch_class = 'tmce-active'; } ?> <div class="customEditor wp-core-ui wp-editor-wrap <?php echo 'tmce-active'; //echo $switch_class; ?> "> <div class="wp-editor-tools hide-if-no-js">
function motopressCEAddCEBtn() { global $motopressCESettings; global $motopressCELang; global $post; global $motopressCEIsjQueryVer; global $wp_version; $post_status = get_post_status(get_the_ID()); $isAutosaveEnabled = get_option('motopress-ce-autosave-autodraft', 1); $isMotopressLiteUpgraded = $motopressCESettings['license_type'] !== 'Lite' && get_site_option('motopress-ce-lite-status') === 'started'; if ($isMotopressLiteUpgraded) { ?> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','__mpcegaTracker'); __mpcegaTracker('create', 'UA-39340273-1', { 'allowLinker' : true }); </script> <?php } $CEButtonText = apply_filters('mpce_button_text', strtr($motopressCELang->CEButton, array('%BrandName%' => $motopressCESettings['brand_name']))); ?> <script type="text/javascript"> jQuery(document).ready(function($) { if (!Browser.IE && !Browser.Opera) { var motopressCEButton = $('<input />', { type: 'button', id: 'motopress-ce-btn', 'class': 'wp-core-ui button-primary', value: '<?php echo $CEButtonText; ?> ', 'data-post-id' : '<?php echo $post->ID; ?> ', disabled: 'disabled' }).insertAfter($('div#titlediv')); <?php if (extension_loaded('mbstring')) { ?> <?php if ($motopressCEIsjQueryVer) { ?> var preloader = $('#motopress-preload'); motopressCEButton.on('click', function() { //console.time('ce'); //console.profile(); preloader.show(); <?php if ($isMotopressLiteUpgraded) { ?> __mpcegaTracker('send', { 'hitType' : 'event', 'eventCategory' : 'mpce-event', 'eventAction' : 'mpce-lite-upgrade', 'eventLabel' : '<?php echo urlencode(wp_get_theme()); ?> ', 'hitCallback' : function(){ $.ajax({ url: motopress.ajaxUrl, type: 'POST', dataType: 'text', data: { action: 'motopress_ce_update_lite_status', nonce: motopressCE.nonces.motopress_ce_update_lite_status, status: 'upgraded' } }); } }); <?php } ?> <?php if ($post_status == 'auto-draft' && $isAutosaveEnabled && version_compare($wp_version, '3.6', '>=')) { ?> var postData = wp.autosave.getPostData(); if (postData.content.length || postData.excerpt.length || postData.post_title.length) { var pluginAutoSaved = sessionStorage.getItem('motopressPluginAutoSaved'); pluginAutoSaved = (pluginAutoSaved && pluginAutoSaved === 'true') ? true : false; if (!pluginAutoSaved){ sessionStorage.setItem('motopressPluginAutoOpen', true); sessionStorage.setItem('motopressPluginAutoSaved', true); window.onbeforeunload = null; $(window).off( 'beforeunload.edit-post' ); jQuery('form#post').submit(); return false; } } <?php } ?> sessionStorage.setItem('motopressPluginAutoSaved', false); if (typeof CE === 'undefined') { var head = $('head')[0]; var stealVerScript = $('<script />', { text: 'var steal = { production: "mp/ce/production.js" + motopress.pluginVersionParam };' })[0]; head.appendChild(stealVerScript); var script = $('<script />', { src: '<?php echo $motopressCESettings["plugin_root_url"]; ?> ' + '/' + '<?php echo $motopressCESettings["plugin_name"]; ?> ' + '/steal/steal.production.js?mp/ce' })[0]; head.appendChild(script); } }); function mpceOnEditorInit() { motopressCEButton.removeAttr('disabled'); if (pluginAutoOpen) { sessionStorage.setItem('motopressPluginAutoOpen', false); motopressCEButton.click(); } } var editorState = "<?php echo wp_default_editor(); ?> "; var pluginAutoOpen = sessionStorage.getItem('motopressPluginAutoOpen'); var paramPluginAutoOpen = ('<?php if (isset($_GET['motopress-ce-auto-open']) && $_GET['motopress-ce-auto-open']) { echo $_GET['motopress-ce-auto-open']; } ?> ' === 'true') ? true : false; //fix different site (WordPress Address) and home (Site Address) url for sessionStorage pluginAutoOpen = ((pluginAutoOpen && pluginAutoOpen === 'true') || paramPluginAutoOpen) ? true : false; if (pluginAutoOpen) preloader.show(); if (typeof tinyMCE !== 'undefined' && editorState === 'tinymce') { if (tinyMCE.majorVersion === '4') { tinyMCE.on('AddEditor', function(args){ if(args.editor.id === 'content'){ args.editor.on('init', function(ed){ mpceOnEditorInit(); }); } }); } else { tinyMCE.onAddEditor.add(function(mce, ed) { if (ed.editorId === 'content') { ed.onInit.add(function(ed) { mpceOnEditorInit(); }); } }); } } else { mpceOnEditorInit(); } <?php } else { add_action('admin_notices', 'motopressCEIsjQueryVerNotice'); } // endif jquery version check } else { add_action('admin_notices', 'motopressCEIsMBStringEnabledNotice'); } ?> } }); </script> <?php $isHideNativeEditor = apply_filters('mpce_hide_native_editor', false); if ($isHideNativeEditor) { ?> <style type="text/css"> #postdivrich{ display: none; } </style> <?php } }
/** * Outputs the HTML for a single instance of the editor. * * @static * @param string $content The initial content of the editor. * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers). * @param array $settings See the _parse_settings() method for description. */ public static function editor($content, $editor_id, $settings = array()) { $set = self::parse_settings($editor_id, $settings); $editor_class = ' class="' . trim(esc_attr($set['editor_class']) . ' wp-editor-area') . '"'; $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; $default_editor = 'html'; $buttons = $autocomplete = ''; $editor_id_attr = esc_attr($editor_id); if ($set['drag_drop_upload']) { self::$drag_drop_upload = true; } if (!empty($set['editor_height'])) { $height = ' style="height: ' . (int) $set['editor_height'] . 'px"'; } else { $height = ' rows="' . (int) $set['textarea_rows'] . '"'; } if (!current_user_can('upload_files')) { $set['media_buttons'] = false; } if (self::$this_tinymce) { $autocomplete = ' autocomplete="off"'; if (self::$this_quicktags) { $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor(); // 'html' is used for the "Text" editor tab. if ('html' !== $default_editor) { $default_editor = 'tinymce'; } $buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce" class="wp-switch-editor switch-tmce"' . ' data-wp-editor-id="' . $editor_id_attr . '">' . __('Visual') . "</button>\n"; $buttons .= '<button type="button" id="' . $editor_id_attr . '-html" class="wp-switch-editor switch-html"' . ' data-wp-editor-id="' . $editor_id_attr . '">' . _x('Text', 'Name for the Text editor tab (formerly HTML)') . "</button>\n"; } else { $default_editor = 'tinymce'; } } $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active'; $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class; if ($set['_content_editor_dfw']) { $wrap_class .= ' has-dfw'; } echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">'; if (self::$editor_buttons_css) { wp_print_styles('editor-buttons'); self::$editor_buttons_css = false; } if (!empty($set['editor_css'])) { echo $set['editor_css'] . "\n"; } if (!empty($buttons) || $set['media_buttons']) { echo '<div id="wp-' . $editor_id_attr . '-editor-tools" class="wp-editor-tools hide-if-no-js">'; if ($set['media_buttons']) { self::$has_medialib = true; if (!function_exists('media_buttons')) { include ABSPATH . 'wp-admin/includes/media.php'; } echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">'; /** * Fires after the default media button(s) are displayed. * * @since 2.5.0 * * @param string $editor_id Unique editor identifier, e.g. 'content'. */ do_action('media_buttons', $editor_id); echo "</div>\n"; } echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n"; echo "</div>\n"; } $quicktags_toolbar = ''; if (self::$this_quicktags) { if ('content' === $editor_id && !empty($GLOBALS['current_screen']) && $GLOBALS['current_screen']->base === 'post') { $toolbar_id = 'ed_toolbar'; } else { $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar'; } $quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar"></div>'; } /** * Filters the HTML markup output that displays the editor. * * @since 2.1.0 * * @param string $output Editor's HTML markup. */ $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' . $quicktags_toolbar . '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr($set['textarea_name']) . '" ' . 'id="' . $editor_id_attr . '">%s</textarea></div>'); // Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat). if (self::$this_tinymce) { add_filter('the_editor_content', 'format_for_editor', 10, 2); } /** * Filters the default editor content. * * @since 2.1.0 * * @param string $content Default editor content. * @param string $default_editor The default editor for the current user. * Either 'html' or 'tinymce'. */ $content = apply_filters('the_editor_content', $content, $default_editor); // Remove the filter as the next editor on the same page may not need it. if (self::$this_tinymce) { remove_filter('the_editor_content', 'format_for_editor'); } // Back-compat for the `htmledit_pre` and `richedit_pre` filters if ('html' === $default_editor && has_filter('htmledit_pre')) { // TODO: needs _deprecated_filter(), use _deprecated_function() as substitute for now _deprecated_function('add_filter( htmledit_pre )', '4.3.0', 'add_filter( format_for_editor )'); $content = apply_filters('htmledit_pre', $content); } elseif ('tinymce' === $default_editor && has_filter('richedit_pre')) { _deprecated_function('add_filter( richedit_pre )', '4.3.0', 'add_filter( format_for_editor )'); $content = apply_filters('richedit_pre', $content); } if (false !== stripos($content, 'textarea')) { $content = preg_replace('%</textarea%i', '</textarea', $content); } printf($the_editor, $content); echo "\n</div>\n\n"; self::editor_settings($editor_id, $set); }
function editor($content, $editor_id, $settings = array(), $media_buttons = true) { if (function_exists('wp_editor')) { $settings['media_buttons'] = $media_buttons; wp_editor($content, $editor_id, $settings); return; } $this->editor_ids[] = $editor_id; $set = wp_parse_args($settings, array('wpautop' => true, 'wp_buttons_css' => PODS_URL . '/ui/wp-editor/editor-buttons.css', 'editor_class' => 'wp-editor-area', 'upload_link_title' => 'Upload and insert images or other media', 'media_buttons_context' => '', 'textarea_rows' => get_option('default_post_edit_rows', 10))); if (!$set['wpautop']) { $set['apply_source_formatting'] = true; } $rows = (int) $set['textarea_rows']; $can_richedit = user_can_richedit(); $id = $editor_id; $default_editor = is_admin() ? wp_default_editor() : 'tinymce'; $default_editor = 'tinymce'; // default editor not working yet in code, so it's turned off for now $toolbar = ''; if (!current_user_can('upload_files')) { $media_buttons = false; } $this->media_buttons = $media_buttons; echo '<div id="wp-' . $id . '-wrap" class="wp-editor-wrap">'; if (!is_admin() && !empty($set['wp_buttons_css'])) { echo '<style type="text/css" scoped="scoped"> @import url("' . $set['wp_buttons_css'] . '"); ' . "</style>\n"; } if ($can_richedit || $media_buttons) { $toolbar .= '<div id="wp-' . $id . '-editor-tools" class="wp-editor-tools">'; if ($can_richedit) { $html_class = $tmce_class = ''; if ('html' == $default_editor) { add_filter('the_editor_content', 'wp_htmledit_pre'); $html_class = 'active '; } else { add_filter('the_editor_content', 'wp_richedit_pre'); $tmce_class = 'active '; } $toolbar .= '<a id="' . $id . '-html" class="' . $html_class . 'hide-if-no-js wp-switch-editor" onclick="wpEditor.s(this);return false;">' . __('HTML') . "</a>\n"; $toolbar .= '<a id="' . $id . '-tmce" class="' . $tmce_class . 'hide-if-no-js wp-switch-editor" onclick="wpEditor.s(this);return false;">' . __('Visual') . "</a>\n"; } if ($media_buttons) { global $post_ID; $href = add_query_arg(array('post_id' => (int) $post_ID, 'TB_iframe' => true), admin_url('media-upload.php')); $title = $set['upload_link_title']; $button = "<a href='" . esc_url($href) . "' id='{$id}-add_media' class='thickbox' title='{$title}'><img src='" . esc_url(admin_url('images/media-button-image.gif')) . "' alt='{$title}' onclick='return false;' /></a>"; $toolbar .= '<div id="wp-' . $id . '-media-buttons" class="hide-if-no-js wp-media-buttons">'; $toolbar .= $set['media_buttons_context'] . apply_filters('wp_upload_buttons', $button, $id); $toolbar .= "</div>\n"; } $toolbar .= "</div>\n"; } $the_editor = apply_filters('the_editor', '<div id="wp-' . $id . '-editor-container" class="wp-editor-container"><textarea class="' . $set['editor_class'] . '" rows="' . $rows . '" cols="40" name="' . $id . '" id="' . $id . '">%s</textarea></div>'); $the_editor_content = apply_filters('the_editor_content', $content); echo apply_filters('the_editor_toolbar', $toolbar); printf($the_editor, $the_editor_content); echo "\n</div>\n\n"; if (is_admin()) { add_action('admin_print_footer_scripts', array($this, 'editor_js'), 50); } else { add_action('wp_print_footer_scripts', array($this, 'editor_js')); } unset($set['wp_buttons_css'], $set['editor_class'], $set['upload_link_title'], $set['media_buttons_context'], $set['textarea_rows']); $this->settings[$editor_id] = $set; }
function render_field($field) { // global global $wp_version; // enqueue acf_enqueue_uploader(); // vars $id = uniqid('acf-editor-'); $default_editor = 'html'; $show_tabs = true; $button = ''; // get height $height = acf_get_user_setting('wysiwyg_height', 300); $height = max($height, 300); // minimum height is 300 // detect mode if (!user_can_richedit()) { $show_tabs = false; } elseif ($field['tabs'] == 'visual') { // case: visual tab only $default_editor = 'tinymce'; $show_tabs = false; } elseif ($field['tabs'] == 'text') { // case: text tab only $show_tabs = false; } elseif (wp_default_editor() == 'tinymce') { // case: both tabs $default_editor = 'tinymce'; } // must be logged in tp upload if (!current_user_can('upload_files')) { $field['media_upload'] = 0; } // mode $switch_class = $default_editor === 'html' ? 'html-active' : 'tmce-active'; // filter value for editor remove_filter('acf_the_editor_content', 'format_for_editor', 10, 2); remove_filter('acf_the_editor_content', 'wp_htmledit_pre', 10, 1); remove_filter('acf_the_editor_content', 'wp_richedit_pre', 10, 1); // WP 4.3 if (version_compare($wp_version, '4.3', '>=')) { add_filter('acf_the_editor_content', 'format_for_editor', 10, 2); $button = 'data-wp-editor-id="' . $id . '"'; // WP < 4.3 } else { $function = $default_editor === 'html' ? 'wp_htmledit_pre' : 'wp_richedit_pre'; add_filter('acf_the_editor_content', $function, 10, 1); $button = 'onclick="switchEditors.switchto(this);"'; } // filter $field['value'] = apply_filters('acf_the_editor_content', $field['value'], $default_editor); ?> <div id="wp-<?php echo $id; ?> -wrap" class="acf-editor-wrap wp-core-ui wp-editor-wrap <?php echo $switch_class; ?> " data-toolbar="<?php echo $field['toolbar']; ?> " data-upload="<?php echo $field['media_upload']; ?> "> <div id="wp-<?php echo $id; ?> -editor-tools" class="wp-editor-tools hide-if-no-js"> <?php if ($field['media_upload']) { ?> <div id="wp-<?php echo $id; ?> -media-buttons" class="wp-media-buttons"> <?php do_action('media_buttons', $id); ?> </div> <?php } ?> <?php if (user_can_richedit() && $show_tabs) { ?> <div class="wp-editor-tabs"> <button id="<?php echo $id; ?> -tmce" class="wp-switch-editor switch-tmce" <?php echo $button; ?> type="button"><?php echo __('Visual', 'acf'); ?> </button> <button id="<?php echo $id; ?> -html" class="wp-switch-editor switch-html" <?php echo $button; ?> type="button"><?php echo _x('Text', 'Name for the Text editor tab (formerly HTML)', 'acf'); ?> </button> </div> <?php } ?> </div> <div id="wp-<?php echo $id; ?> -editor-container" class="wp-editor-container"> <textarea id="<?php echo $id; ?> " class="wp-editor-area" name="<?php echo $field['name']; ?> " <?php if ($height) { ?> style="height:<?php echo $height; ?> px;"<?php } ?> ><?php echo $field['value']; ?> </textarea> </div> </div> <?php }
function render_field($field) { // enqueue acf_enqueue_uploader(); // vars $id = $field['id'] . '-' . uniqid(); $mode = 'html'; $show_tabs = true; // get height $height = acf_get_user_setting('wysiwyg_height', 300); $height = max($height, 300); // minimum height is 300 // detect mode if ($field['tabs'] == 'visual') { // case: visual tab only $mode = 'tmce'; $show_tabs = false; } elseif ($field['tabs'] == 'text') { // case: text tab only $show_tabs = false; } elseif (wp_default_editor() == 'tinymce') { // case: both tabs $mode = 'tmce'; } // mode $switch_class = $mode . '-active'; // filter value for editor remove_all_filters('acf_the_editor_content'); if ($mode == 'tmce') { add_filter('acf_the_editor_content', 'wp_richedit_pre'); } else { add_filter('acf_the_editor_content', 'wp_htmledit_pre'); } $field['value'] = apply_filters('acf_the_editor_content', $field['value']); ?> <div id="wp-<?php echo $id; ?> -wrap" class="acf-wysiwyg-wrap wp-core-ui wp-editor-wrap <?php echo $switch_class; ?> " data-toolbar="<?php echo $field['toolbar']; ?> " data-upload="<?php echo $field['media_upload']; ?> "> <div id="wp-<?php echo $id; ?> -editor-tools" class="wp-editor-tools hide-if-no-js"> <?php if ($field['media_upload']) { ?> <div id="wp-<?php echo $id; ?> -media-buttons" class="wp-media-buttons"> <?php do_action('media_buttons'); ?> </div> <?php } ?> <?php if (user_can_richedit() && $show_tabs) { ?> <div class="wp-editor-tabs"> <a id="<?php echo $id; ?> -html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);"><?php echo _x('Text', 'Name for the Text editor tab (formerly HTML)'); ?> </a> <a id="<?php echo $id; ?> -tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);"><?php echo __('Visual'); ?> </a> </div> <?php } ?> </div> <div id="wp-<?php echo $id; ?> -editor-container" class="wp-editor-container"> <textarea id="<?php echo $id; ?> " class="wp-editor-area" name="<?php echo $field['name']; ?> " <?php if ($height) { ?> style="height:<?php echo $height; ?> px;"<?php } ?> ><?php echo $field['value']; ?> </textarea> </div> </div> <?php }
function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) { $rows = get_option('default_post_edit_rows'); if (($rows < 3) || ($rows > 100)) $rows = 12; $rows = "rows='$rows'"; ?> <div id="editor-toolbar"> <?php if ( user_can_richedit() ) { $wp_default_editor = wp_default_editor(); ?> <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div> <?php if ( 'tinymce' == $wp_default_editor ) { add_filter('the_editor_content', 'wp_richedit_pre'); ?> <a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('HTML'); ?></a> <a id="edButtonPreview" class="active"><?php _e('Visual'); ?></a> <?php } elseif ( 'html' == $wp_default_editor ) { add_filter('the_editor_content', 'wp_htmledit_pre'); ?> <a id="edButtonHTML" class="active"><?php _e('HTML'); ?></a> <a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>');"><?php _e('Visual'); ?></a> <?php } } if ( $media_buttons ) { ?> <div id="media-buttons" class="hide-if-no-js"> <?php do_action( 'media_buttons' ); ?> </div> <?php } ?> </div> <div id="quicktags"> <?php wp_print_scripts( 'quicktags' ); ?> <script type="text/javascript">edToolbar()</script> </div> <?php if ( 'html' != $wp_default_editor ) : ?> <script type="text/javascript"> // <![CDATA[ if ( typeof tinyMCE != "undefined" ) document.getElementById("quicktags").style.display="none"; // ]]> </script> <?php endif; // 'html' != $wp_default_editor $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea class='' $rows cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n"); $the_editor_content = apply_filters('the_editor_content', $content); printf($the_editor, $the_editor_content); ?> <script type="text/javascript"> // <![CDATA[ edCanvas = document.getElementById('<?php echo $id; ?>'); <?php if ( $prev_id && user_can_richedit() ) : ?> // If tinyMCE is defined. if ( typeof tinyMCE != 'undefined' ) { // This code is meant to allow tabbing from Title to Post (TinyMCE). document.getElementById('<?php echo $prev_id; ?>').onkeydown = function (e) { e = e || window.event; if (e.keyCode == 9 && !e.shiftKey && !e.controlKey && !e.altKey) { if ( tinyMCE.activeEditor ) { if ( (jQuery("#post_ID").val() < 1) && (jQuery("#title").val().length > 0) ) { autosave(); } e = null; if ( tinyMCE.activeEditor.isHidden() ) return true; tinyMCE.activeEditor.focus(); return false; } return true; } } } <?php endif; ?> // ]]> </script> <?php }
public static function extend_tiny_mce($init) { if (wp_default_editor() == 'tinymce') { $init['setup'] = 'rich_scroll'; } return $init; }
function devfmt_initEditor($AEditor) { if ('tinymce' == wp_default_editor()) { $AEditor .= "<script language='JavaScript'><!--\n jQuery(document).ready(function(){ if(typeof(switchEditors) != \"undefined\"){ jQuery('textarea#content')[0].value = switchEditors.wpautop(jQuery('textarea#content')[0].value); } }); //-->\n</script>"; } return $AEditor; }
/** * Filters the WordPress editor widget, adding special reSt handling. * * WordPress uses a filter to allow plugins to change the HTML of the * editor widget. This is currently the only way to add another editor * interface, since we cannot influence the editor's HTML until the * "the_editor" filter is run. A reSt-specific toolbar is added to * the HTML (regardless of the "active" editor interface) as well as * an additional textarea, which is used to track the reSt source used * to render a Post/Page's HTML. * * When this filter is called, it is guaranteed that WordPress has already * installed it's own default "the_editor_content" filters. We remove * these here, so our own "the_editor_content" filter will be passed the * original Post/Page HTML. * * @param string $editor The HTML for the rendered editor widget. * * @return string * * @todo Store and retrieve reSt source for each post. */ public static function filterEditor($editor) { global $post; if (wp_default_editor() === 'rest') { /** * Strip the class from the editor to prevent auto-TinyMCE */ $editor = str_replace("class='theEditor'", '', $editor); /** * Disable the content transformations added by the other editors. * * <note> * This must be done as late as possible (after "the_editor" filter is * called) so the filters won't register themselves after we've * removed them. * </note> */ remove_filter('the_editor_content', 'wp_htmledit_pre'); remove_filter('the_editor_content', 'wp_richedit_pre'); /** * Add the reSt editor content filter. */ add_filter('the_editor_content', array(__CLASS__, 'filterEditorContent')); } /** * Create a reSt-specific toolbar. */ $prefix = '<div id="rest-toolbar"></div>'; /** * Either output a warning or the textarea for reSt source. */ if (!get_option('rst2html_path')) { /** * Display a warning if rst2html.py is not set up. */ $contents = '<p>No HTML convertor found! Please edit your <a href="'; $contents .= admin_url('options-general.php?page=rest-plugin-settings'); $contents .= '">' . self::$display_name . ' Settings</a>.</p>'; } else { /** * Get the current reSt source for this Page/Post. */ $rest_src = ''; if ($post->ID) { $rest_src = get_post_meta($post->ID, 'rest_src', true); } /** * Escape printf chars. */ $rest_src = str_replace('%', '%%', $rest_src); /** * Create a textarea to hold the reSt source. */ $contents = sprintf('<textarea cols=40 rows=10>%s</textarea>', htmlentities($rest_src)); } /** * Wrap the textarea or error message in a div. */ $suffix = '<div id="rest-container">' . $contents . '</div>'; /** * Always add the prefix and suffix to the editor we're given. */ $editor = $prefix . $editor . $suffix; /** * Continue processing by other filters. */ return $editor; }
/** * Denote the default editor for the user. * * Note that it would usually be ideal to expose this via a JS variable using wp_localize_script; however, it is * being printed here in order to guarantee that nothing changes this value before it would otherwise be printed. * The "after_wp_tiny_mce" action appears to be the most reliable place to print this variable. * * @since 1.0.0. * * @param array $settings TinyMCE settings. * @return void */ public function after_wp_tiny_mce($settings) { ?> <script type="text/javascript"> var ttfmakeMCE = '<?php echo esc_js(wp_default_editor()); ?> '; </script> <?php }
/** * prepare html data for editor */ function action_the_editor_content($content) { // if rich editing is on => wordpress adds autop which destroys our code // so we need to be there prior than WP. // See wp-includes/general-template.php [1500+] for more info // and "wp_htmledit_pre" vs. "wp_richedit_pre" // the filter functions added are: // a) wp_richedit_pre (wp-includes/formatting.php [1627]) = when tinymce is ACTIVE // b) wp_htmledit_pre (wp-includes/formatting.php [1649]) = when tinymce is INACTIVE if (wp_default_editor() != 'html') { $content = preg_replace('#<\\?php([\\s\\S]*?)\\?>#ie', '\'<img src="\' . PHP_EXECUTION_BASE_URL . \'/assets/trans.gif" class="mceWpPHP mceItemNoResize" title="php" alt="\' . base64_encode(stripslashes(\'\\0\')) . \'" />\'', $content); } return $content; }
/** * Extend TinyMCE config with a setup function. * See http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInit * * @since 0.1.0 * * @param array $init * @return array */ public static function template_tinymce_css($init) { global $typenow; if ($typenow == 'wpem-temps' || $_REQUEST['page'] == 'wpem_mail') { if (isset($_REQUEST['temp_id'])) { $post_id = absint($_REQUEST['temp_id']); } elseif (isset($_POST['schedule']['template']) && !empty($_POST['schedule']['template'])) { $post_id = absint($_POST['schedule']['template']); } else { global $post_id; } $css = get_post_meta($post_id, 'wpem_css-box-field', true); ?> <script type="text/javascript"> function addTempCSS( ed ) { ed.onInit.add( function() { tinyMCE.activeEditor.dom.addStyle(<?php echo json_encode($css); ?> ); } ); }; </script> <?php if (wp_default_editor() == 'tinymce') { $init['setup'] = 'addTempCSS'; } } return $init; }
/** * Extend TinyMCE config with a setup function. * See http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInit * http://wordpress.stackexchange.com/questions/120831/how-to-add-custom-css-theme-option-to-tinymce * @package Customizr * @since Customizr 3.2.11 * */ function tc_user_defined_tinymce_css($init) { if (!apply_filters('tc_add_custom_fonts_to_editor', true)) { return $init; } $_css = TC_resources::$instance->tc_write_fonts_inline_css('', 'mce-content-body'); ?> <script type="text/javascript"> function add_user_defined_CSS( ed ) { //http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x ed.on('init', function() { tinyMCE.activeEditor.dom.addStyle(<?php echo json_encode($_css); ?> ); } ); }; </script> <?php if (wp_default_editor() == 'tinymce') { $init['setup'] = 'add_user_defined_CSS'; } return $init; }
/** * @access private * @since 2.0 * @return void */ function _admin_print_footer_scripts() { if (wp_script_is('editor', 'done') && apply_filters("{$this->slug('hook')}-print-editor-fix", true)) { $this->_comment_tag(true); ?> <script type="text/javascript"> /* <![CDATA[ */ jQuery(function($) { var $div = $('<div/>'); $('body').bind('beforeWpautop', function(e, o) { o.data = o.data.replace(/<\?php.*?\?>/gim, function(str) { return $div.text(str).html(); }); }).bind('beforePreWpautop', function(e, o) { o.data = o.data.replace(/<!--\?php/gi, '<?php').replace(/\?-->/g, '?>').replace(/<\?php.*?\?>/gim, function(str) { return $div.html(str).text(); }); }); <?php if (user_can_richedit() && wp_default_editor() != 'html') { //are we using the visual editor? //the following fixes an issue were the visual editor doesnt display php ?> if (switchEditors.mode == '') { switchEditors.go('content'); switchEditors.go('content'); } <?php } ?> }); /* ]]> */ </script> <?php $this->_comment_tag(false); } if (wp_script_is('admin-widgets', 'done') && apply_filters("{$this->slug('hook')}-print-widget-fix", true)) { $this->_comment_tag(true); ?> <script type="text/javascript"> /* <![CDATA[ */ (function($) { if (wpWidgets) { var appendTitle = wpWidgets.appendTitle; wpWidgets.appendTitle = function(widget) { if ($('input.id_base[value="text"]', widget).length > 0) { var title = $('input[id*="-title"]', widget).val(); if (title) { title = title.replace(/</g, '<').replace(/>/g, '>'); $('.widget-top .widget-title .in-widget-title', widget).html(': ' + title); } } else appendTitle(widget); }; } })(jQuery); /* ]]> */ </script> <?php $this->_comment_tag(false); } }
/** * @internal */ protected function _get_defaults() { return array('tinymce' => true, 'media_buttons' => true, 'teeny' => false, 'wpautop' => true, 'editor_css' => '', 'reinit' => false, 'value' => '', 'size' => 'small', 'editor_type' => wp_default_editor(), 'editor_height' => 400); }
/** * Extend TinyMCE config with a setup function. * See http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInit * http://wordpress.stackexchange.com/questions/120831/how-to-add-custom-css-theme-option-to-tinymce * @package Customizr * @since Customizr 3.2.11 * */ function tc_user_defined_tinymce_css($init) { if (!apply_filters('tc_add_custom_fonts_to_editor', true)) { return $init; } //some plugins fire tiny mce editor in the customizer //in this case, the TC_resource class has to be loaded if (!class_exists('TC_resources')) { TC___::$instance->tc__(array('fire' => array(array('inc', 'resources'))), true); } //fonts $_css = TC_resources::$instance->tc_write_fonts_inline_css('', 'mce-content-body'); //icons $_css .= TC_resources::$instance->tc_get_inline_font_icons_css(); ?> <script type="text/javascript"> function add_user_defined_CSS( ed ) { //http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x ed.on('init', function() { tinyMCE.activeEditor.dom.addStyle(<?php echo json_encode($_css); ?> ); } ); }; </script> <?php if (wp_default_editor() == 'tinymce') { $init['setup'] = 'add_user_defined_CSS'; } return $init; }
/** * Display visual editor forms: TinyMCE, or HTML, or both. * * The amount of rows the text area will have for the content has to be between * 3 and 100 or will default at 12. There is only one option used for all users, * named 'default_post_edit_rows'. * * If the user can not use the rich editor (TinyMCE), then the switch button * will not be displayed. * * @since 2.1.0 * * @param string $content Textarea content. * @param string $id HTML ID attribute value. * @param string $prev_id HTML ID name for switching back and forth between visual editors. * @param bool $media_buttons Optional, default is true. Whether to display media buttons. * @param int $tab_index Optional, default is 2. Tabindex for textarea element. */ function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) { $rows = get_option('default_post_edit_rows'); if ($rows < 3 || $rows > 100) { $rows = 12; } if (!current_user_can('upload_files')) { $media_buttons = false; } $richedit = user_can_richedit(); $rows = "rows='{$rows}'"; if ($richedit || $media_buttons) { ?> <div id="editor-toolbar"> <?php if ($richedit) { $wp_default_editor = wp_default_editor(); ?> <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?> ')" /></div> <?php if ('html' == $wp_default_editor) { add_filter('the_editor_content', 'wp_htmledit_pre'); ?> <a id="edButtonHTML" class="active" onclick="switchEditors.go('<?php echo $id; ?> ', 'html');"><?php _e('HTML'); ?> </a> <a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?> ', 'tinymce');"><?php _e('Visual'); ?> </a> <?php } else { add_filter('the_editor_content', 'wp_richedit_pre'); ?> <a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?> ', 'html');"><?php _e('HTML'); ?> </a> <a id="edButtonPreview" class="active" onclick="switchEditors.go('<?php echo $id; ?> ', 'tinymce');"><?php _e('Visual'); ?> </a> <?php } } if ($media_buttons) { ?> <div id="media-buttons" class="hide-if-no-js"> <?php do_action('media_buttons'); ?> </div> <?php } ?> </div> <?php } ?> <div id="quicktags"> <?php wp_print_scripts('quicktags'); ?> <script type="text/javascript">edToolbar()</script> </div> <?php $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea {$rows} cols='40' name='{$id}' tabindex='{$tab_index}' id='{$id}'>%s</textarea></div>\n"); $the_editor_content = apply_filters('the_editor_content', $content); printf($the_editor, $the_editor_content); ?> <script type="text/javascript"> // <![CDATA[ edCanvas = document.getElementById('<?php echo $id; ?> '); <?php if (user_can_richedit() && $prev_id) { ?> var dotabkey = true; // If tinyMCE is defined. if ( typeof tinyMCE != 'undefined' ) { // This code is meant to allow tabbing from Title to Post (TinyMCE). jQuery('#<?php echo $prev_id; ?> ')[jQuery.browser.opera ? 'keypress' : 'keydown'](function (e) { if (e.which == 9 && !e.shiftKey && !e.controlKey && !e.altKey) { if ( (jQuery("#post_ID").val() < 1) && (jQuery("#title").val().length > 0) ) { autosave(); } if ( tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden() && dotabkey ) { e.preventDefault(); dotabkey = false; tinyMCE.activeEditor.focus(); return false; } } }); } <?php } ?> // ]]> </script> <?php }
function qtranxf_the_editor($editor_div) { // remove wpautop, which causes unmatched <p> on combined language strings if ('html' != wp_default_editor()) { remove_filter('the_editor_content', 'wp_richedit_pre'); add_filter('the_editor_content', 'qtranxf_htmledit_pre', 99); } return $editor_div; }
function jcl_the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) { $rows = get_option('default_post_edit_rows'); if ($rows < 3 || $rows > 100) { $rows = 12; } $richedit = true; //user_can_richedit(); $class = ''; if (true) { ?> <div id="editor-toolbar"> <?php if (true) { $wp_default_editor = wp_default_editor(); ?> <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?> ')" /></div> <?php if ('html' == $wp_default_editor) { add_filter('the_editor_content', 'wp_htmledit_pre'); ?> <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'html');"><?php _e('HTML'); ?> </a> <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'tinymce');"><?php _e('Visual'); ?> </a> <?php } else { $class = " class='theEditor'"; add_filter('the_editor_content', 'wp_richedit_pre'); ?> <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'html');"><?php _e('HTML'); ?> </a> <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'tinymce');"><?php _e('Visual'); ?> </a> <?php } } if (true) { ?> <div id="media-buttons" class="hide-if-no-js"> <?php //here are the Upload/Insert buttons top line do_action('media_buttons'); ?> </div> <?php } ?> </div> <?php } ?> <div id="quicktags"><?php //Quicktags don't seem to do much wp_print_scripts('quicktags'); ?> <script type="text/javascript"> document.write('<div id="ed_toolbar">'); for (var i = 0; i < edButtons.length; i++) { edShowButton(edButtons[i], i); } document.write('<input type="button" id="ed_spell" class="ed_button" onclick="edSpell(edCanvas);" title="' + quicktagsL10n.dictionaryLookup + '" value="' + quicktagsL10n.lookup + '" />'); document.write('<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags();" title="' + quicktagsL10n.closeAllOpenTags + '" value="' + quicktagsL10n.closeTags + '" />'); document.write('</div>'); </script> </div> <?php $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='{$rows}'{$class} cols='40' name='{$id}' tabindex='{$tab_index}' id='{$id}'>%s</textarea></div>\n"); $the_editor_content = apply_filters('the_editor_content', $content); printf($the_editor, $the_editor_content); ?> <script type="text/javascript"> edCanvas = document.getElementById('<?php echo $id; ?> '); </script> <?php }
function the_editor_content($content) { global $post; // New code format (stored encoded in database) if (2 == $this->get_code_format($post)) { // If TinyMCE is disabled or the HTML tab is set to be displayed first, we need to decode the HTML if (!user_can_richedit() || 'html' == wp_default_editor()) { $content = $this->decode_shortcode_contents($content); } } else { // If TinyMCE is enabled and is set to be displayed first, we need to encode the HTML if (user_can_richedit() && 'html' != wp_default_editor()) { $content = $this->encode_shortcode_contents($content); } } return $content; }
function render_field($field) { // enqueue acf_enqueue_uploader(); // vars $id = uniqid('acf-editor-'); //$id = $field['id'] . '-' . uniqid(); $mode = 'html'; $show_tabs = true; // get height $height = acf_get_user_setting('wysiwyg_height', 300); $height = max($height, 300); // minimum height is 300 // detect mode // case: visual tab only if ($field['tabs'] == 'visual') { $mode = 'tmce'; $show_tabs = false; } elseif ($field['tabs'] == 'text') { $show_tabs = false; } elseif (wp_default_editor() == 'tinymce') { $mode = 'tmce'; } // mode $switch_class = $mode . '-active'; // filter value for editor remove_all_filters('acf_the_editor_content'); if ($mode == 'tmce') { add_filter('acf_the_editor_content', 'wp_richedit_pre'); } else { add_filter('acf_the_editor_content', 'wp_htmledit_pre'); } global $q_config, $wp_version; $languages = qtrans_getSortedLanguages(true); $values = qtrans_split($field['value'], $quicktags = true); $currentLanguage = $this->plugin->get_active_language(); echo '<div class="multi-language-field multi-language-field-wysiwyg">'; foreach ($languages as $language) { $class = $language === $currentLanguage ? 'wp-switch-editor current-language' : 'wp-switch-editor'; echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; } $uid = uniqid('acf-editor-'); foreach ($languages as $language) { $value = apply_filters('acf_the_editor_content', $values[$language]); $id = $uid . "-{$language}"; $name = $field['name'] . "[{$language}]"; $class = $switch_class; if ($language === $currentLanguage) { $class .= ' current-language'; } ?> <div id="wp-<?php echo $id; ?> -wrap" class="acf-editor-wrap wp-core-ui wp-editor-wrap <?php echo $class; ?> " data-toolbar="<?php echo $field['toolbar']; ?> " data-upload="<?php echo $field['media_upload']; ?> " data-language="<?php echo $language; ?> "> <div id="wp-<?php echo $id; ?> -editor-tools" class="wp-editor-tools hide-if-no-js"> <?php if ($field['media_upload']) { ?> <div id="wp-<?php echo $id; ?> -media-buttons" class="wp-media-buttons"> <?php do_action('media_buttons'); ?> </div> <?php } ?> <?php if (user_can_richedit() && $show_tabs) { ?> <div class="wp-editor-tabs"> <button id="<?php echo $id; ?> -tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);" type="button"><?php echo __('Visual', 'acf'); ?> </button> <button id="<?php echo $id; ?> -html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);" type="button"><?php echo _x('Text', 'Name for the Text editor tab (formerly HTML)', 'acf'); ?> </button> </div> <?php } ?> </div> <div id="wp-<?php echo $id; ?> -editor-container" class="wp-editor-container"> <textarea id="<?php echo $id; ?> " class="qtx-wp-editor-area" name="<?php echo $name; ?> " <?php if ($height) { ?> style="height:<?php echo $height; ?> px;"<?php } ?> ><?php echo $value; ?> </textarea> </div> </div> <?php } echo '</div>'; }
public static function fix_wysiwyg_content($c) { //If the page is rendered with the WYSIWYG editor selected by default, content is processed in PHP land //instead of using the JS land "equivalent" logic (I quote equivalent because there are sooooo many //discrepancies between what JS wpautop and PHP wpautop functions do it's laughable.) if (wp_default_editor() == "tinymce") { //Our whitespace preservation logic breaks existing multiline html comments. //By wrapping them in hidden code blocks, we can preserve whitespace and hide the rendered content $c = preg_replace_callback('/<!--[\\s\\S]*-->/m', array('MP_WP_Preserved_Markup', 'comment_hack_callback'), $c); //First we inject temporary whitespace markers in pre and code elements because they won't //be corrupted when the user switches to html mode.* (actually IE9 will remove the first //newline from a pre tag if there are no non-whitespace characters before the newline.) $c = preg_replace_callback('/<(pre|code)[^>]*>[\\s\\S]+?<\\/\\1>/m', array('MP_WP_Preserved_Markup', 'content_replace_callback'), $c); //Now let's preserve whitespace with html comments so that they can be converted back when switching to //the html mode. FIXME: assuming four spaces is bad mmkay, what if I like only two spaces for a tab? //and this could produce bad markup if a user had <p class="test">hello</p> in their markup. So //work on a more flexible /\s/g approach when \s is inside or outside a tag definition $c = preg_replace("/(\r?\n)/", "\n<!--mep-nl-->", $c); //preserve new lines $c = preg_replace("/(\t|\\s\\s\\s\\s)/", " <!--mep-tab-->", $c); //preserve indents //Now we can restore all whitespace originally escaped in pre & code tags $c = preg_replace("/<mep-preserve-nl>/m", "\n", $c); $c = preg_replace("/<mep-preserve-tab>/m", "\t", $c); $c = preg_replace("/<mep-preserve-space>/m", " ", $c); //finish up with functions that WP normally calls on the_editor_content if (has_filter('the_content', 'convert_chars')) { $c = convert_chars($c); } $c = htmlspecialchars($c, ENT_NOQUOTES); $c = apply_filters('richedit_pre', $c); } return $c; }
public static function editor($content, $editor_id, $settings = array()) { $set = self::parse_settings($editor_id, $settings); $editor_class = ' class="' . trim($set['editor_class'] . ' wp-editor-area theEditor') . '"'; $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; $rows = ' rows="' . (int) $set['textarea_rows'] . '"'; $switch_class = 'html-active'; $buttons = ''; if (!current_user_can('upload_files')) { $set['media_buttons'] = FALSE; } if ($set['quicktags'] && $set['tinymce']) { $switch_class = 'html-active'; if ('html' == wp_default_editor()) { add_filter('the_editor_content', 'wp_htmledit_pre'); } else { add_filter('the_editor_content', 'wp_richedit_pre'); $switch_class = 'tmce-active'; } $buttons .= '<a id="' . $editor_id . '-html" class="hide-if-no-js wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . __('HTML') . "</a>\n"; $buttons .= '<a id="' . $editor_id . '-tmce" class="hide-if-no-js wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</a>\n"; } echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">'; wp_print_styles('editor-buttons'); if (!empty($set['editor_css'])) { echo $set['editor_css'] . "\n"; } if (!empty($buttons) || $set['media_buttons']) { echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools">'; if ($set['media_buttons']) { //self::$has_medialib = true; if (!function_exists('media_buttons')) { include ABSPATH . 'wp-admin/includes/media.php'; } echo '<div id="wp-' . $editor_id . '-media-buttons" class="hide-if-no-js wp-media-buttons">'; do_action('media_buttons', $editor_id); echo "</div>\n"; echo '<div class="wp-editor-tabs">'; echo $buttons; echo "</div>\n"; } echo "</div>\n"; } $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container"><textarea' . $editor_class . $rows . $tabindex . ' cols="40" name="' . $set['textarea_name'] . '" id="' . $editor_id . '">%s</textarea></div>'); $content = apply_filters('the_editor_content', $content); printf($the_editor, $content); echo "\n</div>\n\n"; ckeditor_wordpress::getInstance()->editor_js(); }
/** * Outputs the HTML for a single instance of the editor. * * @param string $content The initial content of the editor. * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers). * @param array $settings See the _parse_settings() method for description. */ public static function editor($content, $editor_id, $settings = array()) { $set = self::parse_settings($editor_id, $settings); $editor_class = ' class="' . trim($set['editor_class'] . ' wp-editor-area') . '"'; $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; $switch_class = 'html-active'; $toolbar = $buttons = $autocomplete = ''; if ($set['drag_drop_upload']) { self::$drag_drop_upload = true; } if (!empty($set['editor_height'])) { $height = ' style="height: ' . $set['editor_height'] . 'px"'; } else { $height = ' rows="' . $set['textarea_rows'] . '"'; } if (!current_user_can('upload_files')) { $set['media_buttons'] = false; } if (!self::$this_quicktags && self::$this_tinymce) { $switch_class = 'tmce-active'; $autocomplete = ' autocomplete="off"'; } elseif (self::$this_quicktags && self::$this_tinymce) { $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor(); $autocomplete = ' autocomplete="off"'; // 'html' is used for the "Text" editor tab. if ('html' === $default_editor) { add_filter('the_editor_content', 'wp_htmledit_pre'); $switch_class = 'html-active'; } else { add_filter('the_editor_content', 'wp_richedit_pre'); $switch_class = 'tmce-active'; } $buttons .= '<button type="button" id="' . $editor_id . '-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</button>\n"; $buttons .= '<button type="button" id="' . $editor_id . '-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . _x('Text', 'Name for the Text editor tab (formerly HTML)') . "</button>\n"; } $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class; if ($set['_content_editor_dfw']) { $wrap_class .= ' has-dfw'; } echo '<div id="wp-' . $editor_id . '-wrap" class="' . $wrap_class . '">'; if (self::$editor_buttons_css) { wp_print_styles('editor-buttons'); self::$editor_buttons_css = false; } if (!empty($set['editor_css'])) { echo $set['editor_css'] . "\n"; } if (!empty($buttons) || $set['media_buttons']) { echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools hide-if-no-js">'; if ($set['media_buttons']) { self::$has_medialib = true; if (!function_exists('media_buttons')) { include ABSPATH . 'wp-admin/includes/media.php'; } echo '<div id="wp-' . $editor_id . '-media-buttons" class="wp-media-buttons">'; /** * Fires after the default media button(s) are displayed. * * @since 2.5.0 * * @param string $editor_id Unique editor identifier, e.g. 'content'. */ do_action('media_buttons', $editor_id); echo "</div>\n"; } echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n"; echo "</div>\n"; } /** * Filter the HTML markup output that displays the editor. * * @since 2.1.0 * * @param string $output Editor's HTML markup. */ $the_editor = apply_filters('the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container">' . '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . $set['textarea_name'] . '" ' . 'id="' . $editor_id . '">%s</textarea></div>'); /** * Filter the default editor content. * * @since 2.1.0 * * @param string $content Default editor content. */ $content = apply_filters('the_editor_content', $content); printf($the_editor, $content); echo "\n</div>\n\n"; self::editor_settings($editor_id, $set); }
function qtrans_modifyRichEditor($old_content) { if (preg_match('~/wp-admin/comment.php$~i', $_SERVER['PHP_SELF'])) { return $old_content; } global $q_config; $init_editor = true; if (version_compare($GLOBALS['wp_version'], QT_SUPPORTED_WP_VERSION, '>')) { if (!(isset($_REQUEST['qtranslateincompatiblemessage']) && $_REQUEST['qtranslateincompatiblemessage'] == "shown")) { echo '<div class="updated" id="qtrans_imsg">' . __('The qTranslate Editor has disabled itself because it hasn\'t been tested with your Wordpress version yet. This is done to prevent Wordpress from malfunctioning. You can reenable it by <a href="javascript:qtrans_editorInit();" title="Activate qTranslate" id="qtrans_imsg_link">clicking here</a> (may cause <b>data loss</b>! Use at own risk!). To remove this message permanently, please update qTranslate to the <a href="http://www.qianqin.de/qtranslate/download/">corresponding version</a>.', 'qtranslate') . '</div>'; } $init_editor = false; } // save callback hook preg_match("/<textarea[^>]*id=\"([^']+)\"/", $old_content, $matches); $id = $matches[1]; preg_match("/cols=\"([^\"]+)\"/", $old_content, $matches); $cols = $matches[1]; // don't do anything if not editing the content if ($id != "content") { return $old_content; } // don't do anything to the editor if it's not rich if (!user_can_richedit()) { //echo '<p class="updated">'.__('The qTranslate Editor could not be loaded because WYSIWYG/TinyMCE is not activated in your profile.').'</p>'; return $old_content; } // remove wpautop if ('html' != wp_default_editor()) { remove_filter('the_editor_content', 'wp_richedit_pre'); } $content = ""; $content_append = ""; // create editing field for selected languages $qt_textarea = '<textarea id="qtrans_textarea_' . $id . '" name="qtrans_textarea_' . $id . '" tabindex="2" cols="' . $cols . '" style="display:none" onblur="qtrans_save(this.value);"></textarea>'; $old_content = preg_replace('#(<textarea[^>]*>.*</textarea>)#', '$1' . $qt_textarea, $old_content); // do some crazy js to alter the admin view $content .= "<script type=\"text/javascript\">\n// <![CDATA[\n"; // include needed js functions $content .= $q_config['js']['qtrans_is_array']; $content .= $q_config['js']['qtrans_xsplit']; $content .= $q_config['js']['qtrans_split']; $content .= $q_config['js']['qtrans_integrate']; $content .= $q_config['js']['qtrans_use']; $content .= $q_config['js']['qtrans_assign']; $content .= $q_config['js']['qtrans_save']; $content .= $q_config['js']['qtrans_integrate_title']; $content .= $q_config['js']['qtrans_get_active_language']; $content .= $q_config['js']['qtrans_hook_on_tinyMCE']; $content .= "function qtrans_editorInit1() {\n"; $content .= $q_config['js']['qtrans_switch']; // insert language, visual and html buttons $el = qtrans_getSortedLanguages(); foreach ($el as $language) { $content .= qtrans_insertTitleInput($language); } $el = qtrans_getSortedLanguages(true); foreach ($el as $language) { $content .= qtrans_createEditorToolbarButton($language, $id); } $content = apply_filters('qtranslate_toolbar', $content); // hide old title bar $content .= "document.getElementById('titlediv').style.display='none';\n"; $content .= "}\n"; $content .= "// ]]>\n</script>\n"; $content_append .= "<script type=\"text/javascript\">\n// <![CDATA[\n"; $content_append .= "function qtrans_editorInit2() {\n"; // show default language tab $content_append .= "document.getElementById('qtrans_select_" . $q_config['default_language'] . "').className='wp-switch-editor switch-tmce switch-html';\n"; // show default language $content_append .= "var text = document.getElementById('" . $id . "').value;\n"; $content_append .= "qtrans_assign('qtrans_textarea_" . $id . "',qtrans_use('" . $q_config['default_language'] . "',text));\n"; $content_append .= "}\n"; $content_append .= "function qtrans_editorInit3() {\n"; // make tinyMCE and mediauploader get the correct data $content_append .= $q_config['js']['qtrans_tinyMCEOverload']; $content_append .= $q_config['js']['qtrans_wpActiveEditorOverload']; $content_append .= "}\n"; $content_append .= $q_config['js']['qtrans_editorInit']; if ($init_editor) { $content_append .= $q_config['js']['qtrans_wpOnload']; } else { $content_append .= "var qtmsg = document.getElementById('qtrans_imsg');\n"; $content_append .= "var et = document.getElementById('wp-" . $id . "-editor-tools');\n"; $content_append .= "et.parentNode.insertBefore(qtmsg, et);\n"; } $content_append = apply_filters('qtranslate_modify_editor_js', $content_append); $content_append .= "// ]]>\n</script>\n"; return $content . $old_content . $content_append; }
/** * Display visual editor forms: TinyMCE, or HTML, or both. * * The amount of rows the text area will have for the content has to be between * 3 and 100 or will default at 12. There is only one option used for all users, * named 'default_post_edit_rows'. * * If the user can not use the rich editor (TinyMCE), then the switch button * will not be displayed. * * @since 2.1.0 * * @param string $content Textarea content. * @param string $id HTML ID attribute value. * @param string $prev_id HTML ID name for switching back and forth between visual editors. * @param bool $media_buttons Optional, default is true. Whether to display media buttons. * @param int $tab_index Optional, default is 2. Tabindex for textarea element. */ function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) { $rows = get_option('default_post_edit_rows'); if ($rows < 3 || $rows > 100) { $rows = 12; } if (!current_user_can('upload_files')) { $media_buttons = false; } $richedit = user_can_richedit(); $class = ''; if ($richedit || $media_buttons) { ?> <div id="editor-toolbar"> <?php if ($richedit) { $wp_default_editor = wp_default_editor(); ?> <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?> ')" /></div> <?php if ('html' == $wp_default_editor) { add_filter('the_editor_content', 'wp_htmledit_pre'); ?> <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'html');"><?php _e('HTML'); ?> </a> <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'tinymce');"><?php _e('Visual'); ?> </a> <?php } else { $class = " class='theEditor'"; add_filter('the_editor_content', 'wp_richedit_pre'); ?> <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'html');"><?php _e('HTML'); ?> </a> <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?> ', 'tinymce');"><?php _e('Visual'); ?> </a> <?php } } if ($media_buttons) { ?> <div id="media-buttons" class="hide-if-no-js"> <?php do_action('media_buttons'); ?> </div> <?php } ?> </div> <?php } ?> <div id="quicktags"><?php wp_print_scripts('quicktags'); ?> <script type="text/javascript">edToolbar()</script> </div> <?php $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='{$rows}'{$class} cols='40' name='{$id}' tabindex='{$tab_index}' id='{$id}'>%s</textarea></div>\n"); $the_editor_content = apply_filters('the_editor_content', $content); printf($the_editor, $the_editor_content); ?> <script type="text/javascript"> edCanvas = document.getElementById('<?php echo $id; ?> '); </script> <?php }
function wp_just_in_time_script_localization() { wp_localize_script('tiny_mce', 'wpTinyMCEConfig', array('defaultEditor' => wp_default_editor())); wp_localize_script('autosave', 'autosaveL10n', array('autosaveInterval' => AUTOSAVE_INTERVAL, 'previewPageText' => __('Preview this Page'), 'previewPostText' => __('Preview this Post'), 'requestFile' => get_option('siteurl') . '/wp-admin/admin-ajax.php', 'savingText' => __('Saving Draft…'))); }
public static function editor_js() { global $tinymce_version, $concatenate_scripts, $compress_scripts; /** * Filter "tiny_mce_version" is deprecated * * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE. * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter. * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code). */ $version = 'ver=' . $tinymce_version; $tmce_on = !empty(self::$mce_settings); if (!isset($concatenate_scripts)) { script_concat_settings(); } $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); if ($tmce_on && 'en' != self::$mce_locale) { include_once ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php'; } $mceInit = $qtInit = ''; if ($tmce_on) { foreach (self::$mce_settings as $editor_id => $init) { $options = self::_parse_init($init); $mceInit .= "'{$editor_id}':{$options},"; } $mceInit = '{' . trim($mceInit, ',') . '}'; } else { $mceInit = '{}'; } if (!empty(self::$qt_settings)) { foreach (self::$qt_settings as $editor_id => $init) { $options = self::_parse_init($init); $qtInit .= "'{$editor_id}':{$options},"; } $qtInit = '{' . trim($qtInit, ',') . '}'; } else { $qtInit = '{}'; } $ref = array('plugins' => implode(',', self::$plugins), 'theme' => 'advanced', 'language' => self::$mce_locale); $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '_src' : ''; do_action('before_wp_tiny_mce', self::$mce_settings); ?> <script type="text/javascript"> tinyMCEPreInit = { base : "<?php echo self::$baseurl; ?> ", suffix : "<?php echo $suffix; ?> ", query : "<?php echo $version; ?> ", mceInit : <?php echo $mceInit; ?> , qtInit : <?php echo $qtInit; ?> , ref : <?php echo self::_parse_init($ref); ?> , load_ext : function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');} }; </script> <?php $baseurl = self::$baseurl; if ($tmce_on) { if ($compressed) { echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&{$version}'></script>\n"; } else { echo "<script type='text/javascript' src='{$baseurl}/tiny_mce.js?{$version}'></script>\n"; echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce-schema.js?{$version}'></script>\n"; } if ('en' != self::$mce_locale && isset($lang)) { echo "<script type='text/javascript'>\n{$lang}\n</script>\n"; } else { echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?{$version}'></script>\n"; } } $mce = self::$has_tinymce && wp_default_editor() == 'tinymce' || !self::$has_quicktags; ?> <script type="text/javascript"> var wpActiveEditor; (function(){ var init, ed, qt, first_init, DOM, el, i, mce = <?php echo (int) $mce; ?> ; if ( typeof(tinymce) == 'object' ) { DOM = tinymce.DOM; // mark wp_theme/ui.css as loaded DOM.files[tinymce.baseURI.getURI() + '/themes/advanced/skins/wp_theme/ui.css'] = true; DOM.events.add( DOM.select('.wp-editor-wrap'), 'mousedown', function(e){ if ( this.id ) wpActiveEditor = this.id.slice(3, -5); }); for ( ed in tinyMCEPreInit.mceInit ) { if ( first_init ) { init = tinyMCEPreInit.mceInit[ed] = tinymce.extend( {}, first_init, tinyMCEPreInit.mceInit[ed] ); } else { init = first_init = tinyMCEPreInit.mceInit[ed]; } if ( mce ) try { tinymce.init(init); } catch(e){} } } else { if ( tinyMCEPreInit.qtInit ) { for ( i in tinyMCEPreInit.qtInit ) { el = tinyMCEPreInit.qtInit[i].id; if ( el ) document.getElementById('wp-'+el+'-wrap').onmousedown = function(){ wpActiveEditor = this.id.slice(3, -5); } } } } if ( typeof(QTags) == 'function' ) { for ( qt in tinyMCEPreInit.qtInit ) { try { quicktags( tinyMCEPreInit.qtInit[qt] ); } catch(e){} } } })(); <?php if (self::$ext_plugins) { echo self::$ext_plugins . "\n"; } if (!$compressed && $tmce_on) { ?> (function(){var t=tinyMCEPreInit,sl=tinymce.ScriptLoader,ln=t.ref.language,th=t.ref.theme,pl=t.ref.plugins;sl.markDone(t.base+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'.js');sl.markDone(t.base+'/themes/'+th+'/langs/'+ln+'_dlg.js');sl.markDone(t.base+'/themes/advanced/skins/wp_theme/ui.css');tinymce.each(pl.split(','),function(n){if(n&&n.charAt(0)!='-'){sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'.js');sl.markDone(t.base+'/plugins/'+n+'/langs/'+ln+'_dlg.js');}});})(); <?php } if (!is_admin()) { echo 'var ajaxurl = "' . admin_url('admin-ajax.php', 'relative') . '";'; } ?> </script> <?php if (in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true)) { self::wp_link_dialog(); } if (in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true)) { self::wp_fullscreen_html(); } do_action('after_wp_tiny_mce', self::$mce_settings); }
function MultilineTextboxInterface($customField, $inputName, $groupCounter, $fieldCounter) { $customFieldId = ''; if (isset($_REQUEST['post'])) { $customFieldId = $customField->id; $value = RCCWP_CustomField::GetCustomFieldValues(true, $_REQUEST['post'], $customField->name, $groupCounter, $fieldCounter); $value = apply_filters('the_editor_content', $value); } else { $value = $customField->value; } $inputHeight = (int) $customField->properties['height']; $inputWidth = (int) $customField->properties['width']; if ($customField->required_field) { $requiredClass = "field_required"; } ?> <?php $wp_default_editor = wp_default_editor(); if ('html' == $wp_default_editor) { ?> <script type="text/javascript"> Event.observe(window, 'load', function() { tinyMCE.execCommand('mceAddControl', true, "content"); switchEditors.go('content', 'html'); }); </script> <?php } $hide_visual_editor = RCCWP_Options::Get('hide-visual-editor'); if ($hide_visual_editor == '' || $hide_visual_editor == 0) { ?> <script type="text/javascript"> Event.observe(window, 'load', function() { tinyMCE.execCommand('mceAddControl', true, "<?php echo $inputName; ?> "); }); function add_editor(id){ tinyMCE.execCommand('mceAddControl', false, id); } function del_editor(id){ tinyMCE.execCommand('mceRemoveControl', false, id); } </script> <?php } ?> <style> .tab_multi_flutter { padding-bottom:30px; display: block; margin-right:10px; } .edButtonHTML_flutter { background-color:#F1F1F1; border-color:#DFDFDF; color:#999999; margin-right:15px; border-style:solid; border-style:solid; border-width:1px; cursor:pointer; display:block; float:right; height:18px; margin:5px 5px 0 0; padding:4px 5px 2px; } .edButtonPreview_flutter { background-color:#F1F1F1; border-color:#DFDFDF; color:#999999; margin-right:15px; border-style:solid; border-style:solid; border-width:1px; cursor:pointer; display:block; float:right; height:18px; margin:5px 5px 0 0; padding:4px 5px 2px; } </style> <?php if ($hide_visual_editor == '' || $hide_visual_editor == 0) { ?> <div class="tab_multi_flutter"> <a onclick="del_editor('<?php echo $inputName; ?> ');" class="edButtonHTML_flutter">HTML</a> <a onclick="add_editor('<?php echo $inputName; ?> ');" class="edButtonHTML_flutter" >Visual</a> </div> <?php } ?> <div class="mul_flutter"> <textarea class="<?php echo $requiredClass; ?> " tabindex="3" id="<?php echo $inputName; ?> " name="<?php echo $inputName; ?> " rows="<?php echo $inputHeight; ?> " cols="<?php echo $inputWidth; ?> "><?php echo $value; ?> </textarea> </div> <?php }