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

Here's my problem. I need following solution.If a user is in the admin area of Wordpress and is not an administrato

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745438796a4627734.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信