• Resolved Julianwave

    (@julianwave)


    Hi

    I have a site where I want to use your WP-PostRatings plugin. I also want to hide admin screens from subscribers.

    WP-PostRatings works fine until I add the following to my functions.php

    * Redirect back to homepage and not allow access to
    * WP admin for Subscribers.
    */

    function themeblvd_redirect_admin(){
    if ( ! current_user_can( ‘edit_posts’ ) ){
    wp_redirect( site_url() );
    exit;
    }
    }
    add_action( ‘admin_init’, ‘themeblvd_redirect_admin’ );

    I’ve narrowed it down to this 1 issue, as soon as I add it it makes your plugin go horribly wrong.

    I don’t think I know enough php to sort it out, so any advice would be much appreciated.

    I’d really like to use your plugin, but I do need to hide admin screens from subscribers as well.

    I’ve noticed similar things happen with other voting type plugins so I am suspecting I need to find a different way of hiding the admin..?

    I see you respond very quickly to queries, so thanks for a great plugin and thanks for looking after it so well.

    Julian Coates.

    https://ww.wp.xz.cn/plugins/wp-postratings/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lester Chan

    (@gamerz)

    I am not sure what are you trying to archive. If you do not have the access to see the plugin, it will not show up in the menu at all.

    For PosRatings we check to see if you can access the plugin if not we it will die();

    Thread Starter Julianwave

    (@julianwave)

    I think I fixed it myself 🙂

    What I needed was the following code

    /**
     * Restrict access to the administration screens.
     *
     * Only administrators will be allowed to access the admin screens,
     * all other users will be automatically redirected to the front of
     * the site instead.
     *
     * We do allow access for Ajax requests though, since these may be
     * initiated from the front end of the site by non-admin users.
     */
    function restrict_admin_with_redirect() {
    
    	if ( ! current_user_can( 'manage_options' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
    		wp_redirect( site_url() );
    		exit;
    	}
    }
    
    add_action( 'admin_init', 'restrict_admin_with_redirect', 1 );

    which stops subscribers viewing the admin area while allowing access for Ajax requests.

    See http://codex.ww.wp.xz.cn/Plugin_API/Action_Reference/admin_init “Example: Access Control with redirect”

    Cheers

    Thanks a lot Julian, I was searching this for a long time!

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

The topic ‘WP-PostRatings problem with admin_init’ is closed to new replies.