我们的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 个评论