• Resolved khunmax

    (@khunmax)


    Hey Aleksander

    My site has both a blog and bbpress forum.

    I am running my own functionality plugin to keep overall plugin count as low as possible.

    I want to hide wp admin from non admin users (and direct non admin to homepage).

    I have tested about 5 or 6 different snippets but all of them conflict with your plugin. I even tried ones that claimed to not break ajax…but none worked.

    Do you have a “block admin and redirect to homepage” code snippet that doesn’t conflict with stock ticker that you can share with me?

    Thanks in advance for any assistance.

    Kind Regards

    Max

    https://wordpress.org/plugins/stock-ticker/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi Max,

    Can you please provide some examples so I test.

    This is first time I meet such request, and never tried similar combination.

    Cheers,
    Aleksandar

    Thread Starter khunmax

    (@khunmax)

    Hey Alex

    This is the one from the BBpress website that broke your plugin (written by one of the MODS!):

    /**
     * Disable admin bar on the frontend of your website
     * for subscribers.
     */
    function rkk_disable_admin_bar() {
    	if( ! current_user_can('edit_posts') )
    		add_filter('show_admin_bar', '__return_false');
    }
    add_action( 'after_setup_theme', 'rkk_disable_admin_bar' );
    
    /**
     * Redirect back to homepage and not allow access to
     * WP admin for Subscribers.
     */
    function rkk_redirect_admin(){
    	if ( ! current_user_can( 'edit_posts' ) ){
    		wp_redirect( site_url() );
    		exit;
    	}
    }
    add_action( 'admin_init', 'rkk_redirect_admin' );

    It is the redirect part that conflicts with ajax in your plugin?

    Thanks for you prompt reply.

    Kind Regards

    Max

    Hi Max,

    Actually, that will break each call to admin_ajax.php if initiated by non-admin user or logged out visitor.

    Use this code instead:

    /**
     * Redirect back to homepage and not allow access to
     * WP admin for Subscribers.
     */
    function rkk_redirect_admin(){
    	if ( ! defined('DOING_AJAX') && ! current_user_can( 'edit_posts' ) ){
    		wp_redirect( site_url() );
    		exit;
    	}
    }
    add_action( 'admin_init', 'rkk_redirect_admin' );

    Cheers

    Thread Starter khunmax

    (@khunmax)

    Hey Aleksander

    Sorry I didn’t get back to you sooner.

    Thanks very much for the snippet.

    Yes the code supplied by a MOD at BBpress is tantamount to malware. 🙂

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

The topic ‘block admin conflicting with your plugin (ajax?)’ is closed to new replies.