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
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 @@ public function load_hooks() {

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

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

// 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 @@ public function body_class( $classes ) {
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 ) {
donnapep marked this conversation as resolved.
Show resolved Hide resolved

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

if ( ! $is_course_theme ) {
return $classes;
}

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

$css_string = wp_get_global_stylesheet( [ 'variables' ] ) ?? '';
$property_name = '--wp--custom--course-theme-variation';
$pattern = "/$property_name\s*:\s*([^;]+)/";
donnapep marked this conversation as resolved.
Show resolved Hide resolved

if ( preg_match( $pattern, $css_string, $matches ) ) {
// $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;
}

return $classes;
}

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