LearnPress – Course Review - Version 3.0.2

Version Description

  • Used Select2 field in Widget to avoid memory limit issue when querying too large number of courses.
  • Hidden Reply action in back end.
  • Fixed bug "Can't use function return value in write context".
Download this release

Release Info

Developer leehld
Plugin Icon 128x128 LearnPress – Course Review
Version 3.0.2
Comparing to
See all releases

Code changes from version 3.0.1 to 3.0.2

assets/css/admin.css CHANGED
@@ -45,4 +45,7 @@
45
  }
46
  .course-rate {
47
  overflow: hidden;
 
 
 
48
  }
45
  }
46
  .course-rate {
47
  overflow: hidden;
48
+ }
49
+ .select2-container {
50
+ width: 140px !important;
51
  }
inc/load.php CHANGED
@@ -36,7 +36,7 @@ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
36
  */
37
  public function __construct() {
38
  parent::__construct();
39
- add_action( 'widgets_init', array( $this, 'load_widget' ) );
40
  }
41
 
42
  /**
@@ -73,7 +73,10 @@ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
73
 
74
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
75
  LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
76
- LP_Request_Handler::register_ajax( 'learnpress_load_course_review', array( $this, 'learnpress_load_course_review' ) );
 
 
 
77
  add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
78
 
79
  $this->init_comment_table();
@@ -82,11 +85,11 @@ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
82
  /**
83
  * Get html of reviews
84
  */
