• Resolved Greg Marshall

    (@timeassistant)


    Hello, great plugin. However rather than showing a user the “you dont have permissions to view this page” type message, is it possible to just redirect them to the default (theme) 404 page?

    This would suit me better as I would rather a user didnt know the restricted items existed

    thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Janis Elsts

    (@whiteshadow)

    There’s no easy way to do that.

    However, if you’re familiar with WordPress development, you could use the admin_page_access_denied hook to display your own error message or redirect the user somewhere. Admin Menu Editor triggers this hook just before it displays its “you do not have permission” error message. Technically, it would be possible to write a hook callback that shows something else and then stops script execution before AME can show the default message.

    Thread Starter Greg Marshall

    (@timeassistant)

    Thanks for the quick reply 🙂

    I’ll give it a go and see if I can figure that out and I’ll post back with my findings

    Thread Starter Greg Marshall

    (@timeassistant)

    Ok so I think it’s working right, based off this codex reference – https://developer.wordpress.org/reference/hooks/admin_page_access_denied/

    I came up with this…

    
            function awol_admin_page_access_denied() { 
             // trigger  404, custom text or redirect etc here
            awol_trigger_404(); // just a custom function I use to produce a 404 page
    	die(); // force script to exit here and stops default plugin response
            }; 
                     
            // add the action 
            add_action( 'admin_page_access_denied', 'awol_admin_page_access_denied' ); 
    
    

    Thanks for helping me in the right direction, hopefully this code will help someone else 🙂

    Plugin Author Janis Elsts

    (@whiteshadow)

    That looks like fine to me. I’ll mark this as resolved.

    Thread Starter Greg Marshall

    (@timeassistant)

    Yep I’m happy with this, thank you very much ! 🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘redirect restricted items to 404?’ is closed to new replies.