LLMS_Reviews::output()

This function handles the HTML output of the reviews and review form.


Description Description

If the option is enabled, the review form will be output, if not, nothing will happen. This function also checks to see if a user is allowed to review more than once.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.review.php

	public static function output() {

		/**
		 * 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' ) );

			?>
			<div id="old_reviews">
				<h3><?php echo esc_html( $section_title ); ?></h3>
				<?php
				$args = array(
					'posts_per_page'   => 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 );

				/**
				 * 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'] . '}';
				}

				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( '<style>', '</style>' ), '', $styles['custom-css'] );
				}

				if ( $inline_styles ) {
					echo '<style id="llms_review_custom_styles">' . esc_html( $inline_styles ) . '</style>';
				}

				foreach ( $posts_array as $post ) {
					?>
					<div class="llms_review">
						<div class="llms_review_title"><strong><?php echo esc_html( get_the_title( $post->ID ) ); ?></strong></div>
						<div class="llms_review_name">
							<?php
							// Translators: %s = The author display name.
							echo esc_html( sprintf( __( 'By: %s', 'lifterlms' ), get_the_author_meta( 'display_name', get_post_field( 'post_author', $post->ID ) ) ) );
							?>
						</div>
						<p><?php echo esc_html( get_post_field( 'post_content', $post->ID ) ); ?></p>
					</div>
					<?php
				}
				?>
				<hr>
			</div>
			<?php
		}

		/**
		 * Check to see if reviews are open.
		 */
		if ( get_post_meta( get_the_ID(), '_llms_reviews_enabled', true ) && is_user_logged_in() ) {

			/**
			 * 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' ) );

			if ( ! self::current_user_can_write_review( get_the_ID() ) ) {
				?>
				<div id="thank_you_box">
					<div><?php echo esc_html( $thank_you_text ); ?></div>
				</div>
				<?php
			} else {
				?>
				<div class="review_box" id="review_box">
					<h3><?php esc_html_e( 'Write a Review', 'lifterlms' ); ?></h3>
					<!--<form method="post" name="review_form" id="review_form">-->
					<label for="review_title">
						<?php esc_html_e( 'Review Title', 'lifterlms' ); ?>
					</label>
					<input type="text" name="review_title" id="review_title">
					<div class="review_error" id="review_title_error"><?php esc_html_e( 'Review Title is required.', 'lifterlms' ); ?></div>
					<label for="review_text">
						<?php esc_html_e( 'Review Text', 'lifterlms' ); ?>
					</label>
					<textarea name="review_text" id="review_text"></textarea>
					<div class="review_error" id="review_text_error"><?php esc_html_e( 'Review Text is required.', 'lifterlms' ); ?></div>
					<input name="action" value="submit_review" type="hidden">
					<input name="post_ID" value="<?php echo esc_attr( get_the_ID() ); ?>" type="hidden" id="post_ID">
					<?php wp_nonce_field( 'llms-review', 'llms_review_nonce' ); ?>
					<input type="submit" class="button" value="<?php esc_attr_e( 'Leave Review', 'lifterlms' ); ?>" id="llms_review_submit_button">
					<!--</form>	-->
				</div>
				<div class="thank_you_box" id="thank_you_box">
					<h2><?php echo esc_html( $thank_you_text ); ?></h2>
				</div>
				<?php
			}
		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
7.1.3 Improve inline styles, escape output.
3.24.0 Unknown.
1.2.7 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.