Ticket #4954: 4954.ray.01b.ajax.patch
File 4954.ray.01b.ajax.patch, 3.1 KB (added by , 11 years ago) |
---|
-
bp-core/bp-core-rewrite.php
class BP_Rewrite { 29 29 * 30 30 * @var array 31 31 */ 32 public $registered_query_vars = array( );32 public $registered_query_vars = array( 'bp_component', 'bp_path' ); 33 33 34 34 /** 35 35 * Constructor. … … class BP_Rewrite { 38 38 add_filter( 'query_vars', array( $this, 'query_vars' ) ); 39 39 add_action( 'bp_generate_rewrite_rules', array( $this, 'rewrite_rules' ), 999 ); 40 40 add_action( 'bp_parse_query', array( $this, 'parse_query' ), 2 ); 41 add_action( ' bp_init', array( $this, 'setup_ajax_globals' ), 2);41 add_action( 'wp_loaded', array( $this, 'setup_ajax_globals' ) ); 42 42 add_action( 'posts_request', array( $this, 'posts_request' ), 10, 2 ); 43 43 } 44 44 … … class BP_Rewrite { 138 138 * function like bp_is_current_action() during AJAX, it will not work. This 139 139 * has the potential to break some plugins utilizing this behavior. 140 140 * 141 * Fortunately, our old URI globals function handles AJAX requests just fine, 142 * so let's bring it off the bench durng AJAX. 141 * To workaround this, we manually load up the WP query on AJAX here. 143 142 */ 144 143 public function setup_ajax_globals() { 145 144 // stop if we're not on an ajax request … … class BP_Rewrite { 147 146 return; 148 147 } 149 148 150 // sigh... hello old friend, we're stuck with you at least for now. 151 bp_core_set_uri_globals(); 149 // BP sends a 'cookie' parameter on AJAX requests 150 // If this AJAX request doesn't have this parameter, stop now! 151 if ( empty( $_POST['cookie'] ) ) { 152 return; 153 } 154 155 // Fool WP into using the referer for AJAX requests 156 // This is to pass WP::parse_request()'s stringent requirements 157 // 158 // @todo Needs further testing in different environments. 159 // Especially PHP_SELF on IIS... 160 $_SERVER['PHP_SELF'] = 'index.php'; 161 $_SERVER['REQUEST_URI'] = bp_core_referrer(); 162 163 // manually load our custom 'bp_parse_query' hook 164 add_action( 'parse_query', array( $this, 'ajax_parse_query' ), 2 ); 165 166 // load the WP query 167 wp(); 152 168 } 153 169 154 170 /** 155 171 * Add our query vars to WordPress. 156 172 */ 157 173 public function query_vars( $vars ) { 158 $this->registered_query_vars[] = 'bp_component';159 $this->registered_query_vars[] = 'bp_path';160 161 174 return array_merge( $this->registered_query_vars, $vars ); 162 175 } 163 176 … … class BP_Rewrite { 226 239 public static function get_bp_frontpage_component() { 227 240 return self::get_bp_frontpage_component_from_page_id( get_option( 'page_on_front' ) ); 228 241 } 242 243 /** 244 * AJAX-capable version of {@link bp_parse_query()}. 245 * 246 * bp_parse_query() does not run in the admin area. When AJAX is called, WP 247 * assumes we are in the admin area. As a consequence, our custom 248 * 'parse_query' actions won't run. 249 * 250 * This is a stub method to allow the 'bp_parse_query' hook to run. 251 * 252 * @param object $query The current WP_Query instance. 253 */ 254 public function ajax_parse_query( $posts_query ) { 255 do_action_ref_array( 'bp_parse_query', array( &$posts_query ) ); 256 } 229 257 }