• Resolved brook1979

    (@brook1979)


    Hi People,

    Without using a plugin or using css, HOW can i stop people (users of my website) from accessing /wp-admin/post-new.php once they are logged in to the site. Everything else is fine, i just need to restrict this access.

    I have managed to remove it from the admin menu button “add new” but im a little unsure as to how to restrict the access.

    Cheers in advance if anyone can help.

    Carl

Viewing 7 replies - 16 through 22 (of 22 total)
  • hi Carl,

    i have tested the code my side and it works! i will re-attached the code (made a few minor changes). Should work on your side!

    So, head back to your themes functions.php file and paste the following code:

    <?php
    function mod_caps()
    {
      $editor_role = get_role('editor');
      $editor_role->remove_cap('publish_posts');
    }
    
    function mod_menu()
    {
     global $submenu;
         $submenu['edit.php'][10][1] = 'publish_posts';
    }
    
    function hide_buttons()
    {
      global $current_screen;
    
      if($current_screen->id == 'edit-post' && !current_user_can('publish_posts'))
      {
        echo '<style>.add-new-h2{display: none;}</style>';
      }
    }
    
    function ap_redirect() {
    $result = stripos($_SERVER['REQUEST_URI'], 'post-new.php');
      if ($result!==false && !current_user_can('publish_posts'))  {
        wp_redirect(get_option('siteurl') . '/wp-admin/index.php?permissions_error=true');
    	}
    }
    
    function permissions_admin_notice()
    {
      echo "<div id='permissions-warning' class='error fade'><p><strong>".__('You do not have permission to access that page.')."</strong></p></div>";
    }
    
    function showp_notice()
    {
      if($_GET['permissions_error'])
      {
        add_action('admin_notices', 'permissions_admin_notice');
      }
    }
    
    add_action('admin_init','mod_caps');
    add_action('admin_init','showp_notice');
    add_action('admin_menu','mod_menu');
    add_action('admin_menu','ap_redirect');
    add_action('admin_head','hide_buttons');
    
    ?>

    Do note that this includes the editor only. However, the author, and subscriber can be added manually so only admin has access.

    I have checked and made sure that all brackets are closed ??

    For testing purposes, please do make sure that you disable the role scoper plugin. You can always switch this back on afterwards.

    Do let me know the outcome as i will most likely turn this into a plugin.

    Good Luck!

    Seems i missed a line in the original admin_redirect function (now ap_redirect)

    Thread Starter brook1979

    (@brook1979)

    Sweeeeeeeeeeeeeeeet! It works like a charm!

    Thanks soooo muck RSP for all your help, cant tell ya how much i appreciate that.

    ONE last thing about this, which wordpress php file is it that i have to configure to put a “NICER” permissions page up…??? If you are making this a plugin it might be worth adding this in as a configuration???

    THANKS AGAIN, thats awesome news for me…

    Carl

    Fantastic! You are most welcome Carl,

    Okay, as seen in the code, the permission is found here:

    /wp-admin/index.php?permissions_error=true');

    However, i would assume that the permission message text can be altered within the code (section where it appears).

    Should i turn this into a plugin, i will most certainly add this as a config ??

    Thread Starter brook1979

    (@brook1979)

    Hi RSP,

    Thanks again! Honestly saved me alot of time that as. If ya lived round the corner we’d be going for a beer.

    I would definitely turn it in to a plugin! When you take a step back and look at the plugins available theres not that many available when it comes to hard hacks like this, i mean there is adminimize, white lable cms, menu editor etc etc! But it always seems you need about 3 or 4 plugins to make something work. If i had the time and money available i would create a plugin that would absolutely tear apart the wordpress ADMIN! and just because there is alot of developers building sites for clients using wordpress, and then theres people who like using wordpress BUT like i said not comfortable getting 3-4 plugins to work together.

    Thanks AGAIN ?? RSP.

    Carl

    hi Carl,

    you are most welcome! Glad i could help hehe,

    Do have a beer for me ??

    Cheers,

    Thread Starter brook1979

    (@brook1979)

    I will do RSP!

    What is it you actually do RSP?? Catch me on msn if ya like brook1979atmsndotcom

    Carl

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘"add new" post’ is closed to new replies.