Wordpress admin-ajax results in Error 302 redirect

前端 未结 4 1777
孤独总比滥情好
孤独总比滥情好 2021-02-19 20:11

I have customized a plugin to make some ajax calls to admin-ajax.php and it works great. I copied the code over to another site and it no longer works for users who are not logg

4条回答
  •  一个人的身影
    2021-02-19 21:02

    I had something similar occur in a theme. The original coder was trying to prevent a non-admin user from being able to see the /wp-admin/ area.

    Here's an example:

    // Block Access to /wp-admin for non admins.
    function custom_blockusers_init() {
      if ( is_user_logged_in() && is_admin() && !current_user_can( 'administrator' ) ) {
        wp_redirect( home_url() );
        exit;
      }
    }
    add_action( 'init', 'custom_blockusers_init' ); // Hook into 'init'
    

    I would check your theme for source code similar to what I have.

    When you find the code, just add an extra conditional to make sure that a user isn't redirected if the DOING_AJAX constant is defined.

提交回复
热议问题