Skip to:
Content

BuddyPress.org

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#5450 closed defect (bug) (fixed)

Problem with groups in buddypress when a comment has more than five direct answers

Reported by: dmuneras's profile dmuneras Owned by:
Milestone: Priority: high
Severity: normal Version: 1.9.1
Component: Templates Keywords: needs-patch reporter-feedback dev-feedback 2nd-opinion
Cc:

Description

Hi,

I think there is a Javascript error in the following JS source code (line 1707):

http://phpxref.ftwr.co.uk/buddypress/nav.html?bp-templates/bp-legacy/js/buddypress.js.source.html

If a comment has more than five direct answers, we will get the following error:

Uncaught TypeError: Cannot call method 'replace' of undefined, it happens with the following instruction:

BP_DTheme.show_x_comments.replace( '%d', comment_count )

It seems like BP_DTheme.show_x_comments is not defined.

I wrote an script to check if we will get the error (run it using google chrome element inspector).



jq('div.activity-comments').each(function(i){

comment_lis = jq(this).children('ul').children('li');
comment_lis.each(function(i){

if ( i < comment_lis.length - 5 ) {

if ( !i ){

if(window.console)

console.log("WARNING: Comment with ID: " + comment_lis.attr('id')

+ " has more than 5 comments and this is going to exploit! ");

if(window.console)

console.log("Identificador comentario comentado más de 5 veces: " +

jq('div.activity-comments').parents('ul#activity-stream > li').attr('id'));

}

}

});

});



Could you check if I am right or it is something wrong with my Wordpress or Buddypress installation? because when I get the error. I can't comment the comments.

Best regards,
Daniel.

Attachments (2)

Captura de pantalla 2014-03-07 a la(s) 18.49.01.png (52.6 KB) - added by dmuneras 11 years ago.
Error in Google Chrome.
Captura de pantalla 2014-03-07 a la(s) 18.51.08.png (53.5 KB) - added by dmuneras 11 years ago.

Download all attachments as: .zip

Change History (8)

@dmuneras
11 years ago

Error in Google Chrome.

#1 @boonebgorges
11 years ago

  • Keywords reporter-feedback added; 2nd-opinion ui-feedback removed

I can't duplicate this.

A couple of things for you to look at:

  • Here's where bp-legacy (BuddyPress's built-in template pack) registers its localized JS strings (like show_x_comments): https://buddypress.trac.wordpress.org/browser/tags/1.9.2/bp-templates/bp-legacy/buddypress-functions.php#L229
  • You say that BP_DTheme.show_x_comments is not defined. Is the BP_DTheme object defined at all? If *yes*, it suggests that you're using a theme that is overriding BP's default string localization and providing an out-of-date set of strings. If *no*, perhaps you could trace back to see why the wp_localize_script() call linked above is not getting fired.
  • It's possible that the BP_DTheme string is being overwritten by a plugin. Look in your page source to see if the object is defined more than once. Or grep through wp-content/plugins/ to see if other plugins are messing with it somehow. Your plugins.php screenshot shows that BuddyPress Activity Plus is runnning on your installation - you might start your search there.
  • You say that this causes problems in *groups*. Is it *specific* to groups, or does it happen in the sitewide activity stream too? How about on single activity permalink pages (when you click on the timestamp of the item)?

(Side note: please upgrade to BP 1.9.2! There are security vulnerabilities in 1.9.1.)

#2 @dmuneras
11 years ago

  • Component changed from Groups to Theme
  • Keywords dev-feedback 2nd-opinion added
  • Resolution set to fixed
  • Status changed from new to closed

Thanks a lot your answer.

I already found the problem. Some themes like Bounce and Buddy override the variable:

Bounce: '<<bounce dir>>/lib/buddypress/functions-buddypress.php'

// Add words that we need to use in JS to the end of the page so they can be translated and still used
if (!function_exists( 'bp_dtheme_enqueue_scripts')) {
	function bp_dtheme_enqueue_scripts() {
		$params = array(
			'my_favs'           => __('My Favorites', 'buddypress'),
			'accepted'          => __('Accepted', 'buddypress'),
			'rejected'          => __('Rejected', 'buddypress'),
			'show_all_comments' => __('Show all comments for this thread', 'buddypress'),
			'show_all'          => __('Show all', 'buddypress'),
			'comments'          => __('comments', 'buddypress'),
			'close'             => __('Close', 'buddypress'),
			'view'              => __('View', 'buddypress'),
			'mark_as_fav'	    => __('Favorite', 'buddypress'),
			'remove_fav'	    => __('Remove Favorite', 'buddypress')
		);	
		wp_localize_script('dtheme-ajax-js', 'BP_DTheme', $params);
	}
	add_action('wp_enqueue_scripts', 'bp_dtheme_enqueue_scripts');
}

At least it works for us.

Could you explain to me why buddypress defines BP_DTheme in two different functions: bp_dtheme_enqueue_scripts and enqueue_scripts?

Best regards,
Daniel.

Last edited 11 years ago by dmuneras (previous) (diff)

#3 follow-up: @boonebgorges
11 years ago

I already found the problem. Some themes like Bounce and Buddy override the variable

Aha. Yes, that'll do it. It's especially problematic if a theme decides to use BP's core JS, but then uses its own PHP functions for AJAX, localization, stuff like that. They get out of sync.

Could you explain to me why buddypress defines BP_DTheme in two different functions: bp_dtheme_enqueue_scripts and enqueue_scripts?

Sure. bp_dtheme_enqueue_scripts() is used if you're running the bp-default theme, or a child theme of bp-default. BP_Legacy::enqueue_scripts() is used if you're using theme compatibility (ie, you're using a theme that doesn't natively support BuddyPress, like, say, Twenty Fourteen).

#4 in reply to: ↑ 3 @dmuneras
11 years ago

Ok, Boone. Thanks for your help and explanation.

Replying to boonebgorges:

I already found the problem. Some themes like Bounce and Buddy override the variable

Aha. Yes, that'll do it. It's especially problematic if a theme decides to use BP's core JS, but then uses its own PHP functions for AJAX, localization, stuff like that. They get out of sync.

Could you explain to me why buddypress defines BP_DTheme in two different functions: bp_dtheme_enqueue_scripts and enqueue_scripts?

Sure. bp_dtheme_enqueue_scripts() is used if you're running the bp-default theme, or a child theme of bp-default. BP_Legacy::enqueue_scripts() is used if you're using theme compatibility (ie, you're using a theme that doesn't natively support BuddyPress, like, say, Twenty Fourteen).

#5 @johnjamesjacoby
11 years ago

  • Milestone Awaiting Review deleted

#6 @DJPaul
8 years ago

  • Component changed from Appearance - Template Parts to Templates
Note: See TracTickets for help on using tickets.