#5450 closed defect (bug) (fixed)
Problem with groups in buddypress when a comment has more than five direct answers
Reported by: | 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)
Change History (8)
#1
@
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 theBP_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 thewp_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
@
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.
#3
follow-up:
↓ 4
@
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
@
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).
Error in Google Chrome.