WordPress.org

Ready to get started?Download WordPress

Forums

WordPress MU Domain Mapping
Don't Redirect Admin Ajax (8 posts)

  1. Aaron
    Member
    Posted 3 years ago #

    When admin backend is set to redirect to original blog url, it causes AJAX cross-domain issues with plugins that use admin-ajax.php for front end AJAX.

    Can you prevent the redirect for that file in admin?

    buddypress directory search and http://wordpress.org/extend/plugins/chat/ are just some examples of plugins that use the WP ajax handler (as they should).

  2. John Turner
    Member
    Posted 3 years ago #

    +1 for this, how can I get the non domain mapped url until then? site_url returns the mapped domain as well as get_option('siteurl')

  3. Ken
    Member
    Posted 3 years ago #

    +1 - maybe what's needed instead is a ticket to move the ajax handling out of admin directory so the remap is not an issue.

  4. nickbudden
    Member
    Posted 3 years ago #

    + 1 from me too...I'm also working on this now. Here is something I tried (which does not work):

    add_action( 'init', 'noadmin_redirect' );
    function noadmin_redirect() {
    $admin_ajax = "wp-admin/admin-ajax.php";
    if( true == is_admin() && ($_SERVER['REQUEST_URI'] != $admin_ajax )) {
    if( !current_user_can('administrator') ) {
    wp_redirect( get_bloginfo('url') ); exit();
    }
    }
    }

  5. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 3 years ago #

  6. nickbudden
    Member
    Posted 3 years ago #

    Here is a function to do this without breaking admin-ajax

    function my_admin_init(){
    if( !defined('DOING_AJAX') && !current_user_can('administrator') ){
    wp_redirect( home_url() );
    exit();
    }
    }
    add_action('admin_init','my_admin_init');

    This function was provided by Milo on Stack Overflow.

  7. John Turner
    Member
    Posted 2 years ago #

    @wpmuguru dev version worked for me :)

  8. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 2 years ago #

    @John Turner - thanks for letting me know :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic