Version Description
- Updated to be compatible with LearnPress 2.0
Download this release
Release Info
Developer | leehld |
Plugin | LearnPress – Course Review |
Version | 2.0 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 2.0
- assets/admin.css +48 -0
- assets/course-review.css +78 -10
- assets/course-review.js +9 -7
- incs/review-functions.php +131 -29
- incs/review-widgets.php +99 -0
- languages/learnpress-course-review.pot +95 -95
- learnpress-course-review.php +149 -13
- readme.txt +11 -6
- templates/course-rate.php +38 -15
- templates/course-review.php +1 -3
- templates/loop-review.php +20 -15
- templates/rating-stars.php +3 -2
- templates/review-form.php +2 -1
- templates/shortcode-course-rate.php +34 -0
- templates/shortcode-course-review.php +32 -0
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
@@ -76,7 +76,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 +121,105 @@
|
|
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 |
-
|
133 |
-
|
|
|
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:
|
|
|
142 |
}
|
143 |
-
|
|
|
144 |
content: '\f154\f154\f154\f154\f154';
|
145 |
line-height: 1;
|
146 |
vertical-align: top;
|
147 |
}
|
148 |
-
|
|
|
149 |
content: '\f155\f155\f155\f155\f155';
|
150 |
line-height: 1;
|
151 |
vertical-align: top;
|
152 |
}
|
153 |
-
|
|
|
154 |
position: absolute;
|
155 |
-
top:0;
|
156 |
left: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
}
|
76 |
}
|
77 |
|
78 |
.review-form .review-fields > li input[type="text"],
|
79 |
+
.review-form .review-fields > li textarea {
|
80 |
width: 100%;
|
81 |
}
|
82 |
|
121 |
color: #F05A19;
|
122 |
cursor: pointer;
|
123 |
}
|
124 |
+
|
125 |
.review-form .ajaxload,
|
126 |
+
.review-form .message {
|
127 |
display: none;
|
128 |
}
|
129 |
+
|
130 |
.course-review-wrapper.submitting .ajaxload,
|
131 |
+
.course-review-wrapper.error .message {
|
132 |
display: inline-block;
|
133 |
}
|
134 |
+
|
135 |
+
.review-stars-rated {
|
136 |
+
width: 90px;
|
137 |
position: relative;
|
138 |
+
display: inline-block;
|
139 |
}
|
140 |
+
|
141 |
.review-stars-rated .review-stars.empty,
|
142 |
.review-stars-rated .review-stars.filled {
|
143 |
width: 120px;
|
144 |
height: 24px;
|
145 |
font-family: dashicons;
|
146 |
+
font-size: 18px;
|
147 |
+
color: #f2b827;
|
148 |
}
|
149 |
+
|
150 |
+
.review-stars-rated .review-stars.empty:before {
|
151 |
content: '\f154\f154\f154\f154\f154';
|
152 |
line-height: 1;
|
153 |
vertical-align: top;
|
154 |
}
|
155 |
+
|
156 |
+
.review-stars-rated .review-stars.filled:before {
|
157 |
content: '\f155\f155\f155\f155\f155';
|
158 |
line-height: 1;
|
159 |
vertical-align: top;
|
160 |
}
|
161 |
+
|
162 |
+
.review-stars-rated .review-stars.filled {
|
163 |
position: absolute;
|
164 |
+
top: 0;
|
165 |
left: 0;
|
166 |
+
}
|
167 |
+
|
168 |
+
.course-rate {
|
169 |
+
overflow: hidden;
|
170 |
+
margin: 10px 0;
|
171 |
+
}
|
172 |
+
|
173 |
+
.course-rate .review-bar {
|
174 |
+
width: calc(100% - 125px);
|
175 |
+
margin-right: 5px;
|
176 |
+
height: 15px;
|
177 |
+
background: #DDD;
|
178 |
+
display: inline-block;
|
179 |
+
}
|
180 |
+
|
181 |
+
.course-rate .review-bar .rating {
|
182 |
+
background: #95e6f9;
|
183 |
+
height: 15px;
|
184 |
+
}
|
185 |
+
|
186 |
+
.course-rate .review-number {
|
187 |
+
margin-bottom: 0;
|
188 |
+
}
|
189 |
+
|
190 |
+
.course-reviews-list {
|
191 |
+
list-style: none;
|
192 |
+
margin: 0;
|
193 |
+
}
|
194 |
+
|
195 |
+
.course-reviews-list li {
|
196 |
+
margin-bottom: 20px;
|
197 |
+
padding: 20px;
|
198 |
+
background-color: #fafafa;
|
199 |
+
border: 1px solid #ddd;
|
200 |
+
overflow: hidden;
|
201 |
+
}
|
202 |
+
|
203 |
+
.course-reviews-list li .review-author {
|
204 |
+
width: 80px;
|
205 |
+
float: left;
|
206 |
+
margin-right: 20px;
|
207 |
+
}
|
208 |
+
|
209 |
+
.course-reviews-list li .review-text {
|
210 |
+
width: -webkit-calc(100% - 100px);
|
211 |
+
float: left;
|
212 |
+
}
|
213 |
+
|
214 |
+
.course-reviews-list li .user-name {
|
215 |
+
margin: 5px;
|
216 |
+
}
|
217 |
+
|
218 |
+
.course-reviews-list li .review-title {
|
219 |
+
clear: both;
|
220 |
+
font-size: 14px;
|
221 |
+
font-style: italic;
|
222 |
+
font-weight: 700;
|
223 |
+
line-height: 25px;
|
224 |
+
margin: 9px 0 15px;
|
225 |
}
|
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 =
|
96 |
if (response.result == 'success') {
|
97 |
closeForm();
|
98 |
-
|
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 =
|
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');
|
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
|
47 |
-
INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key
|
48 |
-
WHERE p.ID
|
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 |
-
|
71 |
-
$
|
72 |
-
|
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 |
-
|
|
|
|
|
|
|
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 ( !$
|
125 |
|
126 |
$comment = false;
|
127 |
global $wpdb;
|
@@ -159,8 +171,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
|
163 |
-
if( !$user_review ) {
|
164 |
$user = get_user_by( 'id', $user_id );
|
165 |
$comment_id = wp_new_comment(
|
166 |
array(
|
@@ -185,7 +197,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,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
}
|
190 |
|
191 |
/*
|
@@ -221,6 +256,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;
|
171 |
$user_id = $args['user_id'];
|
172 |
$course_id = $args['course_id'];
|
173 |
$user_review = learn_press_get_user_rate( $course_id, $user_id );
|
174 |
+
$comment_id = 0;
|
175 |
+
if ( !$user_review ) {
|
176 |
$user = get_user_by( 'id', $user_id );
|
177 |
$comment_id = wp_new_comment(
|
178 |
array(
|
197 |
}
|
198 |
|
199 |
function learn_press_course_review_template( $name, $args = null ) {
|
200 |
+
learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
|
201 |
+
}
|
202 |
+
|
203 |
+
/*
|
204 |
+
add_action( 'learn_press_after_courses_loop_item', function () {
|
205 |
+
global $post;
|
206 |
+
echo "[", learn_press_get_course_rate_total( $post->ID ), "]";
|
207 |
+
} );*/
|
208 |
+
|
209 |
+
/*
|
210 |
+
* If we are viewing archive course page, so load all ratings of courses
|
211 |
+
* into cache to reduce queries and time rather than load separate course
|
212 |
+
* in loop
|
213 |
+
*/
|
214 |
+
add_filter( 'the_posts', 'learn_press_init_courses_review' );
|
215 |
+
function learn_press_init_courses_review( $posts ) {
|
216 |
+
if ( $posts ) {
|
217 |
+
$pIds = array();
|
218 |
+
foreach ( $posts as $p ) {
|
219 |
+
$pIds[] = $p->ID;
|
220 |
+
}
|
221 |
+
_learn_press_get_ratings( $pIds );
|
222 |
+
}
|
223 |
+
return $posts;
|
224 |
}
|
225 |
|
226 |
/*
|
256 |
/**
|
257 |
* Print rate for course
|
258 |
*/
|
259 |
+
function leanr_press_get_ratings_result( $course_id = '', $get_items = false ) {
|
260 |
+
global $wpdb;
|
261 |
+
$query = $wpdb->prepare( "
|
262 |
+
SELECT
|
263 |
+
COUNT(*) `count` ,AVG(cm.meta_value) `avg`
|
264 |
+
FROM
|
265 |
+
{$wpdb->comments} c
|
266 |
+
INNER JOIN
|
267 |
+
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key='_lpr_rating'
|
268 |
+
WHERE
|
269 |
+
c.comment_approved = 1
|
270 |
+
AND c.comment_type = 'review'
|
271 |
+
AND c.user_id > 0
|
272 |
+
AND c.comment_post_ID =%d "
|
273 |
+
, $course_id );
|
274 |
+
$row = $wpdb->get_row( $query );
|
275 |
+
|
276 |
+
$count = 0;
|
277 |
+
$avg = 0;
|
278 |
+
if ( $row ) {
|
279 |
+
$count = $row->count;
|
280 |
+
$avg = $row->avg;
|
281 |
+
}
|
282 |
|
283 |
+
$rows = array();
|
284 |
+
if ( $count != 0 ):
|
285 |
+
$query = $wpdb->prepare( "
|
286 |
+
SELECT
|
287 |
+
cm.meta_value `rate`, COUNT(*) `count`
|
288 |
+
FROM
|
289 |
+
{$wpdb->comments} c
|
290 |
+
INNER JOIN
|
291 |
+
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key='_lpr_rating'
|
292 |
+
WHERE
|
293 |
+
c.comment_approved = 1
|
294 |
+
AND c.comment_type = 'review'
|
295 |
+
AND c.user_id > 0
|
296 |
+
AND c.comment_post_ID =%d
|
297 |
+
GROUP BY `cm`.`meta_value`
|
298 |
+
ORDER BY `cm`.`meta_value` DESC
|
299 |
+
"
|
300 |
+
, $course_id );
|
301 |
+
$rows = $wpdb->get_results( $query, OBJECT_K );
|
302 |
+
endif;
|
303 |
|
304 |
+
$items = array();
|
305 |
+
for ( $i = 5; $i > 0; $i -- ) {
|
306 |
+
if ( isset( $rows[$i] ) ) {
|
307 |
+
$items[] = array(
|
308 |
+
'rated' => $rows[$i]->rate
|
309 |
+
, 'total' => $rows[$i]->count
|
310 |
+
, 'percent' => $rows[$i]->count / $count * 100
|
311 |
+
);
|
312 |
+
} else {
|
313 |
+
$items[] = array(
|
314 |
+
'rated' => $i
|
315 |
+
, 'total' => 0
|
316 |
+
, 'percent' => 0
|
317 |
+
);
|
318 |
+
}
|
319 |
+
}
|
320 |
+
$result = array(
|
321 |
+
'course_id' => $course_id
|
322 |
+
, 'total' => $count
|
323 |
+
, 'rated' => $avg
|
324 |
+
, 'items' => $items
|
325 |
+
);
|
326 |
|
327 |
+
return $result;
|
328 |
+
}
|
incs/review-widgets.php
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Reviews functions
|
4 |
+
*/
|
5 |
+
|
6 |
+
if ( !defined( 'ABSPATH' ) ) {
|
7 |
+
exit; // Exit if accessed directly
|
8 |
+
}
|
9 |
+
// Creating the widget
|
10 |
+
class LearnPress_Course_Review_Widget extends WP_Widget {
|
11 |
+
|
12 |
+
function __construct() {
|
13 |
+
parent::__construct(
|
14 |
+
'lpr_course_review',
|
15 |
+
__( 'Course Review', 'learnpress-course-review' ),
|
16 |
+
array('description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ),)
|
17 |
+
);
|
18 |
+
}
|
19 |
+
|
20 |
+
|
21 |
+
public function widget( $args, $instance ) {
|
22 |
+
$title = apply_filters( 'widget_title', $instance['title'] );
|
23 |
+
echo $args['before_widget'];
|
24 |
+
|
25 |
+
if ( !empty( $title ) ) {
|
26 |
+
echo $args['before_title'] . $title . $args['after_title'];
|
27 |
+
}
|
28 |
+
|
29 |
+
$course_id = isset($instance['course_id'] ) ? $instance['course_id'] : 0;
|
30 |
+
$show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
|
31 |
+
$show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
|
32 |
+
|
33 |
+
if( !$course_id ) {
|
34 |
+
$course_id = get_the_ID();
|
35 |
+
}
|
36 |
+
|
37 |
+
ob_start();
|
38 |
+
if( $show_rate == 'yes' ) {
|
39 |
+
$course_rate = learn_press_get_course_rate( $course_id, false );
|
40 |
+
$rate_args = array(
|
41 |
+
'course_id' => $course_id
|
42 |
+
, 'course_rate' => $course_rate
|
43 |
+
);
|
44 |
+
learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
|
45 |
+
}
|
46 |
+
|
47 |
+
if( $show_review == 'yes' ){
|
48 |
+
$course_review = learn_press_get_course_review( $course_id );
|
49 |
+
learn_press_course_review_template( 'shortcode-course-review.php', array('course_id'=>$course_id, 'course_review'=>$course_review) );
|
50 |
+
}
|
51 |
+
|
52 |
+
$content = ob_get_contents();
|
53 |
+
ob_clean();
|
54 |
+
echo $content;
|
55 |
+
echo $args['after_widget'];
|
56 |
+
}
|
57 |
+
|
58 |
+
public function form( $instance ) {
|
59 |
+
$title = isset( $instance['title'] )?$instance['title']:__( 'New title', 'wpb_widget_domain' );
|
60 |
+
$course_id = isset($instance['course_id'])?$instance['course_id']:'';
|
61 |
+
$show_rate = isset($instance['show_rate'])?$instance['show_rate']:'no';
|
62 |
+
$show_review = isset($instance['show_review'])?$instance['show_review']:'no';
|
63 |
+
?>
|
64 |
+
<p>
|
65 |
+
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
|
66 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
67 |
+
</p>
|
68 |
+
<p>
|
69 |
+
<label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:' ); ?></label>
|
70 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'course_id' ); ?>" name="<?php echo $this->get_field_name( 'course_id' ); ?>" type="text" value="<?php echo esc_attr( $course_id ); ?>" />
|
71 |
+
</p>
|
72 |
+
<p>
|
73 |
+
<label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:' ); ?></label>
|
74 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>" name="<?php echo $this->get_field_name( 'show_rate' ); ?>" type="checkbox" value="yes" <?php checked( $show_rate, 'yes', true); ?>/>
|
75 |
+
</p>
|
76 |
+
<p>
|
77 |
+
<label for="<?php echo $this->get_field_id( 'show_review' ); ?>"><?php _e( 'Show Review:' ); ?></label>
|
78 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'show_review' ); ?>" name="<?php echo $this->get_field_name( 'show_review' ); ?>" type="checkbox" value="yes" <?php checked( $show_review, 'yes', true); ?> />
|
79 |
+
</p>
|
80 |
+
<?php
|
81 |
+
}
|
82 |
+
|
83 |
+
// Updating widget replacing old instances with new
|
84 |
+
public function update( $new_instance, $old_instance ) {
|
85 |
+
$instance = array();
|
86 |
+
var_dump($new_instance);
|
87 |
+
$instance['title'] = (!empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
88 |
+
$instance['course_id'] = (!empty( $new_instance['course_id'] ) ) ? strip_tags( $new_instance['course_id'] ) : '';
|
89 |
+
$instance['show_rate'] = (!empty( $new_instance['show_rate'] ) ) ? strip_tags( $new_instance['show_rate'] ) : '';
|
90 |
+
$instance['show_review'] = (!empty( $new_instance['show_review'] ) ) ? strip_tags( $new_instance['show_review'] ) : '';
|
91 |
+
var_dump($instance);
|
92 |
+
return $instance;
|
93 |
+
}
|
94 |
+
|
95 |
+
}
|
96 |
+
|
97 |
+
// Class wpb_widget ends here
|
98 |
+
// Register and load the widget
|
99 |
+
|
languages/learnpress-course-review.pot
CHANGED
@@ -1,95 +1,95 @@
|
|
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 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 ""
|
learnpress-course-review.php
CHANGED
@@ -1,10 +1,10 @@
|
|
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:
|
8 |
Author URI: http://thimpress.com
|
9 |
Tags: learnpress
|
10 |
Text Domain: learnpress-course-review
|
@@ -17,7 +17,8 @@ if ( !defined( 'ABSPATH' ) ) {
|
|
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
|
@@ -28,6 +29,12 @@ class LP_Addon_Course_Review {
|
|
28 |
*/
|
29 |
protected static $_instance = null;
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
/**
|
32 |
* LP_Addon_Course_Review constructor.
|
33 |
*/
|
@@ -43,21 +50,31 @@ class LP_Addon_Course_Review {
|
|
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 |
-
|
47 |
-
|
48 |
-
add_action( '
|
49 |
-
add_action( 'learn_press_content_learning_summary', array( $this, '
|
|
|
|
|
|
|
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 |
|
@@ -75,6 +92,10 @@ class LP_Addon_Course_Review {
|
|
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 );
|
@@ -93,6 +114,7 @@ class LP_Addon_Course_Review {
|
|
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 |
}
|
@@ -101,11 +123,10 @@ class LP_Addon_Course_Review {
|
|
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['
|
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'] : '';
|
@@ -133,10 +154,124 @@ class LP_Addon_Course_Review {
|
|
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 |
|
@@ -148,10 +283,11 @@ class LP_Addon_Course_Review {
|
|
148 |
* Load text domain
|
149 |
*/
|
150 |
static function load_text_domain() {
|
151 |
-
if( function_exists('learn_press_load_plugin_text_domain')
|
|
|
|
|
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.0
|
8 |
Author URI: http://thimpress.com
|
9 |
Tags: learnpress
|
10 |
Text Domain: learnpress-course-review
|
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 |
+
define( 'LP_ADDON_COURSE_REVIEW_VER', '2.0' );
|
21 |
+
define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '2.0' );
|
22 |
|
23 |
/**
|
24 |
* Class LP_Addon_Course_Review
|
29 |
*/
|
30 |
protected static $_instance = null;
|
31 |
|
32 |
+
/**
|
33 |
+
* @var null
|
34 |
+
*/
|
35 |
+
|
36 |
+
private static $comment_type = 'review';
|
37 |
+
|
38 |
/**
|
39 |
* LP_Addon_Course_Review constructor.
|
40 |
*/
|
50 |
define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
|
51 |
define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
|
52 |
|
53 |
+
add_filter( 'learn_press_course_tabs', array( $this, 'add_course_tab_reviews' ), 5 );
|
54 |
+
|
55 |
+
// add_action( 'learn_press_content_landing_summary', array( $this, 'print_rate' ), 75, 1 );
|
56 |
+
// add_action( 'learn_press_content_learning_summary', array( $this, 'print_rate' ), 75, 1 );
|
57 |
+
// add_action( 'learn_press_content_landing_summary', array( $this, 'print_review' ), 80 );
|
58 |
+
// add_action( 'learn_press_content_learning_summary', array( $this, 'print_review' ), 80 );
|
59 |
+
// add_action( 'learn_press_content_learning_summary', array( $this, 'add_review_button' ), 5 );
|
60 |
add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
|
61 |
add_action( 'wp', array( $this, 'course_review_init' ) );
|
62 |
//add_action( 'parse_comment_query', array( $this, 'exclude_rating' ) );
|
63 |
|
64 |
add_action( 'init', array( $this, 'load_text_domain' ) );
|
65 |
|
66 |
+
//add_action('restrict_manage_comments', array($this, 'add_comment_post_type_filter'));
|
67 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
|
68 |
|
69 |
require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-functions.php';
|
70 |
+
require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-widgets.php';
|
71 |
|
72 |
LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
|
73 |
|
74 |
+
$this->init_comment_table();
|
75 |
+
|
76 |
+
add_shortcode( 'learnpress-course-review', array( $this, 'shortcode_review' ) );
|
77 |
+
add_action( 'widgets_init', array( $this, 'load_widget' ) );
|
78 |
self::$_instance = $this;
|
79 |
}
|
80 |
|
92 |
}
|
93 |
}
|
94 |
|
95 |
+
function admin_enqueue_assets() {
|
96 |
+
wp_enqueue_style( 'ourse-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/admin.css' );
|
97 |
+
}
|
98 |
+
|
99 |
function review_assets() {
|
100 |
if ( learn_press_is_course() ) {
|
101 |
wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.js', array( 'jquery' ), '', true );
|
114 |
}
|
115 |
|
116 |
function course_review_init() {
|
117 |
+
|
118 |
$paged = !empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
|
119 |
learn_press_get_course_review( get_the_ID(), $paged );
|
120 |
}
|
123 |
$query->query_vars['type__not_in'] = 'review';
|
124 |
}
|
125 |
|
|
|
126 |
function add_review() {
|
127 |
$response = array( 'result' => 'success' );
|
128 |
$nonce = !empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
|
129 |
+
$id = !empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
|
130 |
$rate = !empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
|
131 |
$title = !empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
|
132 |
$content = !empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
|
154 |
learn_press_send_json( $response );
|
155 |
}
|
156 |
|
157 |
+
function init_comment_table() {
|
158 |
+
add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
|
159 |
+
add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
|
160 |
+
}
|
161 |
+
|
162 |
+
function add_comment_type_filter( $cmt_types ) {
|
163 |
+
$cmt_types[self::$comment_type] = __( 'Course review', 'earnpress-course-review' );
|
164 |
+
return $cmt_types;
|
165 |
+
}
|
166 |
+
|
167 |
+
function add_comment_content_filter( $cmt_text ) {
|
168 |
+
global $comment;
|
169 |
+
if ( !$comment || $comment->comment_type != 'review' ) return $cmt_text;
|
170 |
+
|
171 |
+
ob_start();
|
172 |
+
$rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
|
173 |
+
echo '<div class="course-rate">';
|
174 |
+
learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
|
175 |
+
echo '</div>';
|
176 |
+
$cmt_text .= ob_get_clean();
|
177 |
+
return $cmt_text;
|
178 |
+
}
|
179 |
+
|
180 |
+
function add_comment_post_type_filter() {
|
181 |
+
?>
|
182 |
+
<label class="screen-reader-text" for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
|
183 |
+
<select id="filter-by-comment-post-type" name="post_type">
|
184 |
+
<?php
|
185 |
+
$comment_post_types = apply_filters( 'learn_press_admin_comment_post_type_types_dropdown', array(
|
186 |
+
'' => __( 'All post type' ),
|
187 |
+
'lp_course' => __( 'Course comments' ),
|
188 |
+
) );
|
189 |
+
|
190 |
+
foreach ( $comment_post_types as $type => $label ) {
|
191 |
+
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
|
192 |
+
}
|
193 |
+
|
194 |
+
?>
|
195 |
+
|
196 |
+
</select>
|
197 |
+
<?php
|
198 |
+
}
|
199 |
+
|
200 |
+
|
201 |
+
function shortcode_review( $atts ) {
|
202 |
+
|
203 |
+
$atts = shortcode_atts( array(
|
204 |
+
'course_id' => 0,
|
205 |
+
'show_rate' => 'yes',
|
206 |
+
'show_review' => 'yes'
|
207 |
+
), $atts, 'shortcode_review' );
|
208 |
+
|
209 |
+
$course_id = $atts['course_id'];
|
210 |
+
if ( !$course_id ) {
|
211 |
+
$course_id = get_the_ID();
|
212 |
+
}
|
213 |
+
|
214 |
+
ob_start();
|
215 |
+
if ( $atts['show_rate'] ) {
|
216 |
+
$course_rate = learn_press_get_course_rate( $course_id, false );
|
217 |
+
$total = learn_press_get_course_rate_total( $course_id, false );
|
218 |
+
$rate_args = array(
|
219 |
+
'course_id' => $course_id
|
220 |
+
, 'course_rate' => $course_rate
|
221 |
+
, 'total' => $total
|
222 |
+
);
|
223 |
+
learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
|
224 |
+
}
|
225 |
+
|
226 |
+
if ( $atts['show_review'] ) {
|
227 |
+
$course_review = learn_press_get_course_review( $course_id );
|
228 |
+
learn_press_course_review_template( 'shortcode-course-review.php', array( 'course_id' => $course_id, 'course_review' => $course_review ) );
|
229 |
+
}
|
230 |
+
|
231 |
+
$content = ob_get_contents();
|
232 |
+
ob_clean();
|
233 |
+
return $content;
|
234 |
+
}
|
235 |
+
|
236 |
+
function load_widget() {
|
237 |
+
register_widget( 'LearnPress_Course_Review_Widget' );
|
238 |
+
}
|
239 |
+
|
240 |
+
|
241 |
+
public function add_course_tab_reviews( $tabs ) {
|
242 |
+
$tabs['reviews'] = array(
|
243 |
+
'title' => __( 'Reviews', 'learnpres-course-review' )
|
244 |
+
, 'priority' => 0
|
245 |
+
, 'callback' => array( $this, 'add_course_tab_reviews_callback' )
|
246 |
+
);
|
247 |
+
|
248 |
+
return $tabs;
|
249 |
+
}
|
250 |
+
|
251 |
+
public function add_course_tab_reviews_callback() {
|
252 |
+
$course_id = learn_press_get_course_id();
|
253 |
+
$this->print_rate();
|
254 |
+
$this->print_review();
|
255 |
+
$this->add_review_button();
|
256 |
+
}
|
257 |
+
|
258 |
+
public static function admin_notice() {
|
259 |
+
?>
|
260 |
+
<div class="error">
|
261 |
+
<p><?php printf( __( '<strong>Course Review</strong> addon version %s requires LearnPress version %s or higher', 'learnpress-course-review' ), LP_ADDON_COURSE_REVIEW_VER, LP_ADDON_COURSE_REVIEW_REQUIRE_VER ); ?></p>
|
262 |
+
</div>
|
263 |
+
<?php
|
264 |
+
}
|
265 |
+
|
266 |
/**
|
267 |
* Return unique instance of LP_Addon_Course_Review object
|
268 |
*/
|
269 |
static function instance() {
|
270 |
+
if ( !defined( 'LEARNPRESS_VERSION' ) || ( version_compare( LEARNPRESS_VERSION, LP_ADDON_COURSE_REVIEW_REQUIRE_VER, '<' ) ) ) {
|
271 |
+
add_action( 'admin_notices', array( __CLASS__, 'admin_notice' ) );
|
272 |
+
return false;
|
273 |
+
}
|
274 |
+
|
275 |
if ( !self::$_instance ) {
|
276 |
self::$_instance = new self();
|
277 |
|
283 |
* Load text domain
|
284 |
*/
|
285 |
static function load_text_domain() {
|
286 |
+
if ( function_exists( 'learn_press_load_plugin_text_domain' ) ) {
|
287 |
+
learn_press_load_plugin_text_domain( LP_ADDON_COURSE_REVIEW_PATH, true );
|
288 |
+
}
|
289 |
}
|
|
|
|
|
|
|
290 |
|
291 |
+
}
|
292 |
|
293 |
+
add_action( 'learn_press_loaded', array( 'LP_Addon_Course_Review', 'instance' ) );
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
===
|
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.
|
7 |
-
Stable tag:
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -49,7 +49,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 +57,12 @@ 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
|
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.6.1
|
7 |
+
Stable tag: 2.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
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 |
|
58 |
1. LearnPress Course Review screenshot.
|
59 |
|
60 |
+
== Changelog ==
|
61 |
+
|
62 |
+
= 2.1 =
|
63 |
+
|
64 |
+
= 2.0 =
|
65 |
+
+ Updated to be compatible with LearnPress 2.0
|
66 |
|
67 |
= 1.1 =
|
68 |
+ Fixed comments do not show in admin
|
templates/course-rate.php
CHANGED
@@ -1,20 +1,43 @@
|
|
1 |
-
<?php
|
2 |
if ( !defined( 'ABSPATH' ) ) {
|
3 |
-
|
4 |
}
|
5 |
|
6 |
-
$course_id
|
7 |
-
$
|
8 |
-
$
|
|
|
|
|
9 |
?>
|
10 |
<div class="course-rate">
|
11 |
-
<?php
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 base 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 |
-
$
|
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,23 @@
|
|
1 |
<li>
|
2 |
-
<
|
3 |
-
<?php
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
<?php
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
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-text">
|
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 class="review-content">
|
18 |
+
<?php do_action( 'learn_press_before_review_content' );?>
|
19 |
+
<?php echo $review->content ?>
|
20 |
+
<?php do_action( 'learn_press_after_review_content' );?>
|
21 |
+
</div>
|
22 |
</div>
|
23 |
</li>
|
templates/rating-stars.php
CHANGED
@@ -1,4 +1,5 @@
|
|
|
|
1 |
<div class="review-stars-rated">
|
2 |
-
|
3 |
-
|
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="
|
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 |
+
}
|