Since I am facing a issue with your wordpress that if my authors publish a page in my website then it goes to Pending Review Status. This is working fine. But the preview url of each post that is in pending review status is visible to everyone except other users also. Let me give you an example. If I am the author of your website and created a post and send to pending review after that i copied the preview url and send it to globally since everyone can see that post without getting approval of the administrator. So, I have a question, can I redirect all preview urls to any custom url or on my homepage.

Example:- https://example.com/?p=16311&preview=true/ or https://example.com/?p=16311 TO https://example.com/under-approval/

This is very serious issue which each of your users will face in future. For reference I also added a link of that page such that you can also check that the pending review post is visible to everyone…

For reference you can check this url https://thefaceofindia.in/?p=16309&preview=true

This url is opening worldwide without getting approval of administrator

1 Answer 1

    function mmk_pending_review_redirect(){
        $user = wp_get_current_user();
        if(get_post_status ( get_the_id() ) != 'publish')
            if (is_user_logged_in() && !in_array( 'administrator', (array) $user->roles ) && !is_author() ) {
                wp_redirect( "https://example.com/under-approval");
              wp_redirect( "https://example.com/under-approval") );
add_action('template_redirect', 'mmk_pending_review_redirect');

explanation: redirect non-admin users to custom URL if they are not author of the current post where status is not published. (change page id to your custom page)

  • I want to show pending review post only to administrator not to author and anybody else, i want to redirect the specific page if to any custom url if anybody tries to visit that pending review page. example.com/?p=16374&preview=true to any custom page Nov 24, 2021 at 4:48
  • i have updated the code so if a user is not logged in and tries to access a post that is not published it will be redirected. if a user is logged in but not with admin role it will also get redirected. you can modify/remove this part get_permalink( $custom_url_id ) to give your own custom url.
    – MMK
    Nov 24, 2021 at 18:21
  • I have updated the code , check
    – MMK
    Nov 25, 2021 at 15:29
  • but this code is redirecting all my 404 pages, I only want to redirect pending review pages. Nov 25, 2021 at 15:42
  • remove this part, else{ wp_redirect( "example.com/under-approval") ); exit; } non logged in users won't be able to see the page anyways, and get 404 if they try to access it.
    – MMK
    Nov 25, 2021 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.