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.