Skip to:
Content

BuddyPress.org

Opened 12 months ago

Closed 3 months ago

#9304 closed defect (bug) (fixed)

'no-js' body class not being added correctly since BuddyPress 12.1.0

Reported by: r-a-y Owned by: espellcaste
Priority: normal Milestone: 14.5.0
Component: Templates Version: 12.1.1
Severity: normal Keywords: has-patch
Cc:

Description

r13672 added is_buddypress() checks before adding the 'no-js' body class.

However, the is_buddypress() check is done too early on the 'after_setup_theme' hook, so this means the 'no-js' body class is never added since BuddyPress 12+ and when the rewrites parser is enabled.

Need to delay the check. See attached patch.

Attachments (3)

9304.01.patch (2.5 KB ) - added by r-a-y 12 months ago.
9304-without-patch_with-patch.png (92.3 KB ) - added by emaralive 3 months ago.
Screenshot - 9304-without-patch_with-patch.png
9304.02.patch (1.3 KB ) - added by emaralive 3 months ago.
9304.02.patch supersedes 9304.01.patch

Download all attachments as: .zip

Change History (14)

@r-a-y
12 months ago

#1 @espellcaste
9 months ago

  • Milestone Awaiting Review14.5.0

#2 @vapvarun
9 months ago

Tested 9304.01.patch - works as expected.

Before patch: no-js class never added on BP pages because is_buddypress() returns false in constructor.

After patch: no-js class properly added, then replaced with js by BuddyPress JavaScript.

Thanks @r-a-y for the clean fix! +1 for commit.

#3 @espellcaste
9 months ago

In 14174:

Restore no-js body class for BuddyPress pages.

Regression introduced at [13672], part of [13418].

Props r-a-y and vapvarun.

See #8679
See #9304 (14.0)

#4 @espellcaste
9 months ago

  • Owner set to espellcaste
  • Resolutionfixed
  • Status newclosed

In 14175:

Restore no-js body class for BuddyPress pages.

Regression introduced at [13672], part of [13418].

Props r-a-y and vapvarun.

See #8679
Fixes #9304 (trunk)

#5 @emaralive
3 months ago

  • Resolution fixed
  • Status closedreopened

Reopened due an incomplete assessment of the efficacy of the initial patch. It turns out that the boolean operator used for a conditional check should have been && (AND) as opposed to || (OR). The below snippet represents the current coding with the OR operator.

public function add_nojs_body_class( $classes ) {
    /** This filter is documented in bp-core/bp-core-dependency.php */
    if ( ! is_buddypress() || apply_filters( 'bp_enqueue_assets_in_bp_pages_only', true ) ) {
        return $classes;
    }

    $classes[] = 'no-js';

    return array_unique( $classes );
}

The following is that table that supports a simple truth table to illustrate the issue at hand:

A = ! is_buddypress() - true when on a non BuddyPress page and false when on a BuddyPress page
B = apply_filters( 'bp_enqueue_assets_in_bp_pages_only', true ) - true when only enqueue on BP pages, false on any page
T = true
F = false
R = result - true when no-js is added to the body class, otherwise false

The below truth table represent the situation with the OR operator.

A B R
T T F
T F F
F T F
F F T

So, the only state in which no-js is added to the body class is when on a BP page (A is false) and when the filter hook bp_enqueue_assets_in_bp_pages_only is false (B is false).

The top image (without patch) from the screenshot (9304-without-patch_with-patch.png) represents the truth table state of when on a BP page (A is false) and when the filter hook bp_enqueue_assets_in_bp_pages_only is false (B is true).

Changing the boolean operator from OR to AND, produces the following truth table which produces the desired outcome for each state. The bottom image (with patch) from the screenshot (9304-without-patch_with-patch.png) represents the truth table state of when on a BP page (A is false) and when the filter hook bp_enqueue_assets_in_bp_pages_only is false (B is true).

A B R
T T F
T F T
F T T
F F T

NOTE: attachment 9304.02.patch to be used in conjunction with attachment 9304.01.patch. Apply 9304.01.patch first the 9304.02.patch

Last edited 3 months ago by emaralive (previous) (diff)

@emaralive
3 months ago

Screenshot - 9304-without-patch_with-patch.png

@emaralive
3 months ago

9304.02.patch supersedes 9304.01.patch

#6 @dcavins
3 months ago

OK I see. We wanted to negate this statement:
if ( is_buddypress() || ! apply_filters( 'bp_enqueue_assets_in_bp_pages_only', true ) ) { ... }

so could have written
if ( ! ( is_buddypress() || ! apply_filters( 'bp_enqueue_assets_in_bp_pages_only', true ) ) ) { ... }

but chose to solve it out. According to the rules of logic (De Morgan?) the negation should be
if ( ! is_buddypress() && apply_filters( 'bp_enqueue_assets_in_bp_pages_only', true ) ) { ... }

Thanks for catching this!

#7 @dcavins
3 months ago

In 14204:

Restore no-js body class for BuddyPress pages. (12.0 branch)

Regression introduced at [13672], part of [13418].

Props r-a-y and vapvarun.

See #8679
See #9304 (14.0)

#8 @emaralive
3 months ago

Yeah, logic can be confusing. Thanks for the commits!

#9 @emaralive
3 months ago

  • Resolutionfixed
  • Status reopenedclosed

#10 @emaralive
3 months ago

  • Resolution fixed
  • Status closedreopened

Oops, thought we were done here, so I closed it but, we appear to be missing some commit messages, so I'll reopen again.

Last edited 3 months ago by emaralive (previous) (diff)

#11 @emaralive
3 months ago

  • Resolutionfixed
  • Status reopenedclosed

In 14200:

Fix 'no-js' body class logic for BuddyPress pages.

This is a correction to 14175 which attempted to address the regression introduced at [13672], part of [13418].

Props emaralive.

Fixes #9304.


In 14202:

Fix 'no-js' body class logic for BuddyPress pages. (14.0 branch)

This is a correction to 14175 which attempted to address the regression introduced at [13672], part of [13418].

Props emaralive.

Fixes #9304.


In 14205:

Fix 'no-js' body class logic for BuddyPress pages. (12.0 branch)

This is a correction to 14175 which attempted to address the regression introduced at [13672], part of [13418].

Props emaralive.

Fixes #9304.

Note: See TracTickets for help on using tickets.