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

更新时间:2023-04-08 16:04 分类: 建站教程 人气: (381) 0个评论

直接上代码,比较简单
[Wordpress教程]WordPress 如何实现删除文章并通知投稿作者不通过理由

add_action( 'post_submitbox_misc_actions', 'ttzip_delete_notice_metabox' );
function ttzip_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(".ttzip-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: "ttzip_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 ttzip_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'].'。','ttzip'), $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', 'ttzip_delete_notice_callback');
本文最后更新于2023年4月8日,已超过半年没有更新,如果文章内容失效,请反馈给我们,谢谢!
除特别注明外,本站所有文章均为天天下载原创,转载请注明出处来自https://www.ttzip.com/wordpress-deleting-for-rejection.html
4人喜欢