- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 wp_editor 创建了一个前端编辑器,它可以正常工作。
经过测试,我注意到它会删除内容中插入的所有短代码。我调查了这个问题,发现是“ob_”(输出缓冲)移除了它们。如果我删除此输出缓冲,则短代码可以正常显示,但它会破坏我为编辑器创建的功能。
我如何保留下面使用的代码,但修改它以确保显示所有短代码?非常感谢任何帮助/想法,S。
if(!is_feed() && current_user_can( 'manage_network' ) ) :
function ps_add_post_editor($content) {
global $post;
$settings = array(
'wpautop' => true,
'media_buttons' => false
);
$content .= '<div id="content-edit-area" style="display:none;"><form action="" id="page-content-editor-panel" method="post"><span id="ajax_my_post_edit_nonce" class="hidden">' . wp_create_nonce( 'ajax_my_post_edit_nonce' ) . '</span>' . ps_get_wp_editor($post->post_content, 'textarea-' . $post->ID , $settings) . '<input type="submit" id="feesavebtn" value="Save" /></form><a href="#" id="cancelbtn">Cancel</a></div><br><br><div id="loadingmessage"><img src="'.get_template_directory_uri().'/images/loading.gif" /> saving...</div>
<style type="text/css">
#textarea-'.$post->ID.'_ifr, #textarea-'.$post->ID.' { min-height:700px !important; }
</style>
<script type="text/javascript">
jQuery(\'#page-content-editor-panel\').submit(function(){
var pageid = '.$post->ID.';
var content;
var editor = tinyMCE.get(\'textarea-'.$post->ID.'\');
if (editor) {
content = editor.getContent();
} else {
content = jQuery(\'#textarea-'.$post->ID.'\').val();
}
jQuery(\'#content-edit-area\').hide();
jQuery(\'#loadingmessage\').show();
jQuery.post(
ajaxurl,
{
\'action\':\'add_foobar\',
\'nonce\':jQuery(\'#ajax_my_post_edit_nonce\').text(),
\'post_id\':pageid,
\'post_data\':content
},
function(response){
window.location.reload(true);
}
);
return false;
});
</script>';
return $content;
}
function ps_get_wp_editor($content,$textarea,$settings) {
ob_start();
wp_editor($content, $textarea, $settings);
$edior_html_code = ob_get_contents();
ob_end_clean();
return $edior_html_code;
}
add_filter('the_content', 'ps_add_post_editor');
add_action('wp_ajax_add_foobar', 'prefix_ajax_add_foobar');
add_action('wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar');
function prefix_ajax_add_foobar() {
if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax_my_post_edit_nonce' ) ) {
$myfee_post = array();
$myfee_post['ID'] = $_POST['post_id'];
$myfee_post['post_content'] = $_POST['post_data'];
wp_update_post( $myfee_post );
die("This page has now been updated.");
} else {
die("Unable to process your request at this time.");
}
}
endif;
最佳答案
我不得不承认,我不完全确定你的目标是什么,但就其值(value)而言,这似乎对我有用:
remove_filter('the_content', 'do_shortcode', 11);
function ps_get_wp_editor($content,$textarea,$settings = array()) {
ob_start();
wp_editor($content, $textarea, $settings);
$editor_html_code = ob_get_contents();
ob_end_clean();
return $editor_html_code;
}
function ps_add_post_editor($content) {
global $post;
$post_content = $post->post_content;
$content = ps_get_wp_editor($post_content, 'ps-editor-' . $post->ID );
return $content;
}
add_filter('the_content', 'ps_add_post_editor');
function ps_eat_pants() {
return "eat pants has happened";
}
add_shortcode('eat_pants', 'ps_eat_pants');
问题是,如果你想像在后端编辑器中一样编辑短代码,你需要从“the_content”中删除“do_shortcode”过滤器,这样它就不会在显示时运行在前端。
我必须承认,我不知道您发布的代码实际上是如何工作的,我假设它要么打错了,要么断章取意。 =)
我的意思是,您实际上没有为您的函数提供所有必要的参数...
如果您更详细地解释您在做什么可能会有所帮助,但我希望这会有所帮助。
[编辑:哦,那个“eat_pants”东西只是一个测试简码...]
关于Wordpress wp_editor 简码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18508395/
我使用 wp_editor 创建了一个前端编辑器,它可以正常工作。 经过测试,我注意到它会删除内容中插入的所有短代码。我调查了这个问题,发现是“ob_”(输出缓冲)移除了它们。如果我删除此输出缓冲,则
我在循环中的插件中有以下代码,因此有多个所见即所得编辑器: 'tsort-contarea', 'media_buttons' => true, 'editor_height' =>
我正在创建一个 wordpress 网站,注册用户可以在前端通过 wp_editor() 创建自己的帖子,但只有一个帖子。 现在我想限制用户只能看到他上传的媒体。我在functions.php 中使用
我有一个名为 soto_property 的自定义帖子类型,我在其中添加了三个 wp_editor 作为帖子元,使用此代码 - wp_editor( htmlspecialchars_decode(
我为新闻通讯创建了一个自定义插件。我的表、数据库等一切都很好。我正在尝试创建一个所见即所得以允许用户在不知道任何 HTML 的情况下添加 HTML 元素。但是,wp_editor 没有正确显示,如此处
我正在尝试自定义幻灯片默认字段( slides field - Redux framework )以包含 wp 编辑器而不是文本区域(描述区域) 原始文件在这里:https://raw.githubu
在 CPT metabox 中,我使用的是 wp_editor()。第一个是通过 php 函数加载。但是,当我通过 jQuery 克隆表单字段时,它不会添加 wp_editor,而是添加简单的文本区域
我有一个 wordpress 页面,用户可以在其中从前端添加帖子。为此,我使用 WP_editor() 函数。 当我在一个新的 wordpress 页面中尝试这些功能时,我可以直接使用 tinyMCE
这是一个答案/解决方案而不是一个问题,即使我在我的开发环境中尝试过,仍然可能存在一些错误。 我最近尝试在小部件/菜单中使用wp_editor,经过一番搜索,我没有找到我想要的完整解决方案。 在我按小时
我在 wordpress 中设置了一个自定义管理页面,我正在使用 wp_editor() 函数来显示文本编辑器框,但是当我提交/发布表单时,文本会进入编辑器字段为空。 例如,参见(删节的)代码: ">
我正在创建一个带有管理设置页面的插件,我想使用设置 API。 我可以保存文本字段和复选框,但是当我使用 wp_editor 添加设置字段时,它没有保存..? 我以前使用 get_option 来完成此
我正在使用 WP 的 wp_editor api(使用 WP 版本 3.3.1)在 WordPress 用户个人资料页面中构建自定义传记字段。 当我添加任何内容时,WSYIWYG 编辑器不会将段落标签
我正在尝试向我的主题添加一些选项,并且添加了一个所见即所得文本区域,该文本区域的值将转到选项表(wp-options)。 这是我使用的代码: $settings = array( 'textare
我想将带有 TinyMCE 的 WP 编辑器添加到我的自定义文本小部件中,但它不会显示 TinyMCE 按钮,它只显示文本区域。当我在 page.php 上测试我的代码时,它运行良好 - 编辑器显示所
我正在尝试用 wp_editor() 替换文本区域 我的 textarea 表单元素如下所示: 然后我有: wp_editor( $content, 'post_text' ); 我遇到的问题是表单
我在 wordpress 管理页面上有 2 个 html 所见即所得编辑器。两者都使用 WP_EDITOR() 函数。第一个硬编码到页面中: 'create_txt','te
您可以为 wp_editor() 生成的 TinyMCE 文本区域设置占位符文本吗? http://codex.wordpress.org/Function_Reference/wp_editor 我
如何向 Wordpress 添加自定义属性 wp_editor 文本区域字段? 在官方文档中没有办法做到这一点。我需要向由 生成的文本区域添加客户端验证属性(data-bvalidator="requ
我正在创建一个 WordPress 插件。它具有通过 AJAX 添加产品时显示编辑器的功能,但编辑器未正确显示。 用户可以添加任意数量的产品,因此请记住,会有多个 wp_editor() 请参阅随附的
我有一个表单,正在尝试使用 serialize 将其转换为 AJAX。仅当用户开始在标题字段中输入时,大部分表单本身才会由 AJAX 加载。 这是 loadEditor 的代码
我是一名优秀的程序员,十分优秀!