Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#6615 closed defect (bug) (fixed)

bp_get_the_post_class() mistakenly removes classes

Reported by: dcavins Owned by: dcavins
Milestone: 2.4 Priority: normal
Severity: normal Version: 2.1
Component: Core Keywords: has-patch commit
Cc: dcavins

Description

bp_get_the_post_class() tries to unset the classes page and type-page on BuddyPress pages. However, it uses array_search() to find the key to unset and doesn't check for strict falsey-ness (array_search returns the found key--including 0-- or false if nothing is found).

In our function, if the targeted class isn't found, the zeroth element of the array is accidentally unset. I've added a strict check on the result of array_search() before unsetting anything.

This also could be done using array_diff(), if you have some idea that that would be more efficient/less klutzy, please let me know. :)

Attachments (1)

6615.01.patch (924 bytes) - added by dcavins 5 years ago.
Add strict check on result of array_search() in bp_get_the_post_class().

Download all attachments as: .zip

Change History (5)

@dcavins
5 years ago

Add strict check on result of array_search() in bp_get_the_post_class().

#1 @DJPaul
5 years ago

Nice spot

#2 @r-a-y
5 years ago

  • Keywords commit added
  • Version changed from 2.3.3 to 2.1

Fix looks good. You can blame me for this one!

I'm guessing that a plugin or theme might have removed the 'page' or 'type-page' CSS classes, which is why this is necessary.

#3 @dcavins
5 years ago

  • Owner set to dcavins
  • Resolution set to fixed
  • Status changed from new to closed

In 10109:

Limit class deletion in bp_get_the_post_class().

Prevent bp_get_the_post_class() from deleting
the zeroth element in the wp_classes array when
array_search() returns false.

Fixes #6615.

#4 @dcavins
5 years ago

Thanks @DJPaul and @r-a-y for your feedback!

Note: See TracTickets for help on using tickets.