LearnPress – Course Review - Version 2.2

Version Description

  • Fixed bug cannot review course have commented
  • Add notices upgrading addon for LP 3.0
Download this release

Release Info

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

Code changes from version 1.1 to 2.2

assets/admin.css ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .review-stars {
3
+ margin: 0 0;
4
+ list-style: none;
5
+ overflow: hidden;
6
+ }
7
+
8
+ .review-stars:after {
9
+ clear: both;
10
+ content: '';
11
+ display: block;
12
+ }
13
+
14
+ .course-review-wrapper.submitting .ajaxload,
15
+ .course-review-wrapper.error .message{
16
+ display: inline-block;
17
+ }
18
+ .review-stars-rated{
19
+ width: 70px;
20
+ position: relative;
21
+ float: left;
22
+ }
23
+ .review-stars-rated .review-stars.empty,
24
+ .review-stars-rated .review-stars.filled {
25
+ width: 70px;
26
+ height: 14px;
27
+ font-family: dashicons;
28
+ font-size: 14px;
29
+ }
30
+ .review-stars-rated .review-stars.empty:before{
31
+ content: '\f154\f154\f154\f154\f154';
32
+ line-height: 1;
33
+ vertical-align: top;
34
+ }
35
+ .review-stars-rated .review-stars.filled:before{
36
+ content: '\f155\f155\f155\f155\f155';
37
+ line-height: 1;
38
+ vertical-align: top;
39
+ color: #f0cc05;
40
+ }
41
+ .review-stars-rated .review-stars.filled{
42
+ position: absolute;
43
+ top:0;
44
+ left: 0;
45
+ }
46
+ .course-rate {
47
+ overflow: hidden;
48
+ }
assets/course-review.css CHANGED
@@ -31,6 +31,10 @@
31
  text-align: left;
32
  }
33
 
 
 
 
 
34
  .review-form h3 {
35
  font-size: 16px;
36
  margin: 0 0 20px;
@@ -76,7 +80,7 @@
76
  }
77
 
78
  .review-form .review-fields > li input[type="text"],
79
- .review-form .review-fields > li textarea{
80
  width: 100%;
81
  }
82
 
@@ -121,37 +125,116 @@
121
  color: #F05A19;
122
  cursor: pointer;
123
  }
 
124
  .review-form .ajaxload,
125
- .review-form .message{
126
  display: none;
127
  }
 
128
  .course-review-wrapper.submitting .ajaxload,
129
- .course-review-wrapper.error .message{
130
  display: inline-block;
131
  }
132
- .review-stars-rated{
133
- width: 120px;
 
134
  position: relative;
 
135
  }
 
136
  .review-stars-rated .review-stars.empty,
137
  .review-stars-rated .review-stars.filled {
138
  width: 120px;
139
  height: 24px;
140
  font-family: dashicons;
141
- font-size: 24px;
 
142
  }
143
- .review-stars-rated .review-stars.empty:before{
 
144
  content: '\f154\f154\f154\f154\f154';
145
  line-height: 1;
146
  vertical-align: top;
147
  }
148
- .review-stars-rated .review-stars.filled:before{
 
149
  content: '\f155\f155\f155\f155\f155';
150
  line-height: 1;
151
  vertical-align: top;
152
  }
153
- .review-stars-rated .review-stars.filled{
 
154
  position: absolute;
155
- top:0;
156
  left: 0;
157
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  text-align: left;
32
  }
33
 
34
+ .review-form .close {
35
+ margin-top: 10px;
36
+ }
37
+
38
  .review-form h3 {
39
  font-size: 16px;
40
  margin: 0 0 20px;
80
  }
81
 
82
  .review-form .review-fields > li input[type="text"],
83
+ .review-form .review-fields > li textarea {
84
  width: 100%;
85
  }
86
 
125
  color: #F05A19;
126
  cursor: pointer;
127
  }
128
+
129
  .review-form .ajaxload,
130
+ .review-form .message {
131
  display: none;
132
  }
133
+
134
  .course-review-wrapper.submitting .ajaxload,
135
+ .course-review-wrapper.error .message {
136
  display: inline-block;
137
  }
138
+
139
+ .review-stars-rated {
140
+ width: 90px;
141
  position: relative;
142
+ display: inline-block;
143
  }
144
+
145
  .review-stars-rated .review-stars.empty,
146
  .review-stars-rated .review-stars.filled {
147
  width: 120px;
148
  height: 24px;
149
  font-family: dashicons;
150
+ font-size: 18px;
151
+ color: #f2b827;
152
  }
153
+
154
+ .review-stars-rated .review-stars.empty:before {
155
  content: '\f154\f154\f154\f154\f154';
156
  line-height: 1;
157
  vertical-align: top;
158
  }
159
+
160
+ .review-stars-rated .review-stars.filled:before {
161
  content: '\f155\f155\f155\f155\f155';
162
  line-height: 1;
163
  vertical-align: top;
164
  }
165
+
166
+ .review-stars-rated .review-stars.filled {
167
  position: absolute;
168
+ top: 0;
169
  left: 0;
170
+ }
171
+
172
+ .course-rate {
173
+ overflow: hidden;
174
+ margin: 10px 0;
175
+ }
176
+
177
+ .course-rate .review-bar {
178
+ width: calc(100% - 125px);
179
+ margin-right: 5px;
180
+ height: 15px;
181
+ background: #DDD;
182
+ display: inline-block;
183
+ }
184
+
185
+ .course-rate .review-bar .rating {
186
+ background: #95e6f9;
187
+ height: 15px;
188
+ }
189
+
190
+ .course-rate .review-number {
191
+ margin-bottom: 0;
192
+ }
193
+
194
+ .course-reviews-list {
195
+ list-style: none;
196
+ margin: 0;
197
+ }
198
+
199
+ .course-reviews-list li {
200
+ margin-bottom: 20px;
201
+ padding: 20px;
202
+ background-color: #fafafa;
203
+ border: 1px solid #ddd;
204
+ overflow: hidden;
205
+ }
206
+
207
+ .course-reviews-list li .review-author {
208
+ width: 80px;
209
+ float: left;
210
+ margin-right: 20px;
211
+ }
212
+
213
+ .course-reviews-list li .review-author-info {
214
+ float: left;
215
+ }
216
+
217
+ .course-reviews-list li .review-text {
218
+ width: -webkit-calc(100% - 100px);
219
+ float: right;
220
+ }
221
+
222
+ .course-reviews-list li .user-name {
223
+ margin: 5px;
224
+ }
225
+
226
+ .course-reviews-list li .review-title {
227
+ clear: both;
228
+ font-size: 14px;
229
+ font-style: italic;
230
+ font-weight: 700;
231
+ line-height: 25px;
232
+ margin: 9px 0 15px;
233
+ }
234
+
235
+ @media (max-width: 600px) {
236
+ .course-reviews-list li .review-text {
237
+ width: 100%;
238
+ float: left;
239
+ }
240
+ }
assets/course-review.js CHANGED
@@ -6,7 +6,9 @@
6
  * @version 1.0
7
  */
