我们的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="https://www.mobantu.com/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');
原文链接:https://www.dqzy.cn/2025/04/10/325.html,转载请注明出处。
1、本站所有源码资源(包括源代码、软件、学习资料等)仅供研究学习以及参考等合法使用,请勿用于商业用途以及违法使用。如本站不慎侵犯您的版权请联系我们,我们将及时处理,并撤下相关内容!
2、访问本站的用户必须明白,本站对所提供下载的软件和程序代码不拥有任何权利,其版权归该软件和程序代码的合法拥有者所有,请用户在下载使用前必须详细阅读并遵守软件作者的“使用许可协议”,本站仅仅是一个学习交流的平台。
3、如下载的压缩包需要解压密码,若无特殊说明,那么文件的解压密码则为:www.dqzy.cn。
4、点启资源网是一个免费且专业分享网站源码、图片素材、特效代码、教程文章、站长工具的平台。我们努力给站长提供好的资源!
评论0