最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - If click on SavePublish change Post Status to Pending Review instead Publish

programmeradmin3浏览0评论

Here's my problem. I need following solution.

If a user is in the admin area of Wordpress and is not an administrator - and creates a page or product(via WooCommerce) - that if this user clicks on the blue "publish" button, the page/product should goes into the status "Pending Review", no matter what is selected in the status option or if it is already a published page/post/product whatever. If the blue published button gets clicked, by a non-admin, it always should go to pending review status.

I already fixed the problem with Javascript, but well the User could simply manipulate it - So I am searching for a PHP function.

Here is my current script made with Vanilla JS

add_action( 'init', 'savePendingReview' );
function savePendingReview() {
    if(is_admin()) {
        global $pagenow;
        if(!current_user_can('administrator') && 'post.php' === $pagenow) {
            echo '<script>
            window.addEventListener("load", function() {
            document.getElementById("post_status").selectedIndex = "1";
            </script>';
        }
    }
}

As you see my Javascript solution is pretty dirty. Any ideas how I can fix the problem with PHP? I need to hook into the save_post action to change the post_status.

发布评论

评论列表(0)

  1. 暂无评论