85
- public function learnpress_load_course_review(){
86
- $paged = ! empty( LP_Request::get_post('paged') ) ? intval( LP_Request::get_post('paged') ) : 1;
87
  $response = learn_press_get_course_review( get_the_ID(), $paged );
88
- if($response['reviews'] && count($response['reviews']) > 0){
89
- ob_start();
90
  learn_press_course_review_template( 'course-review.php', array( 'review' => $response ) );
91
  ob_end_clean();
92
  }
@@ -185,6 +188,16 @@ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
185
  public function init_comment_table() {
186
  add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
187
  add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
 
 
 
 
 
 
 
 
 
 
188
  }
189
 
190
  public function add_comment_type_filter( $cmt_types ) {
@@ -231,9 +244,9 @@ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
231
 
232
  public function shortcode_review( $atts ) {
233
  $atts = shortcode_atts( array(
234
- 'course_id' => 0,
235
- 'show_rate' => 'yes',
236
- 'show_review' => 'yes',
237
  'display_amount' => '5'
238
  ), $atts, 'shortcode_review' );
239
 
@@ -255,7 +268,7 @@ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
255
  }
256
 
257
  if ( $atts['show_review'] ) {
258
- $course_review = learn_press_get_course_review( $course_id, 1 , $atts['display_amount']);
259
  learn_press_course_review_template( 'shortcode-course-review.php', array(
260
  'course_id' => $course_id,
261
  'course_review' => $course_review
36
  */
37
  public function __construct() {
38
  parent::__construct();
39
+ add_action( 'widgets_init', array( $this, 'load_widget' ) );
40
  }
41
 
42
  /**
73
 
74
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
75
  LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
76
+ LP_Request_Handler::register_ajax( 'learnpress_load_course_review', array(
77
+ $this,
78
+ 'learnpress_load_course_review'
79
+ ) );
80
  add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
81
 
82
  $this->init_comment_table();
85
  /**
86
  * Get html of reviews
87
  */
88
+ public function learnpress_load_course_review() {
89
+ $paged = LP_Request::get_post( 'paged', 1 ) ? (int) LP_Request::get_post( 'paged', 1 ) : 1;
90
  $response = learn_press_get_course_review( get_the_ID(), $paged );
91
+ if ( $response['reviews'] && count( $response['reviews'] ) > 0 ) {
92
+ ob_start();
93
  learn_press_course_review_template( 'course-review.php', array( 'review' => $response ) );
94
  ob_end_clean();
95
  }
188
  public function init_comment_table() {
189
  add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
190
  add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
191
+ add_filter( 'comment_row_actions', array( $this, 'edit_comment_row_actions' ), 10, 2 );
192
+ }
193
+
194
+ public function edit_comment_row_actions( $actions, $comment ) {
195
+ if ( ! $comment || $comment->comment_type != 'review' ) {
196
+ return $actions;
197
+ }
198
+ unset( $actions['reply'] );
199
+
200
+ return $actions;
201
  }
202
 
203
  public function add_comment_type_filter( $cmt_types ) {
244
 
245
  public function shortcode_review( $atts ) {
246
  $atts = shortcode_atts( array(
247
+ 'course_id' => 0,
248
+ 'show_rate' => 'yes',
249
+ 'show_review' => 'yes',
250
  'display_amount' => '5'
251
  ), $atts, 'shortcode_review' );
252
 
268
  }
269
 
270
  if ( $atts['show_review'] ) {
271
+ $course_review = learn_press_get_course_review( $course_id, 1, $atts['display_amount'] );
272
  learn_press_course_review_template( 'shortcode-course-review.php', array(
273
  'course_id' => $course_id,
274
  'course_review' => $course_review
inc/widgets.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * @author ThimPress
6
  * @package LearnPress/Course-Review/Classes
7
- * @version 3.0.1
8
  */
9
 
10
  // Prevent loading this file directly
@@ -19,9 +19,41 @@ class LearnPress_Course_Review_Widget extends WP_Widget {
19
  __( 'Course Review', 'learnpress-course-review' ),
20
  array( 'description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ), )
21
  );
 
 
 
 
22
  }
23
 
 
 
 
 
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  public function widget( $args, $instance ) {
26
  wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
27
  wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
@@ -67,27 +99,17 @@ class LearnPress_Course_Review_Widget extends WP_Widget {
67
  }
68
 
69
  public function form( $instance ) {
70
- $arg = array(
71
- 'post_type' => 'lp_course',
72
- 'posts_per_page' => - 1,
73
- 'post_status' => 'publish'
74
- );
75
- $the_query = new WP_Query( $arg );
76
  $title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'wpb_widget_domain' );
77
  $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : '';
78
  $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
79
  $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
80
  $display_amount = isset( $instance['display_amount'] ) ? $instance['display_amount'] : 5;
81
- $option = '';
82
- if ( $the_query->have_posts() ) {
83
- while ( $the_query->have_posts() ) {
84
- $the_query->the_post();
85
- $checked = '';
86
- if ( $the_query->post->ID == $course_id ) {
87
- $checked = "selected='selected'";
88
- }
89
- $option .= "<option value='{$the_query->post->ID}' {$checked}>{$the_query->post->post_title}</option>";
90
- }
91
  }
92
  // Reset Post Data
93
  wp_reset_postdata();
@@ -98,12 +120,13 @@ class LearnPress_Course_Review_Widget extends WP_Widget {
98
  name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
99
  value="<?php echo esc_attr( $title ); ?>"/>
100
  </p>
101
- <p>
102
  <label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:', 'learnpress-course-review' ); ?></label>
103
- <select name="<?php echo $this->get_field_name( 'course_id' ); ?>">
 
104
  <?php echo $option; ?>
105
  </select>
106
- </p>
107
  <p>
108
  <label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:', 'learnpress-course-review' ); ?></label>
109
  <input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>"
@@ -119,9 +142,51 @@ class LearnPress_Course_Review_Widget extends WP_Widget {
119
  <p>
120
  <label for="<?php echo $this->get_field_id( 'display_amount' ); ?>"><?php _e( 'Amount Display:', 'learnpress-course-review' ); ?></label>
121
  <input class="widefat" id="<?php echo $this->get_field_id( 'display_amount' ); ?>"
122
- name="<?php echo $this->get_field_name( 'display_amount' ); ?>" type="numeric"
123
  value="<?php echo esc_attr( $display_amount ); ?>"/>
124
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  <?php
126
  }
127
 
4
  *
5
  * @author ThimPress
6
  * @package LearnPress/Course-Review/Classes
7
+ * @version 3.0.2
8
  */
9
 
10
  // Prevent loading this file directly
19
  __( 'Course Review', 'learnpress-course-review' ),
20
  array( 'description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ), )
21
  );
22
+ add_action( 'wp_ajax_learnpress_reviews_search_course', array(
23
+ __CLASS__,
24
+ 'learnpress_reviews_search_course'
25
+ ) );
26
  }
27
 
28
+ /**
29
+ *
30
+ */
31
+ public static function learnpress_reviews_search_course() {
32
+ $return = array();
33
 
34
+ // you can use WP_Query, query_posts() or get_posts() here - it doesn't matter
35
+ $search_results = new WP_Query( array(
36
+ 's' => $_GET['q'], // the search query
37
+ 'post_status' => 'publish', // if you don't want drafts to be returned
38
+ 'ignore_sticky_posts' => 1,
39
+ 'post_type' => LP_COURSE_CPT,
40
+ 'posts_per_page' => 50 // how much to show at once
41
+ ) );
42
+ if ( $search_results->have_posts() ) :
43
+ while ( $search_results->have_posts() ) : $search_results->the_post();
44
+ // shorten the title a little
45
+ $title = ( mb_strlen( $search_results->post->post_title ) > 50 ) ? mb_substr( $search_results->post->post_title, 0, 49 ) . '...' : $search_results->post->post_title;
46
+ $return[] = array( $search_results->post->ID, $title ); // array( Post ID, Post Title )
47
+ endwhile;
48
+ endif;
49
+ echo json_encode( $return );
50
+ die;
51
+ }
52
+
53
+ /**
54
+ * @param array $args
55
+ * @param array $instance
56
+ */
57
  public function widget( $args, $instance ) {
58
  wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
59
  wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
99
  }
100
 
101
  public function form( $instance ) {
 
 
 
 
 
 
102
  $title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'wpb_widget_domain' );
103
  $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : '';
104
  $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
105
  $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
106
  $display_amount = isset( $instance['display_amount'] ) ? $instance['display_amount'] : 5;
107
+ if ( $course_id ) {
108
+ $checked = "selected='selected'";
109
+ $review_title = get_the_title( $course_id );
110
+ $option = "<option value='{$course_id}' {$checked}>{$review_title}</option>";
111
+ } else {
112
+ $option = "<option value='0'>" . __( 'Pick up 1 course', 'learnpress-course-review' ) . "</option>";
 
 
 
 
113
  }
114
  // Reset Post Data
115
  wp_reset_postdata();
120
  name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
121
  value="<?php echo esc_attr( $title ); ?>"/>
122
  </p>
123
+ <div class="rwmb-input">
124
  <label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:', 'learnpress-course-review' ); ?></label>
125
+ <select class="rwmb-select " name="<?php echo $this->get_field_name( 'course_id' ); ?>"
126
+ id="<?php echo $this->get_field_id( 'course_id' ); ?>">
127
  <?php echo $option; ?>
128
  </select>
129
+ </div>
130
  <p>
131
  <label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:', 'learnpress-course-review' ); ?></label>
132
  <input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>"
142
  <p>
143
  <label for="<?php echo $this->get_field_id( 'display_amount' ); ?>"><?php _e( 'Amount Display:', 'learnpress-course-review' ); ?></label>
144
  <input class="widefat" id="<?php echo $this->get_field_id( 'display_amount' ); ?>"
145
+ name="<?php echo $this->get_field_name( 'display_amount' ); ?>" type="number"
146
  value="<?php echo esc_attr( $display_amount ); ?>"/>
147
  </p>
148
+ <script>
149
+ ;(function ($) {
150
+ function _ready() {
151
+ $("#<?php echo $this->get_field_id( 'course_id' ); ?>").select2({
152
+ placeholder: 'Select a course',
153
+ minimumInputLength: 3,
154
+ ajax: {
155
+ url: ajaxurl,
156
+ dataType: 'json',
157
+ quietMillis: 250,
158
+ data: function (params) {
159
+ return {
160
+ q: params.term, // search term
161
+ action: 'learnpress_reviews_search_course'
162
+ };
163
+ },
164
+ processResults: function( data ) {
165
+ var options = [];
166
+ if ( data ) {
167
+
168
+ // data is the array of arrays, and each of them contains ID and the Label of the option
169
+ $.each( data, function( index, text ) { // do not forget that "index" is just auto incremented value
170
+ options.push( { id: text[0], text: text[1] } );
171
+ });
172
+
173
+ }
174
+ return {
175
+ results: options
176
+ };
177
+ },
178
+ cache: true
179
+ },
180
+ language: {
181
+ noResults: function (params) {
182
+ return "There is no course to select.";
183
+ }
184
+ }
185
+ });
186
+ }
187
+ $(document).ready(_ready);
188
+ })(jQuery);
189
+ </script>
190
  <?php
191
  }
192
 
languages/learnpress-course-review.pot CHANGED
@@ -33,43 +33,43 @@ msgstr ""
33
  msgid "LearnPress"
34
  msgstr ""
35
 
36
- #: inc/load.php:136
37
  msgid "Please enter the review title"
38
  msgstr ""
39
 
40
- #: inc/load.php:137
41
  msgid "Please enter the review content"
42
  msgstr ""
43
 
44
- #: inc/load.php:138
45
  msgid "Please select your rating"
46
  msgstr ""
47
 
48
- #: inc/load.php:164
49
  msgid "Error"
50
  msgstr ""
51
 
52
- #: inc/load.php:169
53
  msgid "Invalid course"
54
  msgstr ""
55
 
56
- #: inc/load.php:191
57
  msgid "Course review"
58
  msgstr ""
59
 
60
- #: inc/load.php:215
61
  msgid "Filter by post type"
62
  msgstr ""
63
 
64
- #: inc/load.php:219
65
  msgid "All post type"
66
  msgstr ""
67
 
68
- #: inc/load.php:220
69
  msgid "Course comments"
70
  msgstr ""
71
 
72
- #: inc/load.php:278 templates/course-review.php:21
73
  #: templates/shortcode-course-review.php:21
74
  msgid "Reviews"
75
  msgstr ""
@@ -82,27 +82,31 @@ msgstr ""
82
  msgid "Display ratings and reviews of course"
83
  msgstr ""
84
 
85
- #: inc/widgets.php:76
86
  msgid "New title"
87
  msgstr ""
88
 
89
- #: inc/widgets.php:96
 
 
 
 
90
  msgid "Title:"
91
  msgstr ""
92
 
93
- #: inc/widgets.php:102
94
  msgid "Course Id:"
95
  msgstr ""
96
 
97
- #: inc/widgets.php:108
98
  msgid "Show Rate:"
99
  msgstr ""
100
 
101
- #: inc/widgets.php:114
102
  msgid "Show Review:"
103
  msgstr ""
104
 
105
- #: inc/widgets.php:120
106
  msgid "Amount Display:"
107
  msgstr ""
108
 
33
  msgid "LearnPress"
34
  msgstr ""
35
 
36
+ #: inc/load.php:139
37
  msgid "Please enter the review title"
38
  msgstr ""
39
 
40
+ #: inc/load.php:140
41
  msgid "Please enter the review content"
42
  msgstr ""
43
 
44
+ #: inc/load.php:141
45
  msgid "Please select your rating"
46
  msgstr ""
47
 
48
+ #: inc/load.php:167
49
  msgid "Error"
50
  msgstr ""
51
 
52
+ #: inc/load.php:172
53
  msgid "Invalid course"
54
  msgstr ""
55
 
56
+ #: inc/load.php:204
57
  msgid "Course review"
58
  msgstr ""
59
 
60
+ #: inc/load.php:228
61
  msgid "Filter by post type"
62
  msgstr ""
63
 
64
+ #: inc/load.php:232
65
  msgid "All post type"
66
  msgstr ""
67
 
68
+ #: inc/load.php:233
69
  msgid "Course comments"
70
  msgstr ""
71
 
72
+ #: inc/load.php:291 templates/course-review.php:21
73
  #: templates/shortcode-course-review.php:21
74
  msgid "Reviews"
75
  msgstr ""
82
  msgid "Display ratings and reviews of course"
83
  msgstr ""
84
 
85
+ #: inc/widgets.php:111
86
  msgid "New title"
87
  msgstr ""
88
 
89
+ #: inc/widgets.php:121
90
+ msgid "Pick up 1 course"
91
+ msgstr ""
92
+
93
+ #: inc/widgets.php:127
94
  msgid "Title:"
95
  msgstr ""
96
 
97
+ #: inc/widgets.php:133
98
  msgid "Course Id:"
99
  msgstr ""
100
 
101
+ #: inc/widgets.php:140
102
  msgid "Show Rate:"
103
  msgstr ""
104
 
105
+ #: inc/widgets.php:146
106
  msgid "Show Review:"
107
  msgstr ""
108
 
109
+ #: inc/widgets.php:152
110
  msgid "Amount Display:"
111
  msgstr ""
112
 
learnpress-course-review.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: LearnPress - Course Review
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: Adding review for course.
6
  Author: ThimPress
7
- Version: 3.0.1
8
  Author URI: http://thimpress.com
9
  Tags: learnpress
10
  Requires at least: 3.8
@@ -17,7 +17,7 @@ Domain Path: /languages/
17
  defined( 'ABSPATH' ) || exit;
18
 
19
  define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
20
- define( 'LP_ADDON_COURSE_REVIEW_VER', '3.0.1' );
21
  define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '3.0.0' );
22
 
23
  /**
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: Adding review for course.
6
  Author: ThimPress
7
+ Version: 3.0.2
8
  Author URI: http://thimpress.com
9
  Tags: learnpress
10
  Requires at least: 3.8
17
  defined( 'ABSPATH' ) || exit;
18
 
19
  define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
20
+ define( 'LP_ADDON_COURSE_REVIEW_VER', '3.0.2' );
21
  define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '3.0.0' );
22
 
23
  /**
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: lms, elearning, e-learning, learning management system, education, course, courses, quiz, quizzes, questions, training, guru, sell courses
5
  Requires at least: 3.8
6
  Tested up to: 4.9.5
7
- Stable tag: 3.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -56,6 +56,11 @@ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPr
56
 
57
  == Changelog ==
58
 
 
 
 
 
 
59
  = 3.0.1 =
60
  + Fixed bug with AJAX call when load more reviews.
61
 
4
  Tags: lms, elearning, e-learning, learning management system, education, course, courses, quiz, quizzes, questions, training, guru, sell courses
5
  Requires at least: 3.8
6
  Tested up to: 4.9.5
7
+ Stable tag: 3.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
56
 
57
  == Changelog ==
58
 
59
+ = 3.0.2 =
60
+ + Used Select2 field in Widget to avoid memory limit issue when querying too large number of courses.
61
+ + Hidden Reply action in back end.
62
+ + Fixed bug "Can't use function return value in write context".
63
+
64
  = 3.0.1 =
65
  + Fixed bug with AJAX call when load more reviews.
66