Support » Plugin: Plugins Garbage Collector » Empty Ajax response MultiSite Fix

  • I like the plugin idea, but unfortunately, it wasn’t working for me. After some debugging, I found the following.

    Ajax is going to return an empty response in WP3.x.x MultiSite (with domain mapping) because, by design (in FF), ajax does not allow calls to a different domain (if not in jsonp as it’s the case).

    Th issue is that WP inits all the scripts with the siteurl domain (e.g., but when the admin is invoked within a mapped site ( the ajax call needs to happen within that mapped domain too.

    This is the fix that works for me:

    plugins-garbage-collector\pgc-lib.php li ~29, add the following 2 lines:

    $pgcPluginDirName = substr(dirname(__FILE__), strlen(WP_PLUGIN_DIR) + 1, strlen(__FILE__) - strlen(WP_PLUGIN_DIR)-1);
    ////[alx359] new definition for Multisite support
    $pgc_siteURL_wpmu = ( is_ssl() && !is_admin() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'];
    define('PGC_PLUGIN_DIR_WPMU', $pgc_siteURL_wpmu.'/wp-content/plugins/'.$pgcPluginDirName);

    plugins-garbage-collector.php li ~122 change the following line:

    function pgc_scriptsAction() {
      wp_enqueue_script('pgc_js_script', PGC_PLUGIN_URL.'/pgc-ajax.js', array('jquery','jquery-form'));
      //[alx359] use current (mapped) domain, to avoid forbidden cross-domain ajax calls
      //wp_localize_script('pgc_js_script', 'pgcSettings', array('plugin_url' => PGC_PLUGIN_URL, 'ajax_nonce' => wp_create_nonce('plugins-garbage-collector')));
      wp_localize_script('pgc_js_script', 'pgcSettings', array('plugin_url' => PGC_PLUGIN_DIR_WPMU, 'ajax_nonce' => wp_create_nonce('plugins-garbage-collector')));

    This should fix the issue.

    Additionally, unessential but useful: more comprehensive ajax error messages if something goes wrong, instead of [Object object]
    pgc-ajax.js li ~33

    /*[alx359] better error handling | error: function(msg) {*/
       error: function(jqXHR, textStatus, errorThrown) {
       /*[alx359] better error handling | alert(msg);*/
         alert(textStatus+' - '+errorThrown);


    This below are just little layout embellishments (tested in FF5 only).

    a) Better alignment of ajax wait wheel

    pgc-admin.css li ~72. Change height

    #progressbar {
      height:22px; /*[alx359] changed | height:16px*/

    pgc-admin.css li ~104. Add some padding

    .ajax_processing {
      padding: 0 0 0 10px; /*[alx359] added*/

    b) Better “Scan” button alignment

    pgc-options.php li ~111 change margin

    <div style="float: left; display: inline; margin: -5px 0 10px 0;<?/*[alx359] margin-bottom: 10px;*/?>">
    <input type="button" name="scan_db" value="<?php _e('Scan', 'pgc'); ?>" title="<?php _e('Click this button to gather information how plugins use your WordPress database', 'pgc'); ?>" onclick="pgc_Actions('scan');"/>


Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Empty Ajax response MultiSite Fix’ is closed to new replies.