LearnPress Course Review Shortcode

Below, you’ll find a detailed guide on how to add the LearnPress – Course Review Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the LearnPress – Course Review Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the LearnPress – Course Review Plugin and the shortcodes it provides:

Plugin Icon
LearnPress – Course Review

"LearnPress – Course Review is an invaluable plugin enhancing your educational site. It allows users to rate and give feedback on your courses, ensuring quality and engagement."

★★★✩✩ (6) Active Installs: 40000+ Tested with: 6.1.4 PHP Version: 7.0
Included Shortcodes:
  • [learn_press_review]

LearnPress Course Review [learn_press_review] Shortcode

The LearnPress Course Review shortcode is used to display course reviews and ratings. It enqueues necessary styles and scripts, then sets default settings for ‘course_id’, ‘show_rate’, ‘show_review’, and ‘display_amount’. If no valid course is found, it returns a warning message. It fetches course rate and review data if ‘show_rate’ and ‘show_review’ are set to ‘yes’. Finally, it applies filters and returns the template with rating and review data.

Shortcode: [learn_press_review]

Parameters

Here is a list of all possible learn_press_review shortcode parameters and attributes:

  • course_id – Specifies the unique ID of the course to review.
  • show_rate – Controls whether to display the course rating (‘yes’ or ‘no’).
  • show_review – Determines if the course review will be shown (‘yes’ or ‘no’).
  • display_amount – Defines the number of reviews to display.

Examples and Usage

Basic example – Show reviews of a course by using the course ID

[learn_press_review course_id=101 /]

In this example, we’re using the shortcode to display the reviews of the course with ID 101. The ‘course_id’ parameter specifies which course’s reviews to display. If the course ID is invalid or the course doesn’t exist, a warning message will be displayed.

Advanced examples

Display the reviews of a course and limit the number of reviews displayed

[learn_press_review course_id=101 display_amount=5 /]

In this advanced example, we’re not only displaying the reviews of the course with ID 101, but we’re also limiting the number of reviews displayed to 5. The ‘display_amount’ parameter controls how many reviews to display. If no ‘display_amount’ is specified, the default value is 5.

Show the reviews and the rating of a course

[learn_press_review course_id=101 show_rate=yes show_review=yes /]

In this example, we’re using the shortcode to display both the reviews and the rating of the course with ID 101. The ‘show_rate’ parameter controls whether to display the course’s rating, and the ‘show_review’ parameter controls whether to display the course’s reviews. Both parameters default to ‘yes’ if not specified.

PHP Function Code

In case you have difficulties debugging what causing issues with [learn_press_review] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'learn_press_review', array( $this, 'shortcode_review' ) );

Shortcode PHP function:

function shortcode_review( array $setting = [] ) {
			wp_enqueue_style( 'learnpress' );
			wp_enqueue_style( 'course-review' );
			wp_enqueue_script( 'course-review' );

			$setting = shortcode_atts(
				array(
					'course_id'      => 0,
					'show_rate'      => 'yes',
					'show_review'    => 'yes',
					'display_amount' => '5',
				),
				$setting,
				'shortcode_review'
			);

			$course_id = $setting['course_id'];
			$course    = learn_press_get_course( $course_id );
			if ( ! $course ) {
				$message_data = [
					'status'  => 'warning',
					'content' => __( '[learn_press_review-warning] Course is invalid', 'learnpress-course-review' ),
				];
				ob_start();
				Template::instance()->get_frontend_template( 'global/lp-message.php', compact( 'message_data' ) );
				return ob_get_clean();
			}

			$user              = learn_press_get_current_user();
			$data_for_template = compact( 'course_id', 'user', 'setting' );
			if ( 'yes' === $setting['show_rate'] ) {
				$course_rate_res                      = learn_press_get_course_rate( $course_id, false );
				$data_for_template['course_rate_res'] = $course_rate_res;
			}
			if ( 'yes' === $setting['show_review'] ) {
				$course_review                      = learn_press_get_course_review( $course_id, 1 );
				$data_for_template['course_review'] = $course_review;
			}

			$data_for_template = apply_filters( 'lp/shortcode/course-review/data', $data_for_template );
			ob_start();
			LP_Addon_Course_Review_Preload::$addon->get_template(
				apply_filters( 'lp/shortcode/course-review/rating-comments/template', 'list-rating-reviews.php' ),
				[ 'data' => $data_for_template ]
			);

			return ob_get_clean();
		}

Code file location:

learnpress-course-review/learnpress-course-review/inc/load.php

Conclusion

Now that you’ve learned how to embed the LearnPress – Course Review Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *