diff --git a/.changelogs/reviews-avoid-use-of-inline-css.yml b/.changelogs/reviews-avoid-use-of-inline-css.yml new file mode 100644 index 0000000000..83fae3c257 --- /dev/null +++ b/.changelogs/reviews-avoid-use-of-inline-css.yml @@ -0,0 +1,5 @@ +significance: patch +type: changed +links: + - "#410" +entry: Avoid use of inline styles in course reviews. diff --git a/assets/scss/frontend/_reviews.scss b/assets/scss/frontend/_reviews.scss new file mode 100644 index 0000000000..6df33a0307 --- /dev/null +++ b/assets/scss/frontend/_reviews.scss @@ -0,0 +1,33 @@ +.llms_review { + margin: 20px 0px; + padding: 10px; + + h5 { + font-size: 17px; + margin: 3px 0px; + } + + h6 { + font-size: 13px; + } + + p { + font-size: 15px; + } +} + +.review_box { + + [type=text] { + margin: 10px 0px + } + + h5 { + color: red; + display: none; + } + + + .thank_you_box { + display: none; + } +} diff --git a/assets/scss/lifterlms.scss b/assets/scss/lifterlms.scss index d27cc3626c..b3474e9a0e 100644 --- a/assets/scss/lifterlms.scss +++ b/assets/scss/lifterlms.scss @@ -16,6 +16,7 @@ @import "frontend/syllabus"; @import "frontend/llms-progress"; @import "frontend/llms-author"; +@import "frontend/reviews"; @import "frontend/notices"; @import "frontend/llms-achievements-certs"; diff --git a/includes/class.llms.review.php b/includes/class.llms.review.php index ba74586cb0..8cc1e9e65a 100644 --- a/includes/class.llms.review.php +++ b/includes/class.llms.review.php @@ -3,12 +3,12 @@ * LifterLMS Course reviews * * This class handles the front end of the reviews. It is responsible - * for outputting the HTML on the course page (if reviews are activated) + * for outputting the HTML on the course page (if reviews are activated). * * @package LifterLMS/Classes * - * @since Unknown - * @version 5.9.0 + * @since 1.2.7 + * @version [version] */ defined( 'ABSPATH' ) || exit; @@ -16,18 +16,23 @@ /** * LLMS_Reviews class * - * @since Unknown + * @since 1.2.7 */ class LLMS_Reviews { + /** - * This is the constructor for this class. It takes care of attaching - * the functions in this file to the appropriate actions. These actions are: - * 1) output after course info - * 2) output after membership info - * 3 & 4) Add function call to the proper AJAX call + * This is the constructor for this class. + * + * It takes care of attaching the functions in this file to the + * appropriate actions. + * These actions are: + * 1) Output after course info. + * 2) Output after membership info. + * 3 & 4) Add function call to the proper AJAX call. + * + * @since 3.1.3 * * @return void - * @version 3.1.3 */ public function __construct() { add_action( 'wp_ajax_LLMSSubmitReview', array( $this, 'process_review' ) ); @@ -40,64 +45,112 @@ public function __construct() { * if not, nothing will happen. This function also checks to * see if a user is allowed to review more than once. * - * @since Unknown + * @since 1.2.7 * @since 3.24.0 Unknown. + * @since [version] Improve inline styles, escape output. + * + * @return void */ public static function output() { /** - * Check to see if we are supposed to output the code at all + * Check to see if we are supposed to output the code at all. */ if ( get_post_meta( get_the_ID(), '_llms_display_reviews', true ) ) { + + /** + * Filters the reviews section title. + * + * @since 1.2.7 + * + * @param string $section_title The section title. + */ + $section_title = apply_filters( 'lifterlms_reviews_section_title', __( 'What Others Have Said', 'lifterlms' ) ); + ?>
-

- get_post_meta( get_the_ID(), '_llms_num_reviews', true ), - 'post_type' => 'llms_review', - 'post_status' => 'publish', - 'post_parent' => get_the_ID(), - 'suppress_filters' => true, - ); - $posts_array = get_posts( $args ); +

+ get_post_meta( get_the_ID(), '_llms_num_reviews', true ), + 'post_type' => 'llms_review', + 'post_status' => 'publish', + 'post_parent' => get_the_ID(), + 'suppress_filters' => true, + ); - $styles = array( - 'background-color' => '#EFEFEF', - 'title-color' => 'inherit', - 'text-color' => 'inherit', - 'custom-css' => '', - ); + $posts_array = get_posts( $args ); - if ( has_filter( 'llms_review_custom_styles' ) ) { - $styles = apply_filters( 'llms_review_custom_styles', $styles ); - } + /** + * Allow review custom styles to be filtered. + * + * @since 1.2.7 + * + * @param array $styles Array of custom styles. + */ + $styles = apply_filters( + 'llms_review_custom_styles', + array( + 'background-color' => '#efefef', + 'title-color' => 'inherit', + 'text-color' => 'inherit', + 'custom-css' => '', + ) + ); + + $inline_styles = ''; + + if ( $styles['background-color'] ?? '' ) { + $inline_styles .= '.llms_review{background-color:' . $styles['background-color'] . '}'; + } + + if ( $styles['title-color'] ?? '' ) { + $inline_styles .= '.llms_review h5{color:' . $styles['title-color'] . '}'; + } - foreach ( $posts_array as $post ) { - echo $styles['custom-css']; + if ( $styles['text-color'] ?? '' ) { + $inline_styles .= '.llms_review h6,.llms_review p{color:' . $styles['text-color'] . '}'; + } + if ( $styles['custom-css'] ?? '' ) { + + // Remove style tags in case they were added with the filter. + $inline_styles .= str_replace( array( '' ), '', $styles['custom-css'] ); + } + + if ( $inline_styles ) { + echo ''; + } + + foreach ( $posts_array as $post ) { + ?> +
+
ID ); ?>
+
+ ID ) ) ) ); + ?> +
+

ID ) ); ?>

+
+ -
-
ID ); ?>
-
ID ) ) ); ?>
-

ID ); ?>

-
- -
+
1, @@ -109,6 +162,15 @@ public static function output() { ); $posts_array = get_posts( $args ); + /** + * Filters the thank you text. + * + * @since 1.2.7 + * + * @param string $thank_you_text The thank you text. + */ + $thank_you_text = apply_filters( 'llms_review_thank_you_text', __( 'Thank you for your review!', 'lifterlms' ) ); + /** * Check to see if we are allowed to write more than one review. * If we are not, check to see if we have written a review already. @@ -116,26 +178,26 @@ public static function output() { if ( get_post_meta( get_the_ID(), '_llms_multiple_reviews_disabled', true ) && $posts_array ) { ?>
-

+

-

- - - - - +

+ + +
+ +
- - + +
-