【发布时间】:2015-03-14 07:41:55
【问题描述】:
我有一个管理插件,里面有一个文章列表,旁边有一个“添加到帖子”按钮。单击该按钮后,我想重定向到“/wp-admin/post-new.php”并预先填写表格。
我可以在网址中设置标题,例如wp-admin/post-new.php?post_type=post&post_title=My Titlle。但是,如何预填充内容?
我读过一些类似this 的文章,但不是我要找的。p>
另外,内容每次都会不同,所以我不想设置为默认。
我现在在做什么:
我的 jQuery 按钮点击:
function add_to_post(id) {
var data = {
'action' : 'add_to_post',
'id' : id
};
$.ajax({
type : 'POST',
url : ajaxurl,
data : data
})
.done(function(){
var title = $(document.getElementById('title_'+id)).text();
var link = host+"/wp-admin/post-new.php?post_type=post&post_title="+title;
window.open(link,"_blank");
})
;
}
我的动作插件代码
add_action('wp_ajax_add_to_post','add_to_post_callback');
function add_to_post_callback() {
add_filter( 'default_content', 'my_editor_content', 10 , 2 );
wp_die();
}
function my_editor_content( $content ) {
$content = "This is some custom content I'm adding to the post editor because I hate re-typing it.";
return $content;
}
但是当我点击“添加到帖子”按钮时,内容仍然是空的 我将不胜感激。
阿曼。
【问题讨论】: