Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress 2.2 Activity Updates (Ajax) and Askimet Issue


  • SlothLoveChunk
    Participant

    @slothlovechunk

    When testing BuddyPress 2.2 I’ve run into a problem where posting activity updates or replies won’t display properly (saving via Ajax) with Askimet enabled. They are saving to the DB, but upon hitting “Post Update” or “Post” the spinner just spins forever and in console I see:

    POST http://www.angrybirdsnest.com/wp-admin/admin-ajax.php net::ERR_CONNECTION_RESET

    To debug I disabled all plugins except BP and switched to Twenty Fifteen. Once I did that activity updates started to display properly upon saving. I had a hunch Askimet or bbPress might be the culprit, so I turned Askimet back on first (bbPress was still disabled). My hunch was right as now when I post an activity update it doesn’t work, the spinner spins and the aforementioned error shows in console.

    Long story short, Askimet is one of the most popular plugins out there, so it would be great if someone else could help me double check this and if it’s indeed an issue find a fix.

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    That’s no good. Thanks for the report. We’ll do some testing and report back with the results.


    SlothLoveChunk
    Participant

    @slothlovechunk

    Appreciate that.

    I should add that if I re-enable Akismet while commenting out line 52 in /bp-activity/bp-activity-akismet.php, activity updates post fine.

    Line 52
    add_action( 'bp_activity_before_save',     array( $this, 'check_activity' ), 4, 1 );

    r-a-y
    Keymaster

    @r-a-y

    Sounds like an issue with your environment when pinging an external site.

    Try pinging any site with wp_remote_post( 'URL_HERE' ); and see if you get similar results. Or, see if you can view the RSS feed items that usually show up in the admin dashboard. Do they show up?


    SlothLoveChunk
    Participant

    @slothlovechunk

    @r-a-y

    FWIW, I am testing locally, but ‘wp_remote_post( ‘https://buddypress.org’ );’ seems to return a response just fine. RSS items displayed in the “WordPress News” dashboard widget load as well.

    I don’t want to this to be a red herring, so I am happy to test out any other ideas.


    r-a-y
    Keymaster

    @r-a-y

    Hmm, well there goes my theory 🙂

    We do have one report that Akismet is working on BP 2.2. We’ll try to look into this and whether we can pass on some additional debugging info to you.

    Update – I can also verify that Akismet is working on my local test environment.


    SlothLoveChunk
    Participant

    @slothlovechunk

    I appreciate the update @r-a-y. Akismet is working on my end too; however, that’s not really the problem. The issue seems to be that when Akismet is enabled the spam check prevents an activity update from appearing in the activities list below (prepending to <ul id=”activity-stream” class=”activity-list item-list”>). “Load Newest” does appear, the activity update is saved, and the activity admin shows “Cleared by Akismet”.

    I hope that makes things a bit more clear.


    r-a-y
    Keymaster

    @r-a-y

    I should have noted that Akismet is indeed working with the BP activity component on my end when posting in the activity stream using BP v2.2. No errors or infinite spinners.

    Sorry for the vague comment.


    SlothLoveChunk
    Participant

    @slothlovechunk

    This is definitely strange @r-a-y. If I revert back all works as it should. I’ve debugged a bunch of the functions and they seem to be returning the proper values. It seems that ‘post_update’ action in buddypress.js is not receiving a response though. e.g.

    jq.post( ajaxurl, {
    	action: 'post_update',
    	'cookie': bp_get_cookies(),
    	'_wpnonce_post_update': jq('#_wpnonce_post_update').val(),
    	'content': content,
    	'object': object,
    	'item_id': item_id,
    	'since': last_date_recorded,
    	'_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
    },
    function(response) {
        (removed for sake of shorting the reply here)
    }

    Any guesses as to why not? When debugging Akismet I was able to get a 200 response back no problem.

    [response] => Array
    	(
    		[headers] => Array
    			(
    				[server] => nginx
    				[date] => Fri, 06 Feb 2015 01:00:40 GMT
    				[content-type] => text/plain; charset=utf-8
    				[content-length] => 5
    				[connection] => close
    				[x-akismet-server] => 10.4.64.80
    				[x-akismet-guid] => 42e6a5b9b7e87435df0bd1812654520f
    			)
    
    		[body] => false
    		[response] => Array
    			(
    				[code][/code] => 200
    				[message] => OK
    			)
    
    		[cookies] => Array
    			(
    			)
    
    		[filename] => 
    	)

    SlothLoveChunk
    Participant

    @slothlovechunk

    @r-a-y After a bit more debugging I’ve traced the route of the problem to the updated, “bp_filter_metaid_column_name” function in /bp-core/bp-core-filters.php. The updated function includes a new regex:

    function bp_filter_metaid_column_name( $q ) {
    	/*
    	 * Replace quoted content with __QUOTE__ to avoid false positives.
    	 * This regular expression will match nested quotes.
    	 */
    	$quoted_regex = "/'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'/s";
    	preg_match_all( $quoted_regex, $q, $quoted_matches );
    	$q = preg_replace( $quoted_regex, '__QUOTE__', $q );
    
    	$q = str_replace( 'meta_id', 'id', $q );
    
    	// Put quoted content back into the string.
    	if ( ! empty( $quoted_matches[0] ) ) {
    		for ( $i = 0; $i < count( $quoted_matches[0] ); $i++ ) {
    			$quote_pos = strpos( $q, '__QUOTE__' );
    			$q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 );
    		}
    	}
    
    	return $q;
    }

    The old function was simply:

    function bp_filter_metaid_column_name( $q ) {
    	return str_replace( 'meta_id', 'id', $q );
    }

    If I swap out the updated version of this function for the old one everything works fine. Also, if I comment out the regex portion of ‘bp_filter_metaid_column_name’ it works fine as well.

    I added some logging to this function and the output seems a bit strange to me. It’s a bit hard to follow, but here it goes:

    [06-Feb-2015 18:40:43 UTC] $q First: SELECT activity_id, meta_key, meta_value FROM wp_bp_activity_meta WHERE activity_id IN (404095) ORDER BY meta_id ASC
    
    [06-Feb-2015 18:40:43 UTC] $q Second: SELECT activity_id, meta_key, meta_value FROM wp_bp_activity_meta WHERE activity_id IN (404095) ORDER BY id ASC
    
    [06-Feb-2015 18:40:43 UTC] $q First: SELECT meta_id FROM wp_bp_activity_meta WHERE meta_key = __QUOTE__ AND activity_id = 404095
    
    [06-Feb-2015 18:40:43 UTC] $q Second: SELECT id FROM wp_bp_activity_meta WHERE meta_key = __QUOTE__ AND activity_id = 404095
    
    [06-Feb-2015 18:40:43 UTC] $q Third: SELECT id FROM wp_bp_activity_meta WHERE meta_key = '_bp_akismet_result' AND activity_id = 404095
    
    [06-Feb-2015 18:40:43 UTC] $q First: INSERT INTO <code>wp_bp_activity_meta</code> (<code>activity_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES (__QUOTE__,__QUOTE__,__QUOTE__)
    
    [06-Feb-2015 18:40:43 UTC] $q Second: INSERT INTO <code>wp_bp_activity_meta</code> (<code>activity_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES (__QUOTE__,__QUOTE__,__QUOTE__)
    
    [06-Feb-2015 18:40:43 UTC] $q Third: INSERT INTO <code>wp_bp_activity_meta</code> (<code>activity_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES ('404095',__QUOTE__,__QUOTE__)
    
    [06-Feb-2015 18:40:43 UTC] $q Third: INSERT INTO <code>wp_bp_activity_meta</code> (<code>activity_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES ('404095','_bp_akismet_result',__QUOTE__)
    
    [06-Feb-2015 18:40:43 UTC] $q Third: INSERT INTO <code>wp_bp_activity_meta</code> (<code>activity_id</code>,<code>meta_key</code>,<code>meta_value</code>) VALUES ('404095','_bp_akismet_result','false')

    The SQL statement appended to the ‘$q Third:’ output is logged from inside the ‘$quoted_matches[0]’ for loop (line 744). I get the idea here is for backwards compatibility between ‘id’ and ‘activity_id’, but shouldn’t it still return the “SELECT’ portion of the SQL query?

    Anyhow, I could be completely wrong here, but @r-a-y / @johnjamesjacoby, I’d love to know your thoughts. Sorry for the super long reply


    r-a-y
    Keymaster

    @r-a-y

    @slothlovechunk – Thanks for your in-depth debugging.

    This does seem like a bug. Can you create a new ticket with exactly what you wrote here:
    https://buddypress.trac.wordpress.org/newticket (use the same credentials as you use here on buddypress.org)

    And reference this ticket where the meta SQL changes were made:
    https://buddypress.trac.wordpress.org/ticket/5919

    Thanks so much!


    SlothLoveChunk
    Participant

    @slothlovechunk

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘BuddyPress 2.2 Activity Updates (Ajax) and Askimet Issue’ is closed to new replies.
Skip to toolbar