Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add course theme variation body class #7225

Closed
wants to merge 10 commits into from
4 changes: 4 additions & 0 deletions changelog/add-body-class-for-course-theme-variation
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Body class to indicate Course theme variation
37 changes: 37 additions & 0 deletions includes/class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,8 @@

add_action( 'body_class', array( $this, 'body_class' ) );

add_filter( 'body_class', array( $this, 'maybe_add_course_theme_variation_class' ) );

Check warning on line 738 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L738

Added line #L738 was not covered by tests

// Check for and activate JetPack LaTeX support
add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support' ), 200 ); // Runs after Jetpack has loaded it's modules

Expand Down Expand Up @@ -1405,6 +1407,41 @@
return $classes;
}

/**
* For course theme, add a body class with the variation.
*
* @param array $classes Body classes.
*
* @intenal
donnapep marked this conversation as resolved.
Show resolved Hide resolved
*
* @return array Body classes.
*/
public function maybe_add_course_theme_variation_class( $classes ) {

Check warning on line 1419 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1419

Added line #L1419 was not covered by tests
donnapep marked this conversation as resolved.
Show resolved Hide resolved

$is_course_theme = 'course' === wp_get_theme()->get_template();

Check warning on line 1421 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1421

Added line #L1421 was not covered by tests

if ( ! $is_course_theme ) {
return $classes;

Check warning on line 1424 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1423-L1424

Added lines #L1423 - L1424 were not covered by tests
}

if ( ! is_array( $classes ) ) {
$classes = [];

Check warning on line 1428 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1427-L1428

Added lines #L1427 - L1428 were not covered by tests
}

$css_string = wp_get_global_stylesheet( [ 'variables' ] ) ?? '';
$property_name = '--wp--custom--course-theme-variation';
$pattern = "/$property_name\s*:\s*([^;]+)/";

Check warning on line 1433 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1431-L1433

Added lines #L1431 - L1433 were not covered by tests
donnapep marked this conversation as resolved.
Show resolved Hide resolved

if ( preg_match( $pattern, $css_string, $matches ) ) {

Check warning on line 1435 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1435

Added line #L1435 was not covered by tests
// $matches[0] contains the full match
// $matches[1] contains the CSS value for the specified property
$css_value = trim( $matches[1] );
$classes[] = 'course-theme-variation-' . $css_value;

Check warning on line 1439 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1438-L1439

Added lines #L1438 - L1439 were not covered by tests
}

return $classes;

Check warning on line 1442 in includes/class-sensei.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei.php#L1442

Added line #L1442 was not covered by tests
}

/**
* Checks that the Jetpack Beautiful Maths module has been activated
* to support LaTeX within question titles and answers
Expand Down
Loading