8
  ;(function ($) {
9
-
 
 
10
  function CourseReview() {
11
  var $reviewForm = $('#course-review').appendTo(document.body),
12
  $reviewBtn = $(".write-a-review"),
@@ -70,19 +72,19 @@
70
  var course_id = $(this).attr('data-id');
71
 
72
  if (0 == $reviewTitle.val().length) {
73
- alert(learn_press_course_review.empty_title)
74
  $reviewTitle.focus();
75
  return;
76
  }
77
 
78
  if (0 == $reviewContent.val().length) {
79
- alert(learn_press_course_review.empty_content)
80
  $reviewContent.focus();
81
  return;
82
  }
83
 
84
  if (!rating) {
85
- alert(learn_press_course_review.empty_rating)
86
  return;
87
  }
88
  $reviewForm.addClass('submitting');
@@ -92,10 +94,10 @@
92
  dataType: 'text',
93
  success : function (response) {
94
  submitting = false;
95
- response = LearnPress.parseJSON(response);
96
  if (response.result == 'success') {
97
  closeForm();
98
- LearnPress.reload();
99
  } else {
100
  $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
101
  $reviewForm.removeClass('submitting').addClass('error');
@@ -103,7 +105,7 @@
103
  }
104
  },
105
  error : function (response) {
106
- response = LearnPress.parseJSON(response);
107
  submitting = false;
108
  $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
109
  $reviewForm.removeClass('submitting').addClass('error');
6
  * @version 1.0
7
  */
8
  ;(function ($) {
9
+ if (typeof LP == 'undefined' && typeof LearnPress != 'undefined') {
10
+ window.LP = LearnPress;
11
+ }
12
  function CourseReview() {
13
  var $reviewForm = $('#course-review').appendTo(document.body),
14
  $reviewBtn = $(".write-a-review"),
72
  var course_id = $(this).attr('data-id');
73
 
74
  if (0 == $reviewTitle.val().length) {
75
+ alert(learn_press_course_review.localize.empty_title)
76
  $reviewTitle.focus();
77
  return;
78
  }
79
 
80
  if (0 == $reviewContent.val().length) {
81
+ alert(learn_press_course_review.localize.empty_content)
82
  $reviewContent.focus();
83
  return;
84
  }
85
 
86
  if (!rating) {
87
+ alert(learn_press_course_review.localize.empty_rating)
88
  return;
89
  }
90
  $reviewForm.addClass('submitting');
94
  dataType: 'text',
95
  success : function (response) {
96
  submitting = false;
97
+ response = LP.parseJSON(response);
98
  if (response.result == 'success') {
99
  closeForm();
100
+ LP.reload();
101
  } else {
102
  $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
103
  $reviewForm.removeClass('submitting').addClass('error');
105
  }
106
  },
107
  error : function (response) {
108
+ response = LP.parseJSON(response);
109
  submitting = false;
110
  $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
111
  $reviewForm.removeClass('submitting').addClass('error');
backward.php ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
3
+ define( 'LP_ADDON_COURSE_REVIEW_PATH', dirname( __FILE__ ) );
4
+ define( 'LP_ADDON_COURSE_REVIEW_PER_PAGE', 5 );
5
+ define( 'LP_ADDON_COURSE_REVIEW_VER', '2.0.2' );
6
+ define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '2.0' );
7
+
8
+ /**
9
+ * Class LP_Addon_Course_Review
10
+ */
11
+ class LP_Addon_Course_Review {
12
+ /**
13
+ * @var null
14
+ */
15
+ protected static $_instance = null;
16
+
17
+ /**
18
+ * @var null
19
+ */
20
+
21
+ private static $comment_type = 'review';
22
+
23
+ /**
24
+ * LP_Addon_Course_Review constructor.
25
+ */
26
+ function __construct() {
27
+ if ( ! function_exists( 'learn_press_load_plugin_text_domain' ) ) {
28
+ return;
29
+ }
30
+ if ( self::$_instance || defined( 'LP_ADDON_COURSE_REVIEW_TMPL' ) ) {
31
+ return;
32
+ }
33
+ define( 'LP_ADDON_COURSE_REVIEW_TMPL', LP_ADDON_COURSE_REVIEW_PATH . '/templates/' );
34
+ define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
35
+ define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
36
+
37
+ add_filter( 'learn_press_course_tabs', array( $this, 'add_course_tab_reviews' ), 5 );
38
+
39
+ // add_action( 'learn_press_content_landing_summary', array( $this, 'print_rate' ), 75, 1 );
40
+ // add_action( 'learn_press_content_learning_summary', array( $this, 'print_rate' ), 75, 1 );
41
+ // add_action( 'learn_press_content_landing_summary', array( $this, 'print_review' ), 80 );
42
+ // add_action( 'learn_press_content_learning_summary', array( $this, 'print_review' ), 80 );
43
+ // add_action( 'learn_press_content_learning_summary', array( $this, 'add_review_button' ), 5 );
44
+ add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
45
+ add_action( 'wp', array( $this, 'course_review_init' ) );
46
+ //add_action( 'parse_comment_query', array( $this, 'exclude_rating' ) );
47
+
48
+ add_action( 'init', array( $this, 'load_text_domain' ) );
49
+
50
+ //add_action('restrict_manage_comments', array($this, 'add_comment_post_type_filter'));
51
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
52
+
53
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-functions.php';
54
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-widgets.php';
55
+
56
+ LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
57
+
58
+ $this->init_comment_table();
59
+
60
+ add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
61
+ add_action( 'widgets_init', array( $this, 'load_widget' ) );
62
+ self::$_instance = $this;
63
+ }
64
+
65
+ function print_rate() {
66
+ learn_press_course_review_template( 'course-rate.php' );
67
+ }
68
+
69
+ function print_review() {
70
+ learn_press_course_review_template( 'course-review.php' );
71
+ }
72
+
73
+ function add_review_button() {
74
+ if ( ! learn_press_get_user_rate( get_the_ID() ) ) {
75
+ learn_press_course_review_template( 'review-form.php' );
76
+ }
77
+ }
78
+
79
+ function admin_enqueue_assets() {
80
+ wp_enqueue_style( 'ourse-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/admin.css' );
81
+ }
82
+
83
+ function review_assets() {
84
+ if ( learn_press_is_course() ) {
85
+ wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.js', array( 'jquery' ), '', true );
86
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.css' );
87
+ wp_enqueue_style( 'dashicons' );
88
+ wp_localize_script( 'course-review', 'learn_press_course_review',
89
+ array(
90
+ 'localize' => array(
91
+ 'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
92
+ 'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
93
+ 'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
94
+ )
95
+ )
96
+ );
97
+ }
98
+ }
99
+
100
+ function course_review_init() {
101
+
102
+ $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
103
+ learn_press_get_course_review( get_the_ID(), $paged );
104
+ }
105
+
106
+ function exclude_rating( $query ) {
107
+ $query->query_vars['type__not_in'] = 'review';
108
+ }
109
+
110
+ function add_review() {
111
+ $response = array( 'result' => 'success' );
112
+ $nonce = ! empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
113
+ $id = ! empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
114
+ $rate = ! empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
115
+ $title = ! empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
116
+ $content = ! empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
117
+
118
+ if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
119
+ $response['result'] = 'fail';
120
+ $response['message'] = __( 'Error', 'learnpress-course-review' );
121
+ }
122
+
123
+ if ( get_post_type( $id ) != 'lp_course' ) {
124
+ $response['result'] = 'fail';
125
+ $response['message'] = __( 'Invalid course', 'learnpress-course-review' );
126
+ }
127
+
128
+ $return = learn_press_add_course_review(
129
+ array(
130
+ 'user_id' => get_current_user_id(),
131
+ 'course_id' => $id,
132
+ 'rate' => $rate,
133
+ 'title' => $title,
134
+ 'content' => $content
135
+ )
136
+ );
137
+ $response['comment'] = $return;
138
+ learn_press_send_json( $response );
139
+ }
140
+
141
+ function init_comment_table() {
142
+ add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
143
+ add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
144
+ }
145
+
146
+ function add_comment_type_filter( $cmt_types ) {
147
+ $cmt_types[ self::$comment_type ] = __( 'Course review', 'learnpress-course-review' );
148
+
149
+ return $cmt_types;
150
+ }
151
+
152
+ function add_comment_content_filter( $cmt_text ) {
153
+ global $comment;
154
+ if ( ! $comment || $comment->comment_type != 'review' ) {
155
+ return $cmt_text;
156
+ }
157
+
158
+ ob_start();
159
+ $rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
160
+ echo '<div class="course-rate">';
161
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
162
+ echo '</div>';
163
+ $cmt_text .= ob_get_clean();
164
+
165
+ return $cmt_text;
166
+ }
167
+
168
+ function add_comment_post_type_filter() {
169
+ ?>
170
+ <label class="screen-reader-text"
171
+ for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
172
+ <select id="filter-by-comment-post-type" name="post_type">
173
+ <?php
174
+ $comment_post_types = apply_filters( 'learn_press_admin_comment_post_type_types_dropdown', array(
175
+ '' => __( 'All post type', 'learnpress-course-review' ),
176
+ 'lp_course' => __( 'Course comments', 'learnpress-course-review' ),
177
+ ) );
178
+
179
+ foreach ( $comment_post_types as $type => $label ) {
180
+ echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
181
+ }
182
+
183
+ ?>
184
+
185
+ </select>
186
+ <?php
187
+ }
188
+
189
+
190
+ function shortcode_review( $atts ) {
191
+
192
+ $atts = shortcode_atts( array(
193
+ 'course_id' => 0,
194
+ 'show_rate' => 'yes',
195
+ 'show_review' => 'yes'
196
+ ), $atts, 'shortcode_review' );
197
+
198
+ $course_id = $atts['course_id'];
199
+ if ( ! $course_id ) {
200
+ $course_id = get_the_ID();
201
+ }
202
+
203
+ ob_start();
204
+ if ( $atts['show_rate'] ) {
205
+ $course_rate = learn_press_get_course_rate( $course_id, false );
206
+ $total = learn_press_get_course_rate_total( $course_id, false );
207
+ $rate_args = array(
208
+ 'course_id' => $course_id
209
+ ,
210
+ 'course_rate' => $course_rate
211
+ ,
212
+ 'total' => $total
213
+ );
214
+ learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
215
+ }
216
+
217
+ if ( $atts['show_review'] ) {
218
+ $course_review = learn_press_get_course_review( $course_id );
219
+ learn_press_course_review_template( 'shortcode-course-review.php', array(
220
+ 'course_id' => $course_id,
221
+ 'course_review' => $course_review
222
+ ) );
223
+ }
224
+
225
+ $content = ob_get_contents();
226
+ ob_clean();
227
+
228
+ return $content;
229
+ }
230
+
231
+ function load_widget() {
232
+ register_widget( 'LearnPress_Course_Review_Widget' );
233
+ }
234
+
235
+
236
+ public function add_course_tab_reviews( $tabs ) {
237
+ $course = LP()->global['course'];
238
+ $user = learn_press_get_current_user();
239
+ $tabs['reviews'] = array(
240
+ 'title' => __( 'Reviews', 'learnpress-course-review' ),
241
+ 'priority' => 0,
242
+ 'callback' => array( $this, 'add_course_tab_reviews_callback' )
243
+ );
244
+
245
+
246
+ return $tabs;
247
+ }
248
+
249
+ public function add_course_tab_reviews_callback() {
250
+ $user = learn_press_get_current_user();
251
+ $course_id = learn_press_get_course_id();
252
+ $this->print_rate();
253
+ $this->print_review();
254
+ if ( $user->has_course_status( $course_id, array( 'enrolled', 'completed', 'finished' ) ) ) {
255
+ $this->add_review_button();
256
+ }
257
+ }
258
+
259
+ public static function admin_notice() {
260
+ ?>
261
+ <div class="error">
262
+ <p><?php printf( __( '<strong>Course Review</strong> addon version %s requires <strong>LearnPress</strong> version %s or higher', 'learnpress-course-review' ), LP_ADDON_COURSE_REVIEW_VER, LP_ADDON_COURSE_REVIEW_REQUIRE_VER ); ?></p>
263
+ </div>
264
+ <?php
265
+ }
266
+
267
+ /**
268
+ * Return unique instance of LP_Addon_Course_Review object
269
+ */
270
+ static function instance() {
271
+ if ( ! defined( 'LEARNPRESS_VERSION' ) || ( version_compare( LEARNPRESS_VERSION, LP_ADDON_COURSE_REVIEW_REQUIRE_VER, '<' ) ) ) {
272
+ add_action( 'admin_notices', array( __CLASS__, 'admin_notice' ) );
273
+
274
+ return false;
275
+ }
276
+
277
+ if ( ! self::$_instance ) {
278
+ self::$_instance = new self();
279
+
280
+ }
281
+
282
+ return self::$_instance;
283
+ }
284
+
285
+ /**
286
+ * Load text domain
287
+ */
288
+ static function load_text_domain() {
289
+ if ( function_exists( 'learn_press_load_plugin_text_domain' ) ) {
290
+ learn_press_load_plugin_text_domain( LP_ADDON_COURSE_REVIEW_PATH, true );
291
+ }
292
+ }
293
+
294
+ }
incs/review-functions.php CHANGED
@@ -43,16 +43,17 @@ function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_A
43
  FROM {$wpdb->posts} p
44
  INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
45
  INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
46
- INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
47
- INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
48
- WHERE p.ID=%d AND c.comment_type=%s
49
  ORDER BY c.comment_date DESC
50
  LIMIT %d, %d
51
- ", '_lpr_review_title', '_lpr_rating', $course_id, 'review', $start, $per_page );
52
  $course_review = $wpdb->get_results( $query );
53
  if ( $course_review ) {
 
54
  $results['reviews'] = $course_review;
55
- $results['total'] = $wpdb->get_var( "SELECT FOUND_ROWS();" );
56
  if ( $results['total'] <= $start + $per_page ) {
57
  $results['finish'] = true;
58
  }
@@ -61,28 +62,37 @@ function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_A
61
  return $results;
62
  }
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  /**
65
  * @param $course_id
 
66
  *
67
  * @return mixed|void
68
  */
69
- function learn_press_get_course_rate( $course_id ) {
70
- global $wpdb;
71
- $query = $wpdb->prepare( "
72
- SELECT avg( cm1.meta_value ) as rated
73
- FROM {$wpdb->posts} p
74
- INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
75
- INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key='_lpr_rating'
76
- WHERE p.ID=%d
77
- AND c.comment_type=%s
78
- ", $course_id, 'review' );
79
-
80
- $rated = $wpdb->get_var( $query );
81
- return apply_filters( 'learn_press_get_course_rate', $rated );
82
  }
83
 
84
- function learn_press_get_course_rate_total( $course_id ) {
85
- global $wpdb;
86
  $query = $wpdb->prepare( "
87
  SELECT COUNT(*)
88
  FROM {$wpdb->posts} p
@@ -90,12 +100,15 @@ function learn_press_get_course_rate_total( $course_id ) {
90
  INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
91
  INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
92
  INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
93
- WHERE p.ID=%d AND c.comment_type=%s
94
  ORDER BY c.comment_date DESC",
95
- '_lpr_review_title', '_lpr_rating', $course_id, 'review'
96
  );
97
- $total = $wpdb->get_var( $query );
98
- return $total;
 
 
 
99
  }
100
 
101
  /**
@@ -119,9 +132,8 @@ function learn_press_get_user_review_title( $course_id, $user_id ) {
119
  * @return mixed|void
120
  */
121
  function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
122
- $course = LP_Course::get_course( $course_id );
123
  if ( !$user_id ) $user_id = get_current_user_id();
124
- if ( !$course->id || !$user_id ) return false;
125
 
126
  $comment = false;
127
  global $wpdb;
@@ -129,8 +141,12 @@ function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
129
  SELECT *
130
  FROM {$wpdb->posts} p
131
  INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
 
 
 
132
  WHERE c.comment_post_ID = %d AND user_id = %d
133
  ", $course_id, $user_id );
 
134
  $comments = $wpdb->get_results( $query );
135
  if ( $comments ) {
136
  $comment = $comments[0];
@@ -159,8 +175,8 @@ function learn_press_add_course_review( $args = array() ) {
159
  $user_id = $args['user_id'];
160
  $course_id = $args['course_id'];
161
  $user_review = learn_press_get_user_rate( $course_id, $user_id );
162
- $comment_id = 0;
163
- if( !$user_review ) {
164
  $user = get_user_by( 'id', $user_id );
165
  $comment_id = wp_new_comment(
166
  array(
@@ -185,7 +201,30 @@ function learn_press_add_course_review( $args = array() ) {
185
  }
186
 
187
  function learn_press_course_review_template( $name, $args = null ) {
188
- learn_press_get_template( $name, $args, LP_ADDON_COURSE_REVIEW_THEME_TMPL, LP_ADDON_COURSE_REVIEW_TMPL );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  }
190
 
191
  /*
@@ -221,6 +260,73 @@ add_action( 'wp_ajax_learn_press_add_course_review', 'learn_press_add_course_rev
221
  /**
222
  * Print rate for course
223
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
 
 
43
  FROM {$wpdb->posts} p
44
  INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
45
  INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
46
+ INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key = %s
47
+ INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key = %s
48
+ WHERE p.ID = %d AND c.comment_type = %s AND c.comment_approved = %d
49
  ORDER BY c.comment_date DESC
50
  LIMIT %d, %d
51
+ ", '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1, $start, $per_page );
52
  $course_review = $wpdb->get_results( $query );
53
  if ( $course_review ) {
54
+ $ratings = _learn_press_get_ratings( $course_id );
55
  $results['reviews'] = $course_review;
56
+ $results['total'] = $ratings[$course_id]['total'];// $wpdb->get_var( "SELECT FOUND_ROWS();" );
57
  if ( $results['total'] <= $start + $per_page ) {
58
  $results['finish'] = true;
59
  }
62
  return $results;
63
  }
64
 
65
+ function _learn_press_get_ratings( $course_id ) {
66
+ global $wpdb;
67
+ static $course_rates = array();
68
+ if ( !is_array( $course_id ) ) {
69
+ $ids = array( $course_id );
70
+ } else {
71
+ $ids = $course_id;
72
+ }
73
+ foreach ( $ids as $cid ) {
74
+ if ( !isset( $course_rates[$cid] ) ) {
75
+ $course_rates[$cid] = leanr_press_get_ratings_result( $cid );
76
+ }
77
+ }
78
+ return $course_rates;
79
+ }
80
+
81
+
82
  /**
83
  * @param $course_id
84
+ * @param $field
85
  *
86
  * @return mixed|void
87
  */
88
+ function learn_press_get_course_rate( $course_id, $field = 'rated' ) {
89
+ $ratings = _learn_press_get_ratings( $course_id );
90
+ $rate = ($field && array_key_exists( $field, $ratings[$course_id] )) ? $ratings[$course_id][$field] : $ratings[$course_id];
91
+ return apply_filters( 'learn_press_get_course_rate', $rate );
 
 
 
 
 
 
 
 
 
92
  }
93
 
94
+ function learn_press_get_course_rate_total( $course_id, $field = 'total' ) {
95
+ /*global $wpdb;
96
  $query = $wpdb->prepare( "
97
  SELECT COUNT(*)
98
  FROM {$wpdb->posts} p
100
  INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
101
  INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
102
  INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
103
+ WHERE p.ID=%d AND c.comment_type=%s and c.comment_approved = %d
104
  ORDER BY c.comment_date DESC",
105
+ '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1
106
  );
107
+ $total = $wpdb->get_var( $query );*/
108
+
109
+ $ratings = _learn_press_get_ratings( $course_id );
110
+ $total = array_key_exists( $field, $ratings[$course_id] ) ? $ratings[$course_id][$field] : $ratings;
111
+ return apply_filters( 'learn_press_get_course_rate_total', $total );
112
  }
113
 
114
  /**
132
  * @return mixed|void
133
  */
134
  function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
 
135
  if ( !$user_id ) $user_id = get_current_user_id();
136
+ if ( !$course_id ) $course_id = get_the_ID();
137
 
138
  $comment = false;
139
  global $wpdb;
141
  SELECT *
142
  FROM {$wpdb->posts} p
143
  INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
144
+ INNER JOIN
145
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id
146
+ AND cm.meta_key = '_lpr_rating'
147
  WHERE c.comment_post_ID = %d AND user_id = %d
148
  ", $course_id, $user_id );
149
+
150
  $comments = $wpdb->get_results( $query );
151
  if ( $comments ) {
152
  $comment = $comments[0];
175
  $user_id = $args['user_id'];
176
  $course_id = $args['course_id'];
177
  $user_review = learn_press_get_user_rate( $course_id, $user_id );
178
+ $comment_id = 0;
179
+ if ( !$user_review ) {
180
  $user = get_user_by( 'id', $user_id );
181
  $comment_id = wp_new_comment(
182
  array(
201
  }
202
 
203
  function learn_press_course_review_template( $name, $args = null ) {
204
+ learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
205
+ }
206
+
207
+ /*
208
+ add_action( 'learn_press_after_courses_loop_item', function () {
209
+ global $post;
210
+ echo "[", learn_press_get_course_rate_total( $post->ID ), "]";
211
+ } );*/
212
+
213
+ /*
214
+ * If we are viewing archive course page, so load all ratings of courses
215
+ * into cache to reduce queries and time rather than load separate course
216
+ * in loop
217
+ */
218
+ add_filter( 'the_posts', 'learn_press_init_courses_review' );
219
+ function learn_press_init_courses_review( $posts ) {
220
+ if ( $posts ) {
221
+ $pIds = array();
222
+ foreach ( $posts as $p ) {
223
+ $pIds[] = $p->ID;
224
+ }
225
+ _learn_press_get_ratings( $pIds );
226
+ }
227
+ return $posts;
228
  }
229
 
230
  /*
260
  /**
261
  * Print rate for course
262
  */
263
+ function leanr_press_get_ratings_result( $course_id = '', $get_items = false ) {
264
+ global $wpdb;
265
+ $query = $wpdb->prepare( "
266
+ SELECT
267
+ COUNT(*) `count` ,AVG(cm.meta_value) `avg`
268
+ FROM
269
+ {$wpdb->comments} c
270
+ INNER JOIN
271
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key='_lpr_rating'
272
+ WHERE
273
+ c.comment_approved = 1
274
+ AND c.comment_type = 'review'
275
+ AND c.user_id > 0
276
+ AND c.comment_post_ID =%d "
277
+ , $course_id );
278
+ $row = $wpdb->get_row( $query );
279
+
280
+ $count = 0;
281
+ $avg = 0;
282
+ if ( $row ) {
283
+ $count = $row->count;
284
+ $avg = $row->avg;
285
+ }
286
 
287
+ $rows = array();
288
+ if ( $count != 0 ):
289
+ $query = $wpdb->prepare( "
290
+ SELECT
291
+ cm.meta_value `rate`, COUNT(*) `count`
292
+ FROM
293
+ {$wpdb->comments} c
294
+ INNER JOIN
295
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key='_lpr_rating'
296
+ WHERE
297
+ c.comment_approved = 1
298
+ AND c.comment_type = 'review'
299
+ AND c.user_id > 0
300
+ AND c.comment_post_ID =%d
301
+ GROUP BY `cm`.`meta_value`
302
+ ORDER BY `cm`.`meta_value` DESC
303
+ "
304
+ , $course_id );
305
+ $rows = $wpdb->get_results( $query, OBJECT_K );
306
+ endif;
307
 
308
+ $items = array();
309
+ for ( $i = 5; $i > 0; $i -- ) {
310
+ if ( isset( $rows[$i] ) ) {
311
+ $items[] = array(
312
+ 'rated' => $rows[$i]->rate
313
+ , 'total' => $rows[$i]->count
314
+ , 'percent' => $rows[$i]->count / $count * 100
315
+ );
316
+ } else {
317
+ $items[] = array(
318
+ 'rated' => $i
319
+ , 'total' => 0
320
+ , 'percent' => 0
321
+ );
322
+ }
323
+ }
324
+ $result = array(
325
+ 'course_id' => $course_id
326
+ , 'total' => $count
327
+ , 'rated' => $avg
328
+ , 'items' => $items
329
+ );
330
 
331
+ return $result;
332
+ }
incs/review-widgets.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Reviews functions
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit; // Exit if accessed directly
8
+ }
9
+
10
+ // Creating the widget
11
+ class LearnPress_Course_Review_Widget extends WP_Widget {
12
+
13
+ function __construct() {
14
+ parent::__construct(
15
+ 'lpr_course_review',
16
+ __( 'Course Review', 'learnpress-course-review' ),
17
+ array( 'description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ), )
18
+ );
19
+ }
20
+
21
+
22
+ public function widget( $args, $instance ) {
23
+ $title = apply_filters( 'widget_title', $instance['title'] );
24
+ echo $args['before_widget'];
25
+
26
+ if ( ! empty( $title ) ) {
27
+ echo $args['before_title'] . $title . $args['after_title'];
28
+ }
29
+
30
+ $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : 0;
31
+ $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
32
+ $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
33
+
34
+ if ( ! $course_id ) {
35
+ $course_id = get_the_ID();
36
+ }
37
+
38
+ ob_start();
39
+ if ( $show_rate == 'yes' ) {
40
+ $course_rate = learn_press_get_course_rate( $course_id, false );
41
+ $rate_args = array(
42
+ 'course_id' => $course_id
43
+ ,
44
+ 'course_rate' => $course_rate
45
+ );
46
+ learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
47
+ }
48
+
49
+ if ( $show_review == 'yes' ) {
50
+ $course_review = learn_press_get_course_review( $course_id );
51
+ learn_press_course_review_template( 'shortcode-course-review.php', array( 'course_id' => $course_id,
52
+ 'course_review' => $course_review
53
+ ) );
54
+ }
55
+
56
+ $content = ob_get_contents();
57
+ ob_clean();
58
+ echo $content;
59
+ echo $args['after_widget'];
60
+ }
61
+
62
+ public function form( $instance ) {
63
+ $title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'wpb_widget_domain' );
64
+ $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : '';
65
+ $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
66
+ $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
67
+ ?>
68
+ <p>
69
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'learnpress-course-review' ); ?></label>
70
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
71
+ name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
72
+ value="<?php echo esc_attr( $title ); ?>"/>
73
+ </p>
74
+ <p>
75
+ <label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:', 'learnpress-course-review' ); ?></label>
76
+ <input class="widefat" id="<?php echo $this->get_field_id( 'course_id' ); ?>"
77
+ name="<?php echo $this->get_field_name( 'course_id' ); ?>" type="text"
78
+ value="<?php echo esc_attr( $course_id ); ?>"/>
79
+ </p>
80
+ <p>
81
+ <label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:', 'learnpress-course-review' ); ?></label>
82
+ <input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>"
83
+ name="<?php echo $this->get_field_name( 'show_rate' ); ?>" type="checkbox"
84
+ value="yes" <?php checked( $show_rate, 'yes', true ); ?>/>
85
+ </p>
86
+ <p>
87
+ <label for="<?php echo $this->get_field_id( 'show_review' ); ?>"><?php _e( 'Show Review:', 'learnpress-course-review' ); ?></label>
88
+ <input class="widefat" id="<?php echo $this->get_field_id( 'show_review' ); ?>"
89
+ name="<?php echo $this->get_field_name( 'show_review' ); ?>" type="checkbox"
90
+ value="yes" <?php checked( $show_review, 'yes', true ); ?> />
91
+ </p>
92
+ <?php
93
+ }
94
+
95
+ // Updating widget replacing old instances with new
96
+ public function update( $new_instance, $old_instance ) {
97
+ $instance = array();
98
+ var_dump( $new_instance );
99
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
100
+ $instance['course_id'] = ( ! empty( $new_instance['course_id'] ) ) ? strip_tags( $new_instance['course_id'] ) : '';
101
+ $instance['show_rate'] = ( ! empty( $new_instance['show_rate'] ) ) ? strip_tags( $new_instance['show_rate'] ) : '';
102
+ $instance['show_review'] = ( ! empty( $new_instance['show_review'] ) ) ? strip_tags( $new_instance['show_review'] ) : '';
103
+ var_dump( $instance );
104
+
105
+ return $instance;
106
+ }
107
+
108
+ }
109
+
110
+ // Class wpb_widget ends here
111
+ // Register and load the widget
112
+
languages/learnpress-course-review.pot CHANGED
@@ -1,95 +1,171 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: PACKAGE VERSION\n"
10
- "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2016-03-18 16:57+0700\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: \n"
16
- "MIME-Version: 1.0\n"
17
- "Content-Type: text/plain; charset=CHARSET\n"
18
- "Content-Transfer-Encoding: 8bit\n"
19
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
20
-
21
- #: learnpress-course-review.php:80
22
- msgid "Please enter the review title"
23
- msgstr ""
24
-
25
- #: learnpress-course-review.php:81
26
- msgid "Please enter the review content"
27
- msgstr ""
28
-
29
- #: learnpress-course-review.php:82
30
- msgid "Please select your rating"
31
- msgstr ""
32
-
33
- #: learnpress-course-review.php:109
34
- msgid "Error"
35
- msgstr ""
36
-
37
- #: learnpress-course-review.php:114
38
- msgid "Invalid course"
39
- msgstr ""
40
-
41
- #: templates/course-rate.php:13
42
- #, php-format
43
- msgid "%d rating"
44
- msgid_plural "%d ratings"
45
- msgstr[0] ""
46
- msgstr[1] ""
47
-
48
- #: templates/course-review.php:12
49
- msgid "Reviews"
50
- msgstr ""
51
-
52
- #: templates/course-review.php:13
53
- #, php-format
54
- msgid "Average rate: <span>%.1f</span>"
55
- msgstr ""
56
-
57
- #: templates/course-review.php:21
58
- msgid "Loading..."
59
- msgstr ""
60
-
61
- #: templates/course-review.php:24
62
- msgid "No review to load"
63
- msgstr ""
64
-
65
- #: templates/course-review.php:27
66
- msgid "Load More"
67
- msgstr ""
68
-
69
- #: templates/review-form.php:12 templates/review-form.php:18
70
- msgid "Write a review"
71
- msgstr ""
72
-
73
- #: templates/review-form.php:24
74
- msgid "Title"
75
- msgstr ""
76
-
77
- #: templates/review-form.php:28
78
- msgid "Content"
79
- msgstr ""
80
-
81
- #: templates/review-form.php:32
82
- msgid "Rating"
83
- msgstr ""
84
-
85
- #: templates/review-form.php:42
86
- msgid "Add review"
87
- msgstr ""
88
-
89
- #: templates/review-form.php:43
90
- msgid "Cancel"
91
- msgstr ""
92
-
93
- #: templates/review-form.php:44
94
- msgid "Please wait..."
95
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: Package Name\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2017-09-07 10:29+0700\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
20
+
21
+ #: learnpress-course-review.php:110
22
+ msgid "Please enter the review title"
23
+ msgstr ""
24
+
25
+ #: learnpress-course-review.php:111
26
+ msgid "Please enter the review content"
27
+ msgstr ""
28
+
29
+ #: learnpress-course-review.php:112
30
+ msgid "Please select your rating"
31
+ msgstr ""
32
+
33
+ #: learnpress-course-review.php:139
34
+ msgid "Error"
35
+ msgstr ""
36
+
37
+ #: learnpress-course-review.php:144
38
+ msgid "Invalid course"
39
+ msgstr ""
40
+
41
+ #: learnpress-course-review.php:166
42
+ msgid "Course review"
43
+ msgstr ""
44
+
45
+ #: learnpress-course-review.php:190
46
+ msgid "Filter by post type"
47
+ msgstr ""
48
+
49
+ #: learnpress-course-review.php:194
50
+ msgid "All post type"
51
+ msgstr ""
52
+
53
+ #: learnpress-course-review.php:195
54
+ msgid "Course comments"
55
+ msgstr ""
56
+
57
+ #: learnpress-course-review.php:260 templates/course-review.php:11
58
+ #: templates/shortcode-course-review.php:13
59
+ msgid "Reviews"
60
+ msgstr ""
61
+
62
+ #: learnpress-course-review.php:279
63
+ #, php-format
64
+ msgid ""
65
+ "<strong>Course Review</strong> addon version %s requires <strong>LearnPress</"
66
+ "strong> version %s or higher"
67
+ msgstr ""
68
+
69
+ #: incs/review-widgets.php:16
70
+ msgid "Course Review"
71
+ msgstr ""
72
+
73
+ #: incs/review-widgets.php:17
74
+ msgid "Display ratings and reviews of course"
75
+ msgstr ""
76
+
77
+ #: incs/review-widgets.php:63
78
+ msgid "New title"
79
+ msgstr ""
80
+
81
+ #: incs/review-widgets.php:69
82
+ msgid "Title:"
83
+ msgstr ""
84
+
85
+ #: incs/review-widgets.php:75
86
+ msgid "Course Id:"
87
+ msgstr ""
88
+
89
+ #: incs/review-widgets.php:81
90
+ msgid "Show Rate:"
91
+ msgstr ""
92
+
93
+ #: incs/review-widgets.php:87
94
+ msgid "Show Review:"
95
+ msgstr ""
96
+
97
+ #: templates/course-rate.php:18
98
+ #, php-format
99
+ msgid " %1.2f average based on "
100
+ msgstr ""
101
+
102
+ #: templates/course-rate.php:19
103
+ #, php-format
104
+ msgid " %d rating"
105
+ msgid_plural "%d ratings"
106
+ msgstr[0] ""
107
+ msgstr[1] ""
108
+
109
+ #: templates/course-rate.php:29
110
+ msgid " Star"
111
+ msgstr ""
112
+
113
+ #: templates/course-review.php:19 templates/shortcode-course-review.php:22
114
+ msgid "Loading..."
115
+ msgstr ""
116
+
117
+ #: templates/course-review.php:22 templates/shortcode-course-review.php:25
118
+ msgid "No review to load"
119
+ msgstr ""
120
+
121
+ #: templates/course-review.php:25 templates/shortcode-course-review.php:28
122
+ msgid "Load More"
123
+ msgstr ""
124
+
125
+ #: templates/review-form.php:13 templates/review-form.php:19
126
+ msgid "Write a review"
127
+ msgstr ""
128
+
129
+ #: templates/review-form.php:25
130
+ msgid "Title"
131
+ msgstr ""
132
+
133
+ #: templates/review-form.php:29
134
+ msgid "Content"
135
+ msgstr ""
136
+
137
+ #: templates/review-form.php:33
138
+ msgid "Rating"
139
+ msgstr ""
140
+
141
+ #: templates/review-form.php:43
142
+ msgid "Add review"
143
+ msgstr ""
144
+
145
+ #: templates/review-form.php:44
146
+ msgid "Cancel"
147
+ msgstr ""
148
+
149
+ #: templates/review-form.php:45
150
+ msgid "Please wait..."
151
+ msgstr ""
152
+
153
+ #: templates/shortcode-course-rate.php:12
154
+ #, php-format
155
+ msgid "%d rating"
156
+ msgid_plural "%d ratings"
157
+ msgstr[0] ""
158
+ msgstr[1] ""
159
+
160
+ #: templates/shortcode-course-rate.php:25
161
+ msgid "Star"
162
+ msgstr ""
163
+
164
+ #: templates/shortcode-course-rate.php:26
165
+ msgid "Rate"
166
+ msgstr ""
167
+
168
+ #: templates/shortcode-course-review.php:14
169
+ #, php-format
170
+ msgid "Average rate: <span>%.1f</span>"
171
+ msgstr ""
languages/learnpress-course-review.temp CHANGED
@@ -1,99 +1,99 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: PACKAGE VERSION\n"
10
- "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2016-03-18 16:51+0700\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: \n"
16
- "MIME-Version: 1.0\n"
17
- "Content-Type: text/plain; charset=CHARSET\n"
18
- "Content-Transfer-Encoding: 8bit\n"
19
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
20
-
21
- #: learnpress-course-review.php:80
22
- msgid "Please enter the review title"
23
- msgstr ""
24
-
25
- #: learnpress-course-review.php:81
26
- msgid "Please enter the review content"
27
- msgstr ""
28
-
29
- #: learnpress-course-review.php:82
30
- msgid "Please select your rating"
31
- msgstr ""
32
-
33
- #: learnpress-course-review.php:109
34
- msgid "Error"
35
- msgstr ""
36
-
37
- #: learnpress-course-review.php:114
38
- msgid "Invalid course"
39
- msgstr ""
40
-
41
- #: templates/course-rate.php:13
42
- #, php-format
43
- msgid "%d rating"
44
- msgid_plural "%d ratings"
45
- msgstr[0] ""
46
- msgstr[1] ""
47
-
48
- #: templates/course-review.php:12
49
- msgid "Reviews"
50
- msgstr ""
51
-
52
- #: templates/course-review.php:13
53
- #, php-format
54
- msgid "Average rate: <span>%.1f</span>"
55
- msgstr ""
56
-
57
- #: templates/course-review.php:21
58
- msgid "Loading..."
59
- msgstr ""
60
-
61
- #: templates/course-review.php:24
62
- msgid "No review to load"
63
- msgstr ""
64
-
65
- #: templates/course-review.php:27
66
- msgid "Load More"
67
- msgstr ""
68
-
69
- #: templates/review-form.php:12
70
- msgid "Write a Review"
71
- msgstr ""
72
-
73
- #: templates/review-form.php:18
74
- msgid "Write a review"
75
- msgstr ""
76
-
77
- #: templates/review-form.php:24
78
- msgid "Title"
79
- msgstr ""
80
-
81
- #: templates/review-form.php:28
82
- msgid "Content"
83
- msgstr ""
84
-
85
- #: templates/review-form.php:32
86
- msgid "Rating"
87
- msgstr ""
88
-
89
- #: templates/review-form.php:42
90
- msgid "Add review"
91
- msgstr ""
92
-
93
- #: templates/review-form.php:43
94
- msgid "Cancel"
95
- msgstr ""
96
-
97
- #: templates/review-form.php:44
98
- msgid "Please wait..."
99
- msgstr ""
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2016-03-18 16:51+0700\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
20
+
21
+ #: learnpress-course-review.php:80
22
+ msgid "Please enter the review title"
23
+ msgstr ""
24
+
25
+ #: learnpress-course-review.php:81
26
+ msgid "Please enter the review content"
27
+ msgstr ""
28
+
29
+ #: learnpress-course-review.php:82
30
+ msgid "Please select your rating"
31
+ msgstr ""
32
+
33
+ #: learnpress-course-review.php:109
34
+ msgid "Error"
35
+ msgstr ""
36
+
37
+ #: learnpress-course-review.php:114
38
+ msgid "Invalid course"
39
+ msgstr ""
40
+
41
+ #: templates/course-rate.php:13
42
+ #, php-format
43
+ msgid "%d rating"
44
+ msgid_plural "%d ratings"
45
+ msgstr[0] ""
46
+ msgstr[1] ""
47
+
48
+ #: templates/course-review.php:12
49
+ msgid "Reviews"
50
+ msgstr ""
51
+
52
+ #: templates/course-review.php:13
53
+ #, php-format
54
+ msgid "Average rate: <span>%.1f</span>"
55
+ msgstr ""
56
+
57
+ #: templates/course-review.php:21
58
+ msgid "Loading..."
59
+ msgstr ""
60
+
61
+ #: templates/course-review.php:24
62
+ msgid "No review to load"
63
+ msgstr ""
64
+
65
+ #: templates/course-review.php:27
66
+ msgid "Load More"
67
+ msgstr ""
68
+
69
+ #: templates/review-form.php:12
70
+ msgid "Write a Review"
71
+ msgstr ""
72
+
73
+ #: templates/review-form.php:18
74
+ msgid "Write a review"
75
+ msgstr ""
76
+
77
+ #: templates/review-form.php:24
78
+ msgid "Title"
79
+ msgstr ""
80
+
81
+ #: templates/review-form.php:28
82
+ msgid "Content"
83
+ msgstr ""
84
+
85
+ #: templates/review-form.php:32
86
+ msgid "Rating"
87
+ msgstr ""
88
+
89
+ #: templates/review-form.php:42
90
+ msgid "Add review"
91
+ msgstr ""
92
+
93
+ #: templates/review-form.php:43
94
+ msgid "Cancel"
95
+ msgstr ""
96
+
97
+ #: templates/review-form.php:44
98
+ msgid "Please wait..."
99
+ msgstr ""
learnpress-course-review.php CHANGED
@@ -1,157 +1,38 @@
1
  <?php
2
  /*
3
- Plugin Name: LearnPress Course Review
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: Adding review for course
6
  Author: ThimPress
7
- Version: 1.1
8
  Author URI: http://thimpress.com
9
  Tags: learnpress
10
- Text Domain: learnpress-course-review
 
 
 
11
  Domain Path: /languages/
12
  */
13
- if ( !defined( 'ABSPATH' ) ) {
14
  exit; // Exit if accessed directly
15
  }
16
 
17
- define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
18
- define( 'LP_ADDON_COURSE_REVIEW_PATH', dirname( __FILE__ ) );
19
- define( 'LP_ADDON_COURSE_REVIEW_PER_PAGE', 5 );
20
-
21
-
22
- /**
23
- * Class LP_Addon_Course_Review
24
- */
25
- class LP_Addon_Course_Review {
26
- /**
27
- * @var null
28
- */
29
- protected static $_instance = null;
30
-
31
- /**
32
- * LP_Addon_Course_Review constructor.
33
- */
34
- function __construct() {
35
- if ( !function_exists( 'learn_press_load_plugin_text_domain' ) ) {
36
- return;
37
- }
38
- if ( self::$_instance || defined( 'LP_ADDON_COURSE_REVIEW_TMPL' ) ) {
39
- return;
40
- }
41
-
42
- define( 'LP_ADDON_COURSE_REVIEW_TMPL', LP_ADDON_COURSE_REVIEW_PATH . '/templates/' );
43
- define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
44
- define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
45
-
46
- add_action( 'learn_press_after_the_title', array( $this, 'print_rate' ), 10, 1 );
47
- add_action( 'learn_press_content_landing_summary', array( $this, 'print_review' ), 80 );
48
- add_action( 'learn_press_content_learning_summary', array( $this, 'print_review' ), 80 );
49
- add_action( 'learn_press_content_learning_summary', array( $this, 'add_review_button' ), 5 );
50
- add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
51
- add_action( 'wp', array( $this, 'course_review_init' ) );
52
- //add_action( 'parse_comment_query', array( $this, 'exclude_rating' ) );
53
-
54
- add_action( 'init', array( $this, 'load_text_domain' ) );
55
-
56
-
57
- require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-functions.php';
58
-
59
- LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
60
-
61
- self::$_instance = $this;
62
- }
63
-
64
- function print_rate() {
65
- learn_press_course_review_template( 'course-rate.php' );
66
- }
67
-
68
- function print_review() {
69
- learn_press_course_review_template( 'course-review.php' );
70
- }
71
-
72
- function add_review_button() {
73
- if ( !learn_press_get_user_rate( get_the_ID() ) ) {
74
- learn_press_course_review_template( 'review-form.php' );
75
- }
76
- }
77
-
78
- function review_assets() {
79
- if ( learn_press_is_course() ) {
80
- wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.js', array( 'jquery' ), '', true );
81
- wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.css' );
82
- wp_enqueue_style( 'dashicons' );
83
- wp_localize_script( 'course-review', 'learn_press_course_review',
84
- array(
85
- 'localize' => array(
86
- 'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
87
- 'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
88
- 'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
89
- )
90
- )
91
- );
92
- }
93
- }
94
-
95
- function course_review_init() {
96
- $paged = !empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
97
- learn_press_get_course_review( get_the_ID(), $paged );
98
- }
99
-
100
- function exclude_rating( $query ) {
101
- $query->query_vars['type__not_in'] = 'review';
102
- }
103
-
104
-
105
- function add_review() {
106
- $response = array( 'result' => 'success' );
107
- $nonce = !empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
108
- $id = !empty( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0;
109
- $rate = !empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
110
- $title = !empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
111
- $content = !empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
112
-
113
- if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
114
- $response['result'] = 'fail';
115
- $response['message'] = __( 'Error', 'learnpress-course-review' );
116
- }
117
-
118
- if ( get_post_type( $id ) != 'lp_course' ) {
119
- $response['result'] = 'fail';
120
- $response['message'] = __( 'Invalid course', 'learnpress-course-review' );
121
- }
122
-
123
- $return = learn_press_add_course_review(
124
- array(
125
- 'user_id' => get_current_user_id(),
126
- 'course_id' => $id,
127
- 'rate' => $rate,
128
- 'title' => $title,
129
- 'content' => $content
130
- )
131
- );
132
- $response['comment'] = $return;
133
- learn_press_send_json( $response );
134
- }
135
-
136
- /**
137
- * Return unique instance of LP_Addon_Course_Review object
138
- */
139
- static function instance() {
140
- if ( !self::$_instance ) {
141
- self::$_instance = new self();
142
 
143
- }
144
- return self::$_instance;
145
- }
146
 
147
- /**
148
- * Load text domain
149
- */
150
- static function load_text_domain() {
151
- if( function_exists('learn_press_load_plugin_text_domain')){ learn_press_load_plugin_text_domain(LP_ADDON_COURSE_REVIEW_PATH, true ); }
152
  }
153
  }
154
 
155
- add_action( 'learn_press_ready', array( 'LP_Addon_Course_Review', 'instance' ) );
156
-
157
-
1
  <?php
2
  /*
3
+ Plugin Name: LearnPress - Course Review
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: Adding review for course
6
  Author: ThimPress
7
+ Version: 2.2
8
  Author URI: http://thimpress.com
9
  Tags: learnpress
10
+ Requires at least: 3.8
11
+ Tested up to: 4.8
12
+
13
+ Text Domain: learnpress
14
  Domain Path: /languages/
15
  */
16
+ if ( ! defined( 'ABSPATH' ) ) {
17
  exit; // Exit if accessed directly
18
  }
19
 
20
+ function learn_press_addon_course_review_notice() {
21
+ ?>
22
+ <div class="error">
23
+ <p><?php _e( '<strong>Course Review</strong> addon requires upgrading to works with <strong>LearnPress</strong> version 3.0 or higher', 'learnpress-course-review' ); ?></p>
24
+ </div>
25
+ <?php
26
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ function learn_press_load_addon_course_review() {
 
 
29
 
30
+ if ( defined( 'LEARNPRESS_VERSION' ) && version_compare( LEARNPRESS_VERSION, '3.0', '<' ) ) {
31
+ include_once "backward.php";
32
+ LP_Addon_Course_Review::instance();
33
+ } else {
34
+ add_action( 'admin_notices', 'learn_press_addon_course_review_notice' );
35
  }
36
  }
37
 
38
+ add_action( 'plugins_loaded', 'learn_press_load_addon_course_review' );
 
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === LearnPress Course Review - WordPress extension for LearnPress===
2
- Contributors: thimpress, tunnhn, kendy73
3
  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.2.2
7
- Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -33,10 +33,7 @@ Review add-on for LearnPress is using on some WordPress Themes: [Education WordP
33
  - <a href="http://thimpress.com/shop/co-instructors-add-on-for-learnpress/" target="_blank">Co-instructors add-on for LearnPress</a> - multiple instructors support for each LMS course.
34
  - <a href="http://thimpress.com/shop/collections-add-on-for-learnpress/" target="_blank">Collections add-on for LearnPress</a> - making LMS courses collection by selecting number of courses, this is helpful if you want to combine multiple LMS courses into a collection for a group of skills.
35
  - <a href="http://thimpress.com/shop/stripe-add-on-for-learnpress/" target="_blank">Stripe Payment method for LearnPress</a> - Stripe payment method for LearnPress WordPress LMS Plugin.
36
- - <a href="http://thimpress.com/shop/woocommerce-add-on-for-learnpress/" target="_blank">WooCommerce add-on for LearnPress</a> - using WooCommerce as payment gateway for LearnPrss WordPress LMS Plugin.
37
-
38
- **Credit**
39
- halink0803
40
 
41
  == Installation ==
42
 
@@ -49,7 +46,7 @@ halink0803
49
  1. Search, select and download LearnPress Course Review.
50
  2. Activate the plugin through the 'Plugins' menu in WordPress Dashboard.
51
 
52
- == Frequently Asked Questions ==
53
 
54
  Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPress</a> sites.
55
 
@@ -57,7 +54,21 @@ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPr
57
 
58
  1. LearnPress Course Review screenshot.
59
 
60
- == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  = 1.1 =
63
  + Fixed comments do not show in admin
@@ -66,11 +77,11 @@ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPr
66
  + Compatible with LearnPress version 1.0
67
 
68
  = 0.9.1 =
69
- - Updated languages file
70
- - Fixed PHP5 version 5.3.x error
71
 
72
  = 0.9.0 =
73
- - The first beta release.
74
 
75
  == Upgrade Notice ==
76
  Later :)
1
+ === LearnPress - Course Review ===
2
+ Contributors: thimpress, tunnhn, kendy73, leehld
3
  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.1
7
+ Stable tag: 2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
33
  - <a href="http://thimpress.com/shop/co-instructors-add-on-for-learnpress/" target="_blank">Co-instructors add-on for LearnPress</a> - multiple instructors support for each LMS course.
34
  - <a href="http://thimpress.com/shop/collections-add-on-for-learnpress/" target="_blank">Collections add-on for LearnPress</a> - making LMS courses collection by selecting number of courses, this is helpful if you want to combine multiple LMS courses into a collection for a group of skills.
35
  - <a href="http://thimpress.com/shop/stripe-add-on-for-learnpress/" target="_blank">Stripe Payment method for LearnPress</a> - Stripe payment method for LearnPress WordPress LMS Plugin.
36
+ - <a href="http://thimpress.com/shop/woocommerce-add-on-for-learnpress/" target="_blank">WooCommerce add-on for LearnPress</a> - using WooCommerce as payment gateway for LearnPrss WordPress LMS Plugin.
 
 
 
37
 
38
  == Installation ==
39
 
46
  1. Search, select and download LearnPress Course Review.
47
  2. Activate the plugin through the 'Plugins' menu in WordPress Dashboard.
48
 
49
+ == Frequently Asked Questions ==
50
 
51
  Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPress</a> sites.
52
 
54
 
55
  1. LearnPress Course Review screenshot.
56
 
57
+ == Changelog ==
58
+
59
+ = 2.2 =
60
+ + Fixed bug cannot review course have commented
61
+ + Add notices upgrading addon for LP 3.0
62
+
63
+ = 2.1 =
64
+ + Allow all user and guest user can view reviewed
65
+ + Only allow enrolled user can write new review
66
+
67
+ = 2.0.1 =
68
+ + Changed text domain to learnpress
69
+
70
+ = 2.0 =
71
+ + Updated to be compatible with LearnPress 2.0
72
 
73
  = 1.1 =
74
  + Fixed comments do not show in admin
77
  + Compatible with LearnPress version 1.0
78
 
79
  = 0.9.1 =
80
+ + Updated languages file
81
+ + Fixed PHP5 version 5.3.x error
82
 
83
  = 0.9.0 =
84
+ + The first beta release.
85
 
86
  == Upgrade Notice ==
87
  Later :)
templates/course-rate.php CHANGED
@@ -1,20 +1,43 @@
1
- <?php
2
  if ( !defined( 'ABSPATH' ) ) {
3
- exit; // Exit if accessed directly
4
  }
5
 
6
- $course_id = get_the_ID();
7
- $course_rate = learn_press_get_course_rate( $course_id );
8
- $total = learn_press_get_course_rate_total( $course_id );
 
 
9
  ?>
10
  <div class="course-rate">
11
- <?php
12
- learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
13
- $text=sprintf( _n('%d rating', '%d ratings', $total, 'learnpress-course-review'), $total);
14
- ?>
15
- <p class="review-number">
16
- <?php do_action( 'learn_press_before_total_review_number' );?>
17
- <?php echo $text ; ?>
18
- <?php do_action( 'learn_press_after_total_review_number' );?>
19
- </p>
20
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
  if ( !defined( 'ABSPATH' ) ) {
3
+ exit; // Exit if accessed directly
4
  }
5
 
6
+ $course_id = get_the_ID();
7
+ $course_rate_res = learn_press_get_course_rate( $course_id, false );
8
+ $course_rate = $course_rate_res['rated'];
9
+ $total = $course_rate_res['total'];
10
+
11
  ?>
12
  <div class="course-rate">
13
+ <?php
14
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
15
+ ?>
16
+ <p class="review-number">
17
+ <?php do_action( 'learn_press_before_total_review_number' ); ?>
18
+ <?php printf( __( ' %1.2f average based on ', 'learnpress-course-review' ), $course_rate ); ?>
19
+ <?php printf( _n( ' %d rating', '%d ratings', $total, 'learnpress-course-review' ), $total ); ?>
20
+ <?php do_action( 'learn_press_after_total_review_number' ); ?>
21
+ </p>
22
+ <div>
23
+ <?php
24
+ if ( isset( $course_rate_res['items'] ) && !empty( $course_rate_res['items'] ) ):
25
+ foreach ( $course_rate_res['items'] as $item ):
26
+ $percent = round( $item['percent'], 0 );
27
+ ?>
28
+ <div class="course-rate">
29
+ <span><?php esc_html_e( $item['rated'] ); ?><?php _e( ' Star', 'learnpress-course-review' ); ?></span>
30
+ <!-- <span>--><?php //esc_html_e( $item['total'] );
31
+ ?><!----><?php //_e( 'Rate', 'learnpress-course-review' );
32
+ ?><!--</span>-->
33
+ <div class="review-bar">
34
+ <div class="rating" style="width:<?php echo $percent; ?>% "></div>
35
+ </div>
36
+ <span><?php echo esc_html( $percent ); ?>%</span>
37
+ </div>
38
+ <?php
39
+ endforeach;
40
+ endif;
41
+ ?>
42
+ </div>
43
+ </div>
templates/course-review.php CHANGED
@@ -5,12 +5,10 @@ if ( !defined( 'ABSPATH' ) ) {
5
  $course_id = get_the_ID();
6
  $course_review = learn_press_get_course_review( $course_id );
7
  if ( $course_review['total'] ) {
8
- $course_rate = learn_press_get_course_rate( $course_id );
9
- $reviews = $course_review['reviews'];
10
  ?>
11
  <div id="course-reviews">
12
  <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
13
- <p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress-course-review' ), $course_rate ); ?></p>
14
  <ul class="course-reviews-list">
15
  <?php foreach ( $reviews as $review ) { ?>
16
  <?php
5
  $course_id = get_the_ID();
6
  $course_review = learn_press_get_course_review( $course_id );
7
  if ( $course_review['total'] ) {
8
+ $reviews = $course_review['reviews'];
 
9
  ?>
10
  <div id="course-reviews">
11
  <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
 
12
  <ul class="course-reviews-list">
13
  <?php foreach ( $reviews as $review ) { ?>
14
  <?php
templates/loop-review.php CHANGED
@@ -1,18 +1,25 @@
1
  <li>
2
- <h4 class="user-name">
3
- <?php do_action( 'learn_press_before_review_username' );?>
4
- <?php echo $review->user_login; ?>
5
- <?php do_action( 'learn_press_after_review_username' );?>
6
- </h4>
7
- <?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $review->rate ) );?>
8
- <p class="review-title">
9
- <?php do_action( 'learn_press_before_review_title' );?>
10
- <?php echo $review->title ?>
11
- <?php do_action( 'learn_press_after_review_title' );?>
12
- </p>
13
- <div class="review-content">
14
- <?php do_action( 'learn_press_before_review_content' );?>
15
- <?php echo $review->content ?>
16
- <?php do_action( 'learn_press_after_review_content' );?>
17
- </div>
 
 
 
 
 
 
 
18
  </li>
1
  <li>
2
+ <div class="review-author">
3
+ <?php echo get_avatar( $review->user_email ) ?>
4
+ </div>
5
+ <div class="review-author-info">
6
+ <h4 class="user-name">
7
+ <?php do_action( 'learn_press_before_review_username' ); ?>
8
+ <?php echo $review->user_login; ?>
9
+ <?php do_action( 'learn_press_after_review_username' ); ?>
10
+ </h4>
11
+ <?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $review->rate ) ); ?>
12
+ <p class="review-title">
13
+ <?php do_action( 'learn_press_before_review_title' ); ?>
14
+ <?php echo $review->title ?>
15
+ <?php do_action( 'learn_press_after_review_title' ); ?>
16
+ </p>
17
+ </div>
18
+ <div class="review-text">
19
+ <div class="review-content">
20
+ <?php do_action( 'learn_press_before_review_content' ); ?>
21
+ <?php echo $review->content ?>
22
+ <?php do_action( 'learn_press_after_review_content' ); ?>
23
+ </div>
24
+ </div>
25
  </li>
templates/rating-stars.php CHANGED
@@ -1,4 +1,5 @@
 
1
  <div class="review-stars-rated">
2
- <div class="review-stars empty"></div>
3
- <div class="review-stars filled" style="width:<?php echo $rated*20; ?>%;"></div>
4
  </div>
1
+
2
  <div class="review-stars-rated">
3
+ <div class="review-stars empty"></div>
4
+ <div class="review-stars filled" style="width:<?php echo $rated * 20; ?>%;"></div>
5
  </div>
templates/review-form.php CHANGED
@@ -8,6 +8,7 @@
8
  */
9
 
10
  defined( 'ABSPATH' ) || exit();
 
11
  ?>
12
  <button class="write-a-review"><?php _e( 'Write a review', 'learnpress-course-review' ); ?></button>
13
  <div class="course-review-wrapper" id="course-review">
@@ -46,7 +47,7 @@ defined( 'ABSPATH' ) || exit();
46
  <?php wp_nonce_field( 'learn_press_course_review_' . get_the_ID(), 'review-nonce' ); ?>
47
  <input type="hidden" name="rating" value="0">
48
  <input type="hidden" name="lp-ajax" value="add_review">
49
- <input type="hidden" name="id" value="<?php echo get_the_ID(); ?>">
50
  </li>
51
  </ul>
52
  </form>
8
  */
9
 
10
  defined( 'ABSPATH' ) || exit();
11
+
12
  ?>
13
  <button class="write-a-review"><?php _e( 'Write a review', 'learnpress-course-review' ); ?></button>
14
  <div class="course-review-wrapper" id="course-review">
47
  <?php wp_nonce_field( 'learn_press_course_review_' . get_the_ID(), 'review-nonce' ); ?>
48
  <input type="hidden" name="rating" value="0">
49
  <input type="hidden" name="lp-ajax" value="add_review">
50
+ <input type="hidden" name="comment_post_ID" value="<?php echo get_the_ID(); ?>">
51
  </li>
52
  </ul>
53
  </form>
templates/shortcode-course-rate.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) {
3
+ exit; // Exit if accessed directly
4
+ }
5
+ $course_rate_res = $args['course_rate'];
6
+ $course_rate = $course_rate_res['rated'];
7
+ $total = $course_rate_res['total'];
8
+ ?>
9
+ <div class="course-rate">
10
+ <?php
11
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
12
+ $text = sprintf( _n('%d rating', '%d ratings', $total, 'learnpress-course-review'), $total);
13
+ ?>
14
+ <p class="review-number">
15
+ <?php do_action( 'learn_press_before_total_review_number' );?>
16
+ <?php echo $text ; ?>
17
+ <?php do_action( 'learn_press_after_total_review_number' );?>
18
+ </p>
19
+ <div>
20
+ <?php
21
+ if( isset($course_rate_res['items']) && !empty($course_rate_res['items']) ):
22
+ foreach ($course_rate_res['items'] as $item ):
23
+ ?>
24
+ <div class="course-rate">
25
+ <span><?php esc_html_e($item['rated']);?><?php _e('Star','learnpress-course-review');?></span>
26
+ <span><?php esc_html_e($item['total']);?><?php _e('Rate','learnpress-course-review');?></span>
27
+ <span><?php esc_html_e($item['percent']);?>%</span>
28
+ </div>
29
+ <?php
30
+ endforeach;
31
+ endif;
32
+ ?>
33
+ </div>
34
+ </div>
templates/shortcode-course-review.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) {
3
+ exit; // Exit if accessed directly
4
+ }
5
+
6
+ $course_id = $args['course_id'];
7
+ $course_review = learn_press_get_course_review( $course_id );
8
+ if ( $course_review['total'] ) {
9
+ $course_rate = learn_press_get_course_rate( $course_id, false );
10
+ $reviews = $course_review['reviews'];
11
+ ?>
12
+ <div id="course-reviews">
13
+ <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
14
+ <p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress-course-review' ), $course_rate ); ?></p>
15
+ <ul class="course-reviews-list">
16
+ <?php foreach ( $reviews as $review ) { ?>
17
+ <?php
18
+ learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) );
19
+ ?>
20
+ <?php } ?>
21
+ <?php if ( empty( $course_review['finish'] ) ) { ?>
22
+ <li class="loading"><?php _e( 'Loading...', 'learnpress-course-review' ); ?></li>
23
+ <?php }
24
+ //else?>
25
+ <!-- <li><?php _e( 'No review to load', 'learnpress-course-review' ); ?></li> -->
26
+ </ul>
27
+ <?php if ( empty( $course_review['finish'] ) ) { ?>
28
+ <button class="button" id="course-review-load-more" data-paged="<?php echo $course_review['paged']; ?>"><?php _e( 'Load More', 'learnpress-course-review' ); ?></button>
29
+ <?php } ?>
30
+ </div>
31
+ <?php
32
+ }