Title: WP-PostRatings problem with admin_init
Last modified: August 21, 2016

---

# WP-PostRatings problem with admin_init

 *  Resolved [Julianwave](https://wordpress.org/support/users/julianwave/)
 * (@julianwave)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/wp-postratings-problem-with-admin_init/)
 * 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://wordpress.org/plugins/wp-postratings/](https://wordpress.org/plugins/wp-postratings/)

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

 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/wp-postratings-problem-with-admin_init/#post-5009149)
 * 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](https://wordpress.org/support/users/julianwave/)
 * (@julianwave)
 * [11 years, 12 months ago](https://wordpress.org/support/topic/wp-postratings-problem-with-admin_init/#post-5009226)
 * 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.wordpress.org/Plugin_API/Action_Reference/admin_init](http://codex.wordpress.org/Plugin_API/Action_Reference/admin_init)“
   Example: Access Control with redirect”
 * Cheers
 *  [MiguelMich](https://wordpress.org/support/users/miguelmich/)
 * (@miguelmich)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/wp-postratings-problem-with-admin_init/#post-5009405)
 * 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.

 * ![](https://ps.w.org/wp-postratings/assets/icon.svg?rev=978014)
 * [WP-PostRatings](https://wordpress.org/plugins/wp-postratings/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-postratings/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-postratings/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-postratings/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-postratings/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-postratings/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [MiguelMich](https://wordpress.org/support/users/miguelmich/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/wp-postratings-problem-with-admin_init/#post-5009405)
 * Status: resolved