• MoniqueR

    (@moniquer)


    I hope some-one can help me out. I use this code to prevent users to go to backend:

    add_action( 'admin_init', 'redirect_non_admin_users' );
    function redirect_non_admin_users() {
    	if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
    		wp_redirect( "/dashboard/" );
    		exit;
    	}
    }

    I am doing this, because I handle everything in the front-end (I use front-end pro for this)

    Because of this ,the live search plugin only works for logged in users whom are admin. Is there any way to resolve this?
    So this plugin can be used for every-one?

    https://www.ads-software.com/plugins/daves-wordpress-live-search/

Viewing 1 replies (of 1 total)
  • Plugin Author Dana Ross

    (@csixty4)

    Dave’s WordPress live search uses’s WordPress’s AJAX hooks which, for mostly historical reasons, run in an admin context. But when it’s processing an AJAX request, WordPress sets a constant named DOING_AJAX to “true”. You can change your check to something like:

    if ( ! (defined( 'DOING_AJAX' ) && DOING_AJAX ) && ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {

Viewing 1 replies (of 1 total)
  • The topic ‘Only admin can use live search’ is closed to new replies.