wordpress收费下载资源主题
wordpress付费下载资源插件

WordPress 如何实现删除文章并通知投稿作者不通过理由

我们的modown主题里有通知功能,那么如何实现删除待审文章时附上不通过的理由并通知投稿作者呢?

下面模板兔附上一个简单的代码供参考:

add_action( 'post_submitbox_misc_actions', 'modown_delete_notice_metabox' );
function modown_delete_notice_metabox(){
global $post;
echo '<div class="misc-pub-section"><a href="javascript:;" class="submitdelete modown-delete-notice" data-id="'.$post->ID.'">移动至回收站并通知作者</a></div>

<script>
jQuery(".modown-delete-notice").click(function(){
var ret = prompt("删除理由", "");
if(ret !== null && ret != "") {
//console.log(ret);
jQuery.ajax({
url: ajaxurl,
data: {
pid: jQuery(this).data("id"),
why: ret,
action: "modown_delete_notice"
},
dataType: "json",
type: "POST",
success: function(t) {
if(t.status == 1){
location.href="/wp-admin/edit.php";
}else{
alert(t.msg);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {

}
})
}
});
</script>
';
}


function modown_delete_notice_callback(){
global $wpdb,$current_user;
date_default_timezone_set('Asia/Shanghai'); 
$status = 0;$msg = '处理失败';
if(current_user_can('administrator')){
$post_id = $_POST['pid'];
$cpost = get_post($post_id);
_mbt_add_notice($cpost->post_author, sprintf(__('您好,您发表的文章《%s》审核不通过,原因:'.$_POST['why'].'。','mobantu'), $cpost->post_title), 'post_trash', $post_id);
wp_trash_post($post_id);
$status = 1;
}

$result = array(
'status' => $status,
'msg' => $msg
);

header('Content-type: application/json');
echo json_encode($result);
exit;
}
add_action( 'wp_ajax_modown_delete_notice', 'modown_delete_notice_callback');

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情