Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/21/2012 05:26:22 PM (12 years ago)
Author:
djpaul
Message:

Resolve problems with load order when handling AJAX requests in BuddyPress. Fixes #2599 and #3985, props DJPaul and boonebgorges.

  • Reworks BP-Default's AJAX calls to use correct receiver in WordPress.
  • Hooks BP-Default's AJAX handlers to both 'wp_ajax_nopriv_' and 'wp_ajax'.
  • Updates associated parts in BP core to support this, and deprecates old handling.
  • Renames Activity spam/unspam AJAX actions (new to BP 1.6).
  • Adds full PHPDoc to ajax.php.
  • Code standards pass of ajax.php.
  • Remove unnecessary globals.
  • Backwards compatible with themes based on versions of BP-Default earlier 1.6.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/deprecated/1.6.php

    r5808 r6003  
    5454 */
    5555
    56 /*
     56/**
    5757 * @deprecated 1.6
    5858 * @deprecated No longer used; see bp_blogs_transition_activity_status()
     
    6666 */
    6767
    68 /*
     68/**
    6969 * @deprecated 1.6
    7070 * @deprecated No longer used; see BP_Admin::admin_menus()
     
    7474}
    7575
     76/**
     77 * @deprecated 1.6
     78 * @deprecated No longer used. We do ajax properly now.
     79 */
     80function bp_core_add_ajax_hook() {
     81    _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
     82}
    7683
    7784/**
     
    125132    return apply_filters( 'bp_core_email_from_address_filter', 'noreply@' . $domain[2] );
    126133}
     134
     135/**
     136 * Backward compatibility for AJAX callbacks that do not die() on their own
     137 *
     138 * In BuddyPress 1.6, BP was altered so that it uses admin-ajax.php (instead of wp-load.php) for
     139 * AJAX requests. admin-ajax.php dies with an output of '0' (to signify an error), so that if an
     140 * AJAX callback does not kill PHP execution, a '0' character will be erroneously appended to the
     141 * output. All bp-default AJAX callbacks (/bp-themes/bp-default/_inc/ajax.php) have been updated
     142 * for BP 1.6 so that they die() properly; any theme that dynamically includes this file will
     143 * inherit the fixes. However, any theme that contains a copy of BP's pre-1.5 ajax.php file will
     144 * continue to witness the 'trailing "0"' problem.
     145 *
     146 * This function provides a backward compatible workaround for these themes, by hooking to the
     147 * BP wp_ajax_ actions that were problematic prior to BP 1.6, and killing PHP execution with die().
     148 *
     149 * Note that this hack only runs if the function bp_dtheme_register_actions() is not found (this
     150 * function was introduced in BP 1.6 for related backward compatibility reasons).
     151 */
     152if ( !function_exists( 'bp_dtheme_register_actions' ) ) :
     153    function bp_die_legacy_ajax_callbacks() {
     154
     155        // This is a list of the BP wp_ajax_ hook suffixes whose associated functions did
     156        // not die properly before BP 1.6
     157        $actions = array(
     158            // Directory template loaders
     159            'members_filter',
     160            'groups_filter',
     161            'blogs_filter',
     162            'forums_filter',
     163            'messages_filter',
     164
     165            // Activity
     166            'activity_widget_filter',
     167            'activity_get_older_updates',
     168            'post_update',
     169            'new_activity_comment',
     170            'delete_activity',
     171            'delete_activity_comment',
     172            'spam_activity',
     173            'spam_activity_comment',
     174            'activity_mark_fav',
     175            'activity_mark_unfav',
     176
     177            // Groups
     178            'groups_invite_user',
     179            'joinleave_group',
     180
     181            // Members
     182            'addremove_friend',
     183            'accept_friendship',
     184            'reject_friendship',
     185
     186            // Messages
     187            'messages_close_notice',
     188            'messages_send_reply',
     189            'messages_markunread',
     190            'messages_markread',
     191            'messages_delete',
     192            'messages_autocomplete_results'
     193        );
     194
     195        // For each of the problematic hooks, exit at the very end of execution
     196        foreach( $actions as $action ) {
     197            add_action( 'wp_ajax_'        . $action, create_function( '', 'exit;' ), 9999 );
     198            add_action( 'wp_ajax_nopriv_' . $action, create_function( '', 'exit;' ), 9999 );
     199        }
     200    }
     201    add_action( 'after_setup_theme', 'bp_die_legacy_ajax_callbacks', 20 );
     202endif;
    127203?>
Note: See TracChangeset for help on using the changeset viewer.