LearnPress – Course Review - Version 3.0.5

Version Description

~ Fixed an issue when checking if the user rated or not!

Download this release

Release Info

Developer phamtungpth
Plugin Icon 128x128 LearnPress – Course Review
Version 3.0.5
Comparing to
See all releases

Code changes from version 3.0.4 to 3.0.5

assets/css/admin.css CHANGED
@@ -1,51 +1,51 @@
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
- }
49
- .select2-container {
50
- width: 140px !important;
51
  }
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
+ }
49
+ .select2-container {
50
+ width: 140px !important;
51
  }
assets/css/course-review.css CHANGED
@@ -1,266 +1,266 @@
1
- @charset "UTF-8";
2
- .course-review-wrapper {
3
- display: none;
4
- position: fixed;
5
- top: 0;
6
- left: 0;
7
- right: 0;
8
- bottom: 0;
9
- z-index: 99999;
10
- text-align: center;
11
- }
12
-
13
- .review-overlay {
14
- background: #000;
15
- bottom: 0;
16
- left: 0;
17
- position: fixed;
18
- top: 0;
19
- width: 100%;
20
- opacity: 0.6;
21
- }
22
-
23
- .review-form {
24
- background-color: rgb(255, 255, 255);
25
- padding: 20px;
26
- position: relative;
27
- width: 80%;
28
- max-width: 600px;
29
- margin-top: 50px;
30
- display: inline-block;
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;
41
- }
42
-
43
- .review-form h3 .close {
44
- float: right;
45
- border: none;
46
- text-decoration: none;
47
- width: auto;
48
- height: auto;
49
- margin-right: -9px;
50
- margin-top: -7px;
51
- }
52
-
53
- .review-form h3 .close:before {
54
- font-size: 32px;
55
- }
56
-
57
- .review-form .review-fields {
58
- margin: 0 0 -20px;
59
- list-style: none;
60
- }
61
-
62
- .review-form .review-fields > li {
63
- margin: 0 0 20px 0;
64
- }
65
-
66
- .review-form .review-fields > li > label {
67
- display: block;
68
- margin: 0 0 7px;
69
- font-size: 15px;
70
- }
71
-
72
- .review-form .review-fields > li > label .required {
73
- margin-left: 5px;
74
- display: inline-block;
75
- vertical-align: middle;
76
- font-size: 24px;
77
- line-height: 1;
78
- height: 15px;
79
- margin-top: -3px;
80
- }
81
-
82
- .review-form .review-fields > li input[type="text"],
83
- .review-form .review-fields > li textarea {
84
- width: 100%;
85
- }
86
-
87
- .review-stars {
88
- margin: 0 0;
89
- list-style: none;
90
- overflow: hidden;
91
- }
92
-
93
- .review-stars:after {
94
- clear: both;
95
- content: '';
96
- display: block;
97
- }
98
-
99
- .review-stars > li {
100
- width: 24px;
101
- height: 24px;
102
- float: left;
103
- }
104
-
105
- .review-stars > li span {
106
- text-decoration: none;
107
- font-size: 24px;
108
- border-bottom: none;
109
- width: auto;
110
- height: auto;
111
- }
112
-
113
- .review-stars > li a:visited,
114
- .review-stars > li a:focus {
115
- border: none;
116
- }
117
-
118
- .review-stars > li span:before {
119
- width: 22px;
120
- height: 24px;
121
- }
122
-
123
- .review-stars > li span.hover:before {
124
- content: "\f155";
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
- .course-review-wrapper.submitting .ajaxload {
140
- position: absolute;
141
- top: 48%;
142
- left: 48%;
143
- }
144
-
145
- .course-review-wrapper.submitting .review-form {
146
- position: relative;
147
- }
148
-
149
- .course-review-wrapper.submitting .review-form .form-overlay-review {
150
- background: #000;
151
- bottom: 0;
152
- left: 0;
153
- position: absolute;
154
- top: 0;
155
- width: 100%;
156
- opacity: 0.3;
157
- }
158
-
159
- .review-stars-rated {
160
- width: 90px;
161
- position: relative;
162
- display: inline-block;
163
- }
164
-
165
- .review-stars-rated .review-stars.empty,
166
- .review-stars-rated .review-stars.filled {
167
- width: 120px;
168
- height: 24px;
169
- font-family: dashicons;
170
- font-size: 18px;
171
- color: #f2b827;
172
- }
173
-
174
- .review-stars-rated .review-stars.empty:before {
175
- content: '\f154\f154\f154\f154\f154';
176
- line-height: 1;
177
- vertical-align: top;
178
- white-space: nowrap;
179
- }
180
-
181
- .review-stars-rated .review-stars.filled:before {
182
- content: '\f155\f155\f155\f155\f155';
183
- line-height: 1;
184
- vertical-align: top;
185
- white-space: nowrap;
186
- }
187
-
188
- .review-stars-rated .review-stars.filled {
189
- position: absolute;
190
- top: 0;
191
- left: 0;
192
- }
193
-
194
- .course-rate {
195
- overflow: hidden;
196
- margin: 10px 0;
197
- }
198
-
199
- .course-rate .review-bar {
200
- width: calc(100% - 125px);
201
- margin-right: 5px;
202
- height: 15px;
203
- background: #DDD;
204
- display: inline-block;
205
- }
206
-
207
- .course-rate .review-bar .rating {
208
- background: #95e6f9;
209
- height: 15px;
210
- }
211
-
212
- .course-rate .review-number {
213
- margin-bottom: 0;
214
- }
215
-
216
- .course-reviews-list, .course-reviews-list-shortcode {
217
- list-style: none;
218
- margin: 0;
219
- }
220
-
221
- .course-reviews-list li, .course-reviews-list-shortcode li {
222
- margin-bottom: 20px;
223
- padding: 20px;
224
- background-color: #fafafa;
225
- border: 1px solid #ddd;
226
- overflow: hidden;
227
- }
228
-
229
- .course-reviews-list li .review-author, .course-reviews-list-shortcode li .review-author {
230
- width: 80px;
231
- float: left;
232
- margin-right: 20px;
233
- }
234
-
235
- .course-reviews-list li .review-author-info .course-reviews-list-shortcode li .review-author-info {
236
- float: left;
237
- }
238
-
239
- .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
240
- width: -webkit-calc(100% - 100px);
241
- float: right;
242
- }
243
-
244
- .course-reviews-list li .user-name, .course-reviews-list-shortcode li .user-name {
245
- margin: 5px;
246
- }
247
-
248
- .course-reviews-list li .review-title, .course-reviews-list-shortcode li .review-title {
249
- clear: both;
250
- font-size: 14px;
251
- font-style: italic;
252
- font-weight: 700;
253
- line-height: 25px;
254
- margin: 9px 0 15px;
255
- }
256
-
257
- @media (max-width: 600px) {
258
- .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
259
- width: 100%;
260
- float: left;
261
- }
262
- }
263
-
264
- .loading {
265
- display: none;
266
  }
1
+ @charset "UTF-8";
2
+ .course-review-wrapper {
3
+ display: none;
4
+ position: fixed;
5
+ top: 0;
6
+ left: 0;
7
+ right: 0;
8
+ bottom: 0;
9
+ z-index: 99999;
10
+ text-align: center;
11
+ }
12
+
13
+ .review-overlay {
14
+ background: #000;
15
+ bottom: 0;
16
+ left: 0;
17
+ position: fixed;
18
+ top: 0;
19
+ width: 100%;
20
+ opacity: 0.6;
21
+ }
22
+
23
+ .review-form {
24
+ background-color: rgb(255, 255, 255);
25
+ padding: 20px;
26
+ position: relative;
27
+ width: 80%;
28
+ max-width: 600px;
29
+ margin-top: 50px;
30
+ display: inline-block;
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;
41
+ }
42
+
43
+ .review-form h3 .close {
44
+ float: right;
45
+ border: none;
46
+ text-decoration: none;
47
+ width: auto;
48
+ height: auto;
49
+ margin-right: -9px;
50
+ margin-top: -7px;
51
+ }
52
+
53
+ .review-form h3 .close:before {
54
+ font-size: 32px;
55
+ }
56
+
57
+ .review-form .review-fields {
58
+ margin: 0 0 -20px;
59
+ list-style: none;
60
+ }
61
+
62
+ .review-form .review-fields > li {
63
+ margin: 0 0 20px 0;
64
+ }
65
+
66
+ .review-form .review-fields > li > label {
67
+ display: block;
68
+ margin: 0 0 7px;
69
+ font-size: 15px;
70
+ }
71
+
72
+ .review-form .review-fields > li > label .required {
73
+ margin-left: 5px;
74
+ display: inline-block;
75
+ vertical-align: middle;
76
+ font-size: 24px;
77
+ line-height: 1;
78
+ height: 15px;
79
+ margin-top: -3px;
80
+ }
81
+
82
+ .review-form .review-fields > li input[type="text"],
83
+ .review-form .review-fields > li textarea {
84
+ width: 100%;
85
+ }
86
+
87
+ .review-stars {
88
+ margin: 0 0;
89
+ list-style: none;
90
+ overflow: hidden;
91
+ }
92
+
93
+ .review-stars:after {
94
+ clear: both;
95
+ content: '';
96
+ display: block;
97
+ }
98
+
99
+ .review-stars > li {
100
+ width: 24px;
101
+ height: 24px;
102
+ float: left;
103
+ }
104
+
105
+ .review-stars > li span {
106
+ text-decoration: none;
107
+ font-size: 24px;
108
+ border-bottom: none;
109
+ width: auto;
110
+ height: auto;
111
+ }
112
+
113
+ .review-stars > li a:visited,
114
+ .review-stars > li a:focus {
115
+ border: none;
116
+ }
117
+
118
+ .review-stars > li span:before {
119
+ width: 22px;
120
+ height: 24px;
121
+ }
122
+
123
+ .review-stars > li span.hover:before {
124
+ content: "\f155";
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
+ .course-review-wrapper.submitting .ajaxload {
140
+ position: absolute;
141
+ top: 48%;
142
+ left: 48%;
143
+ }
144
+
145
+ .course-review-wrapper.submitting .review-form {
146
+ position: relative;
147
+ }
148
+
149
+ .course-review-wrapper.submitting .review-form .form-overlay-review {
150
+ background: #000;
151
+ bottom: 0;
152
+ left: 0;
153
+ position: absolute;
154
+ top: 0;
155
+ width: 100%;
156
+ opacity: 0.3;
157
+ }
158
+
159
+ .review-stars-rated {
160
+ width: 90px;
161
+ position: relative;
162
+ display: inline-block;
163
+ }
164
+
165
+ .review-stars-rated .review-stars.empty,
166
+ .review-stars-rated .review-stars.filled {
167
+ width: 120px;
168
+ height: 24px;
169
+ font-family: dashicons;
170
+ font-size: 18px;
171
+ color: #f2b827;
172
+ }
173
+
174
+ .review-stars-rated .review-stars.empty:before {
175
+ content: '\f154\f154\f154\f154\f154';
176
+ line-height: 1;
177
+ vertical-align: top;
178
+ white-space: nowrap;
179
+ }
180
+
181
+ .review-stars-rated .review-stars.filled:before {
182
+ content: '\f155\f155\f155\f155\f155';
183
+ line-height: 1;
184
+ vertical-align: top;
185
+ white-space: nowrap;
186
+ }
187
+
188
+ .review-stars-rated .review-stars.filled {
189
+ position: absolute;
190
+ top: 0;
191
+ left: 0;
192
+ }
193
+
194
+ .course-rate {
195
+ overflow: hidden;
196
+ margin: 10px 0;
197
+ }
198
+
199
+ .course-rate .review-bar {
200
+ width: calc(100% - 125px);
201
+ margin-right: 5px;
202
+ height: 15px;
203
+ background: #DDD;
204
+ display: inline-block;
205
+ }
206
+
207
+ .course-rate .review-bar .rating {
208
+ background: #95e6f9;
209
+ height: 15px;
210
+ }
211
+
212
+ .course-rate .review-number {
213
+ margin-bottom: 0;
214
+ }
215
+
216
+ .course-reviews-list, .course-reviews-list-shortcode {
217
+ list-style: none;
218
+ margin: 0;
219
+ }
220
+
221
+ .course-reviews-list li, .course-reviews-list-shortcode li {
222
+ margin-bottom: 20px;
223
+ padding: 20px;
224
+ background-color: #fafafa;
225
+ border: 1px solid #ddd;
226
+ overflow: hidden;
227
+ }
228
+
229
+ .course-reviews-list li .review-author, .course-reviews-list-shortcode li .review-author {
230
+ width: 80px;
231
+ float: left;
232
+ margin-right: 20px;
233
+ }
234
+
235
+ .course-reviews-list li .review-author-info .course-reviews-list-shortcode li .review-author-info {
236
+ float: left;
237
+ }
238
+
239
+ .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
240
+ width: -webkit-calc(100% - 100px);
241
+ float: right;
242
+ }
243
+
244
+ .course-reviews-list li .user-name, .course-reviews-list-shortcode li .user-name {
245
+ margin: 5px;
246
+ }
247
+
248
+ .course-reviews-list li .review-title, .course-reviews-list-shortcode li .review-title {
249
+ clear: both;
250
+ font-size: 14px;
251
+ font-style: italic;
252
+ font-weight: 700;
253
+ line-height: 25px;
254
+ margin: 9px 0 15px;
255
+ }
256
+
257
+ @media (max-width: 600px) {
258
+ .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
259
+ width: 100%;
260
+ float: left;
261
+ }
262
+ }
263
+
264
+ .loading {
265
+ display: none;
266
  }
assets/js/course-review.js CHANGED
@@ -1,170 +1,170 @@
1
- /**
2
- * LearnPress Course Review addon
3
- *
4
- * WARNING: This script may not work correct with LP version before 1.0
5
- *
6
- * @version 1.0
7
- */
8
- ;(function ($) {
9
- if (typeof LP == 'undefined' && typeof LearnPress != 'undefined') {
10
- window.LP = LearnPress;
11
- }
12
-
13
- function CourseReview() {
14
- var $reviewForm = $('#course-review').appendTo(document.body),
15
- $reviewBtn = $(".write-a-review"),
16
- $stars = $('.review-fields ul > li span', $reviewForm).each(function (i) {
17
- $(this).hover(function () {
18
- if (submitting) {
19
- return;
20
- }
21
- $stars.map(function (j) {
22
- $(this).toggleClass('hover', j <= i);
23
- })
24
- }, function () {
25
- if (submitting) {
26
- return;
27
- }
28
- var selected = $reviewForm.find('input[name="rating"]').val();
29
- if (selected) {
30
- $stars.map(function (j) {
31
- $(this).toggleClass('hover', j < selected);
32
- });
33
- } else {
34
- $stars.removeClass('hover')
35
- }
36
- }).click(function (e) {
37
- if (submitting) {
38
- return;
39
- }
40
- e.preventDefault();
41
- $reviewForm.find('input[name="rating"]').val($stars.index($(this)) + 1);
42
- })
43
- }),
44
- that = this,
45
- submitting = false,
46
- showForm = null,
47
- closeForm = null,
48
- addReview = null;
49
-
50
- showForm = this.showForm = function () {
51
- var _completed = function () {
52
- $('input[type="text"], textarea', this).val('');
53
- $stars.removeClass('hover');
54
- }
55
- $reviewForm.fadeIn(_completed);
56
- }
57
-
58
- closeForm = this.closeForm = function () {
59
- var _completed = function () {
60
- $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
61
- $reviewForm.removeClass('submitting').data('selected', '');
62
- $stars.removeClass('hover')
63
- }
64
- $reviewForm.find('input[name="rating"]').val('')
65
- $(document).focus();
66
- $reviewForm.fadeOut(_completed);
67
- }
68
-
69
- addReview = this.addReview = function () {
70
- var $reviewTitle = $('input[name="review_title"]', $reviewForm);
71
- var $reviewContent = $('textarea[name="review_content"]', $reviewForm);
72
- var rating = $reviewForm.find('input[name="rating"]').val();
73
- var course_id = $(this).attr('data-id');
74
-
75
- if (0 == $reviewTitle.val().length) {
76
- alert(learn_press_course_review.localize.empty_title)
77
- $reviewTitle.focus();
78
- return;
79
- }
80
-
81
- if (0 == $reviewContent.val().length) {
82
- alert(learn_press_course_review.localize.empty_content)
83
- $reviewContent.focus();
84
- return;
85
- }
86
-
87
- if (0 == rating) {
88
- alert(learn_press_course_review.localize.empty_rating)
89
- return;
90
- }
91
- $reviewForm.addClass('submitting');
92
- $.ajax({
93
- url: window.location.href,
94
- data: $('form', $reviewForm).serialize(),
95
- dataType: 'text',
96
- success: function (response) {
97
- submitting = false;
98
- response = LP.parseJSON(response);
99
- if (response.result == 'success') {
100
- closeForm();
101
- LP.reload();
102
- } else {
103
- $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
104
- $reviewForm.removeClass('submitting').addClass('error');
105
- $reviewForm.find('message').html(response.message);
106
- }
107
- },
108
- error: function (response) {
109
- response = LP.parseJSON(response);
110
- submitting = false;
111
- $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
112
- $reviewForm.removeClass('submitting').addClass('error');
113
- $reviewForm.find('message').html(response.message);
114
- }
115
- });
116
- $('button, input[type="text"], textarea', $reviewForm).prop('disabled', true);
117
-
118
- }
119
-
120
- $reviewBtn.click(function (e) {
121
- e.preventDefault();
122
- that.showForm();
123
- });
124
-
125
- $reviewForm
126
- .on('click', '.submit-review', addReview)
127
- .on('click', '.close', function (e) {
128
- e.preventDefault();
129
- closeForm();
130
- })
131
- }
132
-
133
- $(document).ready(function () {
134
- new CourseReview();
135
- });
136
-
137
- })
138
- (jQuery);
139
- jQuery(document).ready(function ($) {
140
-
141
- $(document).on('click', '.course-review-load-more', function () {
142
- var $button = $(this);
143
- if (!$button.is(':visible')) return;
144
- $button.hide();
145
- var paged = parseInt($(this).attr('data-paged')) + 1;
146
- $('#course-reviews .loading').show();
147
- $.ajax({
148
- type: "POST",
149
- dataType: 'html',
150
- url: window.location.href,
151
- data: {
152
- 'lp-ajax': 'learnpress_load_course_review',
153
- 'paged': paged
154
- },
155
- success: function (response) {
156
- //response = LP.parseJSON(response);
157
- var $content = $(response),
158
- $loading = $('#course-reviews .loading').hide();
159
- if ($content.find('.course-reviews-list').length) {
160
- $content.find('.course-reviews-list > li:not(.loading)').insertBefore($loading);
161
- }
162
- if ($content.find('.course-review-load-more').length) {
163
- $button.show().attr('data-paged', paged);
164
- } else {
165
- $button.remove();
166
- }
167
- }
168
- });
169
- });
170
  })
1
+ /**
2
+ * LearnPress Course Review addon
3
+ *
4
+ * WARNING: This script may not work correct with LP version before 1.0
5
+ *
6
+ * @version 1.0
7
+ */
8
+ ;(function ($) {
9
+ if (typeof LP == 'undefined' && typeof LearnPress != 'undefined') {
10
+ window.LP = LearnPress;
11
+ }
12
+
13
+ function CourseReview() {
14
+ var $reviewForm = $('#course-review').appendTo(document.body),
15
+ $reviewBtn = $(".write-a-review"),
16
+ $stars = $('.review-fields ul > li span', $reviewForm).each(function (i) {
17
+ $(this).hover(function () {
18
+ if (submitting) {
19
+ return;
20
+ }
21
+ $stars.map(function (j) {
22
+ $(this).toggleClass('hover', j <= i);
23
+ })
24
+ }, function () {
25
+ if (submitting) {
26
+ return;
27
+ }
28
+ var selected = $reviewForm.find('input[name="rating"]').val();
29
+ if (selected) {
30
+ $stars.map(function (j) {
31
+ $(this).toggleClass('hover', j < selected);
32
+ });
33
+ } else {
34
+ $stars.removeClass('hover')
35
+ }
36
+ }).click(function (e) {
37
+ if (submitting) {
38
+ return;
39
+ }
40
+ e.preventDefault();
41
+ $reviewForm.find('input[name="rating"]').val($stars.index($(this)) + 1);
42
+ })
43
+ }),
44
+ that = this,
45
+ submitting = false,
46
+ showForm = null,
47
+ closeForm = null,
48
+ addReview = null;
49
+
50
+ showForm = this.showForm = function () {
51
+ var _completed = function () {
52
+ $('input[type="text"], textarea', this).val('');
53
+ $stars.removeClass('hover');
54
+ }
55
+ $reviewForm.fadeIn(_completed);
56
+ }
57
+
58
+ closeForm = this.closeForm = function () {
59
+ var _completed = function () {
60
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
61
+ $reviewForm.removeClass('submitting').data('selected', '');
62
+ $stars.removeClass('hover')
63
+ }
64
+ $reviewForm.find('input[name="rating"]').val('')
65
+ $(document).focus();
66
+ $reviewForm.fadeOut(_completed);
67
+ }
68
+
69
+ addReview = this.addReview = function () {
70
+ var $reviewTitle = $('input[name="review_title"]', $reviewForm);
71
+ var $reviewContent = $('textarea[name="review_content"]', $reviewForm);
72
+ var rating = $reviewForm.find('input[name="rating"]').val();
73
+ var course_id = $(this).attr('data-id');
74
+
75
+ if (0 == $reviewTitle.val().length) {
76
+ alert(learn_press_course_review.localize.empty_title)
77
+ $reviewTitle.focus();
78
+ return;
79
+ }
80
+
81
+ if (0 == $reviewContent.val().length) {
82
+ alert(learn_press_course_review.localize.empty_content)
83
+ $reviewContent.focus();
84
+ return;
85
+ }
86
+
87
+ if (0 == rating) {
88
+ alert(learn_press_course_review.localize.empty_rating)
89
+ return;
90
+ }
91
+ $reviewForm.addClass('submitting');
92
+ $.ajax({
93
+ url: window.location.href,
94
+ data: $('form', $reviewForm).serialize(),
95
+ dataType: 'text',
96
+ success: function (response) {
97
+ submitting = false;
98
+ response = LP.parseJSON(response);
99
+ if (response.result == 'success') {
100
+ closeForm();
101
+ LP.reload();
102
+ } else {
103
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
104
+ $reviewForm.removeClass('submitting').addClass('error');
105
+ $reviewForm.find('message').html(response.message);
106
+ }
107
+ },
108
+ error: function (response) {
109
+ response = LP.parseJSON(response);
110
+ submitting = false;
111
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
112
+ $reviewForm.removeClass('submitting').addClass('error');
113
+ $reviewForm.find('message').html(response.message);
114
+ }
115
+ });
116
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', true);
117
+
118
+ }
119
+
120
+ $reviewBtn.click(function (e) {
121
+ e.preventDefault();
122
+ that.showForm();
123
+ });
124
+
125
+ $reviewForm
126
+ .on('click', '.submit-review', addReview)
127
+ .on('click', '.close', function (e) {
128
+ e.preventDefault();
129
+ closeForm();
130
+ })
131
+ }
132
+
133
+ $(document).ready(function () {
134
+ new CourseReview();
135
+ });
136
+
137
+ })
138
+ (jQuery);
139
+ jQuery(document).ready(function ($) {
140
+
141
+ $(document).on('click', '.course-review-load-more', function () {
142
+ var $button = $(this);
143
+ if (!$button.is(':visible')) return;
144
+ $button.hide();
145
+ var paged = parseInt($(this).attr('data-paged')) + 1;
146
+ $('#course-reviews .loading').show();
147
+ $.ajax({
148
+ type: "POST",
149
+ dataType: 'html',
150
+ url: window.location.href,
151
+ data: {
152
+ 'lp-ajax': 'learnpress_load_course_review',
153
+ 'paged': paged
154
+ },
155
+ success: function (response) {
156
+ //response = LP.parseJSON(response);
157
+ var $content = $(response),
158
+ $loading = $('#course-reviews .loading').hide();
159
+ if ($content.find('.course-reviews-list').length) {
160
+ $content.find('.course-reviews-list > li:not(.loading)').insertBefore($loading);
161
+ }
162
+ if ($content.find('.course-review-load-more').length) {
163
+ $button.show().attr('data-paged', paged);
164
+ } else {
165
+ $button.remove();
166
+ }
167
+ }
168
+ });
169
+ });
170
  })
inc/functions.php CHANGED
@@ -1,431 +1,431 @@
1
- <?php
2
- /**
3
- * LearnPress Course Review Functions
4
- *
5
- * Define common functions for both front-end and back-end
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Functions
9
- * @version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
-
15
- /**
16
- * @param int $course_id
17
- * @param int $paged
18
- * @param int $per_page
19
- * @param boolean $force
20
- *
21
- * @return mixed
22
- */
23
- function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_ADDON_COURSE_REVIEW_PER_PAGE, $force = false ) {
24
-
25
- $key = 'course-' . md5( serialize( array( $course_id, $paged, $per_page ) ) );
26
-
27
- if ( false === ( $results = wp_cache_get( $key, 'lp-course-review' ) ) || $force ) {
28
-
29
- global $wpdb;
30
- $per_page = absint( apply_filters( 'learn_press_course_reviews_per_page', $per_page ) );
31
- $paged = absint( $paged );
32
-
33
- if ( $per_page == 0 ) {
34
- $per_page = 9999999;
35
- }
36
-
37
- if ( $paged == 0 ) {
38
- $paged = 1;
39
- }
40
-
41
- $start = ( $paged - 1 ) * $per_page;
42
- $start = max( $start, 0 );
43
- $per_page = max( $per_page, 1 );
44
- $results = array(
45
- 'reviews' => array(),
46
- 'paged' => $paged,
47
- 'total' => 0,
48
- 'per_page' => $per_page
49
- );
50
-
51
- $query = $wpdb->prepare( "
52
- SELECT SQL_CALC_FOUND_ROWS u.*, c.comment_ID as comment_id, cm1.meta_value as title, c.comment_content as content, cm2.meta_value as rate
53
- FROM {$wpdb->posts} p
54
- INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
55
- INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
56
- INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key = %s
57
- INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key = %s
58
- WHERE p.ID = %d AND c.comment_type = %s AND c.comment_approved = %d
59
- ORDER BY c.comment_date DESC
60
- LIMIT %d, %d
61
- ", '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1, $start, $per_page );
62
-
63
- $course_review = $wpdb->get_results( $query );
64
-
65
- if ( $course_review ) {
66
- $ratings = _learn_press_get_ratings( $course_id );
67
- $results['reviews'] = $course_review;
68
- $results['total'] = $ratings[ $course_id ]['total'];
69
- if ( $results['total'] <= $start + $per_page ) {
70
- $results['finish'] = true;
71
- }
72
- }
73
-
74
- wp_cache_set( $key, $results, 'lp-course-review' );
75
- }
76
-
77
- return $results;
78
- }
79
-
80
- function _learn_press_get_ratings( $course_id ) {
81
-
82
- static $course_rates = array();
83
- if ( ! is_array( $course_id ) ) {
84
- $ids = array( $course_id );
85
- } else {
86
- $ids = $course_id;
87
- }
88
- foreach ( $ids as $cid ) {
89
- if ( ! isset( $course_rates[ $cid ] ) ) {
90
- $course_rates[ $cid ] = leanr_press_get_ratings_result( $cid );
91
- }
92
- }
93
-
94
- return $course_rates;
95
- }
96
-
97
-
98
- /**
99
- * @param $course_id
100
- * @param $field
101
- *
102
- * @return mixed
103
- */
104
- function learn_press_get_course_rate( $course_id, $field = 'rated' ) {
105
- $ratings = _learn_press_get_ratings( $course_id );
106
- $rate = ( $field && array_key_exists( $field, $ratings[ $course_id ] ) ) ? $ratings[ $course_id ][ $field ] : $ratings[ $course_id ];
107
-
108
- return apply_filters( 'learn_press_get_course_rate', $rate );
109
- }
110
-
111
- function learn_press_get_course_rate_total( $course_id, $field = 'total' ) {
112
- /*global $wpdb;
113
- $query = $wpdb->prepare( "
114
- SELECT COUNT(*)
115
- FROM {$wpdb->posts} p
116
- INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
117
- INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
118
- INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
119
- INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
120
- WHERE p.ID=%d AND c.comment_type=%s and c.comment_approved = %d
121
- ORDER BY c.comment_date DESC",
122
- '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1
123
- );
124
- $total = $wpdb->get_var( $query );*/
125
-
126
- $ratings = _learn_press_get_ratings( $course_id );
127
- $total = array_key_exists( $field, $ratings[ $course_id ] ) ? $ratings[ $course_id ][ $field ] : $ratings;
128
-
129
- return apply_filters( 'learn_press_get_course_rate_total', $total );
130
- }
131
-
132
- /**
133
- * @param $course_id
134
- * @param $user_id
135
- *
136
- * @return string
137
- */
138
- function learn_press_get_user_review_title( $course_id, $user_id ) {
139
- $course_review = get_post_meta( $course_id, '_lpr_course_review', true );
140
-
141
- if ( $course_review && array_key_exists( $user_id, $course_review['review_title'] ) ) {
142
- return apply_filters( 'learn_press_get_user_review', $course_review['review_title'][ $user_id ] );
143
- }
144
-
145
- return false;
146
- }
147
-
148
- /**
149
- * Get the rating user has posted for a course.
150
- *
151
- * @param int $course_id
152
- * @param int $user_id
153
- *
154
- * @return mixed
155
- */
156
- function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
157
- if ( ! $user_id ) {
158
- $user_id = get_current_user_id();
159
- }
160
- if ( ! $course_id ) {
161
- $course_id = get_the_ID();
162
- }
163
-
164
- // Get in cache if it is already get
165
- if ( false === ( $comment = wp_cache_get( 'user-' . $user_id . '/' . $course_id, 'lp-user-rate' ) ) ) {
166
- global $wpdb;
167
- $query = $wpdb->prepare( "
168
- SELECT *
169
- FROM {$wpdb->posts} p
170
- INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
171
- WHERE c.comment_post_ID = %d
172
- AND c.user_id = %d
173
- AND c.comment_type = %s
174
- ", $course_id, $user_id, 'review' );
175
-
176
- $comment = $wpdb->get_row( $query );
177
-
178
- if ( $comment ) {
179
- $comment->comment_title = get_comment_meta( $comment->comment_ID, '_lpr_review_title', true );
180
- $comment->rating = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
181
- }
182
-
183
- wp_cache_set( 'user-' . $user_id . '/' . $course_id, $comment, 'lp-user-rate' );
184
- }
185
-
186
- return $comment;
187
- }
188
-
189
- /**
190
- * Add new review for a course
191
- *
192
- * @param array
193
- *
194
- * @return int
195
- */
196
- function learn_press_add_course_review( $args = array() ) {
197
- $args = wp_parse_args(
198
- $args,
199
- array(
200
- 'title' => '',
201
- 'content' => '',
202
- 'rate' => '',
203
- 'user_id' => 0,
204
- 'course_id' => 0
205
- )
206
- );
207
- $user_id = $args['user_id'];
208
- $course_id = $args['course_id'];
209
- $user_review = learn_press_get_user_rate( $course_id, $user_id );
210
- $comment_id = 0;
211
- if ( ! $user_review ) {
212
- $user = get_user_by( 'id', $user_id );
213
- $comment_id = wp_new_comment(
214
- array(
215
- 'comment_post_ID' => $course_id,
216
- 'comment_author' => $user->display_name,
217
- 'comment_author_email' => $user->user_email,
218
- 'comment_author_url' => '',
219
- 'comment_content' => $args['content'],
220
- 'comment_parent' => 0,
221
- 'user_id' => $user->ID,
222
- 'comment_approved' => 1,
223
- 'comment_type' => 'review' // let filter to not display it as comments
224
- )
225
- );
226
- }
227
- if ( $comment_id ) {
228
- add_comment_meta( $comment_id, '_lpr_rating', $args['rate'] );
229
- add_comment_meta( $comment_id, '_lpr_review_title', $args['title'] );
230
- }
231
-
232
- return $comment_id;
233
- }
234
-
235
- function learn_press_course_review_template( $name, $args = null ) {
236
- learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
237
- }
238
-
239
- /*
240
- * If we are viewing archive course page, so load all ratings of courses
241
- * into cache to reduce queries and time rather than load separate course
242
- * in loop
243
- */
244
- add_filter( 'the_posts', 'learn_press_init_courses_review' );
245
- function learn_press_init_courses_review( $posts ) {
246
- if ( $posts ) {
247
- $pIds = array();
248
- foreach ( $posts as $p ) {
249
- $pIds[] = $p->ID;
250
- }
251
- _learn_press_get_ratings( $pIds );
252
- }
253
-
254
- return $posts;
255
- }
256
-
257
- /**
258
- * Get rating for a course
259
- *
260
- * @param int $course_id
261
- * @param bool $get_items
262
- *
263
- * @return array
264
- */
265
- function leanr_press_get_ratings_result( $course_id = 0, $get_items = false ) {
266
- //return learn_press_get_ratings_result_bak($course_id);
267
- if ( false === ( $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' ) ) ) {
268
- global $wpdb;
269
-
270
- $query = $wpdb->prepare( "
271
- SELECT
272
- cm.meta_value `rate`, COUNT(1) `count`
273
- FROM
274
- {$wpdb->comments} c
275
- INNER JOIN
276
- {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
277
- WHERE
278
- c.comment_approved = 1
279
- AND c.comment_type = %s
280
- AND c.user_id > 0
281
- AND c.comment_post_ID = %d
282
- GROUP BY `cm`.`meta_value`
283
- ", '_lpr_rating', 'review', $course_id );
284
- $rows = $wpdb->get_results( $query/*, OBJECT_K */ );
285
-
286
- $count = 0;
287
- $rate = 0;
288
- $avg = 0;
289
- $items = array();
290
-
291
- for ( $i = 5; $i > 0; $i -- ) {
292
- $items[ $i ] = array(
293
- 'rated' => $i,
294
- 'total' => 0,
295
- 'percent' => 0
296
- );
297
- }
298
-
299
- if ( $rows ) {
300
-
301
- $count = wp_list_pluck( $rows, 'count' );
302
- $count = array_sum( $count );
303
- $round = array();
304
- $one_hundred = 0;
305
-
306
- foreach ( $rows as $row ) {
307
- $rate += $row->rate * $row->count;
308
- $percent = $row->count / $count * 100;
309
- $items[ $row->rate ] = array(
310
- 'rated' => $row->rate,
311
- 'total' => $row->count,
312
- 'percent' => floor( $percent ),
313
- 'percent_float' => $percent
314
- );
315
- $one_hundred += $items[ $row->rate ]['percent'];
316
- $round[ $row->rate ] = $percent - floor( $percent );
317
- }
318
-
319
- if ( $one_hundred < 100 ) {
320
- arsort( $round );
321
- foreach ( $round as $key => $value ) {
322
- $percent = $items[ $key ]['percent'];
323
- $items[ $key ]['percent'] = ceil( $items[ $key ]['percent_float'] );
324
-
325
- if ( $percent < $items[ $key ]['percent'] ) {
326
- $one_hundred ++;
327
- if ( $one_hundred == 100 ) {
328
- break;
329
- }
330
- }
331
- }
332
- }
333
-
334
-
335
- $avg = $rate / $count;
336
- }
337
-
338
- $result = array(
339
- 'course_id' => $course_id,
340
- 'total' => $count,
341
- 'rated' => $avg,
342
- 'items' => $items
343
- );
344
-
345
- wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings' );
346
- }
347
-
348
- return $result;
349
- }
350
-
351
- function learn_press_get_ratings_result_bak( $course_id = 0, $get_items = false ) {
352
-
353
- if ( false === ( $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' ) ) ) {
354
- LP_Debug::timeStart( 'xxxxx' );
355
- global $wpdb;
356
- $query = $wpdb->prepare( "
357
- SELECT
358
- COUNT(*) `count` ,AVG(cm.meta_value) `avg`
359
- FROM
360
- {$wpdb->comments} c
361
- INNER JOIN
362
- {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
363
- WHERE
364
- c.comment_approved = 1
365
- AND c.comment_type = %s
366
- AND c.user_id > 0
367
- AND c.comment_post_ID = %d
368
- ", '_lpr_rating', 'review', $course_id );
369
- $row = $wpdb->get_row( $query );
370
-
371
- $count = 0;
372
- $avg = 0;
373
-
374
- if ( $row ) {
375
- $count = $row->count;
376
- $avg = $row->avg;
377
- }
378
-
379
- $rows = array();
380
- if ( $count != 0 ):
381
-
382
- $query = $wpdb->prepare( "
383
- SELECT
384
- cm.meta_value `rate`, COUNT(*) `count`
385
- FROM
386
- {$wpdb->comments} c
387
- INNER JOIN
388
- {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
389
- WHERE
390
- c.comment_approved = 1
391
- AND c.comment_type = %s
392
- AND c.user_id > 0
393
- AND c.comment_post_ID = %d
394
- GROUP BY `cm`.`meta_value`
395
- ORDER BY `cm`.`meta_value` DESC
396
- ", '_lpr_rating', 'review', $course_id );
397
- $rows = $wpdb->get_results( $query, OBJECT_K );
398
-
399
- endif;
400
-
401
- $items = array();
402
- for ( $i = 5; $i > 0; $i -- ) {
403
- if ( isset( $rows[ $i ] ) ) {
404
- $items[] = array(
405
- 'rated' => $rows[ $i ]->rate,
406
- 'total' => $rows[ $i ]->count,
407
- 'percent' => $rows[ $i ]->count / $count * 100
408
- );
409
- } else {
410
- $items[] = array(
411
- 'rated' => $i,
412
- 'total' => 0,
413
- 'percent' => 0
414
- );
415
- }
416
- }
417
- $result = array(
418
- 'course_id' => $course_id,
419
- 'total' => $count,
420
- 'rated' => $avg,
421
- 'items' => $items
422
- );
423
- LP_Debug::timeEnd( 'xxxxx' );
424
-
425
- learn_press_debug( $result );
426
-
427
- wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings' );
428
- }
429
-
430
- return $result;
431
  }
1
+ <?php
2
+ /**
3
+ * LearnPress Course Review Functions
4
+ *
5
+ * Define common functions for both front-end and back-end
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Functions
9
+ * @version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ /**
16
+ * @param int $course_id
17
+ * @param int $paged
18
+ * @param int $per_page
19
+ * @param boolean $force
20
+ *
21
+ * @return mixed
22
+ */
23
+ function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_ADDON_COURSE_REVIEW_PER_PAGE, $force = false ) {
24
+
25
+ $key = 'course-' . md5( serialize( array( $course_id, $paged, $per_page ) ) );
26
+
27
+ if ( false === ( $results = wp_cache_get( $key, 'lp-course-review' ) ) || $force ) {
28
+
29
+ global $wpdb;
30
+ $per_page = absint( apply_filters( 'learn_press_course_reviews_per_page', $per_page ) );
31
+ $paged = absint( $paged );
32
+
33
+ if ( $per_page == 0 ) {
34
+ $per_page = 9999999;
35
+ }
36
+
37
+ if ( $paged == 0 ) {
38
+ $paged = 1;
39
+ }
40
+
41
+ $start = ( $paged - 1 ) * $per_page;
42
+ $start = max( $start, 0 );
43
+ $per_page = max( $per_page, 1 );
44
+ $results = array(
45
+ 'reviews' => array(),
46
+ 'paged' => $paged,
47
+ 'total' => 0,
48
+ 'per_page' => $per_page
49
+ );
50
+
51
+ $query = $wpdb->prepare( "
52
+ SELECT SQL_CALC_FOUND_ROWS u.*, c.comment_ID as comment_id, cm1.meta_value as title, c.comment_content as content, cm2.meta_value as rate
53
+ FROM {$wpdb->posts} p
54
+ INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
55
+ INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
56
+ INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key = %s
57
+ INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key = %s
58
+ WHERE p.ID = %d AND c.comment_type = %s AND c.comment_approved = %d
59
+ ORDER BY c.comment_date DESC
60
+ LIMIT %d, %d
61
+ ", '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1, $start, $per_page );
62
+
63
+ $course_review = $wpdb->get_results( $query );
64
+
65
+ if ( $course_review ) {
66
+ $ratings = _learn_press_get_ratings( $course_id );
67
+ $results['reviews'] = $course_review;
68
+ $results['total'] = $ratings[ $course_id ]['total'];
69
+ if ( $results['total'] <= $start + $per_page ) {
70
+ $results['finish'] = true;
71
+ }
72
+ }
73
+
74
+ wp_cache_set( $key, $results, 'lp-course-review' );
75
+ }
76
+
77
+ return $results;
78
+ }
79
+
80
+ function _learn_press_get_ratings( $course_id ) {
81
+
82
+ static $course_rates = array();
83
+ if ( ! is_array( $course_id ) ) {
84
+ $ids = array( $course_id );
85
+ } else {
86
+ $ids = $course_id;
87
+ }
88
+ foreach ( $ids as $cid ) {
89
+ if ( ! isset( $course_rates[ $cid ] ) ) {
90
+ $course_rates[ $cid ] = leanr_press_get_ratings_result( $cid );
91
+ }
92
+ }
93
+
94
+ return $course_rates;
95
+ }
96
+
97
+
98
+ /**
99
+ * @param $course_id
100
+ * @param $field
101
+ *
102
+ * @return mixed
103
+ */
104
+ function learn_press_get_course_rate( $course_id, $field = 'rated' ) {
105
+ $ratings = _learn_press_get_ratings( $course_id );
106
+ $rate = ( $field && array_key_exists( $field, $ratings[ $course_id ] ) ) ? $ratings[ $course_id ][ $field ] : $ratings[ $course_id ];
107
+
108
+ return apply_filters( 'learn_press_get_course_rate', $rate );
109
+ }
110
+
111
+ function learn_press_get_course_rate_total( $course_id, $field = 'total' ) {
112
+ /*global $wpdb;
113
+ $query = $wpdb->prepare( "
114
+ SELECT COUNT(*)
115
+ FROM {$wpdb->posts} p
116
+ INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
117
+ INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
118
+ INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
119
+ INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
120
+ WHERE p.ID=%d AND c.comment_type=%s and c.comment_approved = %d
121
+ ORDER BY c.comment_date DESC",
122
+ '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1
123
+ );
124
+ $total = $wpdb->get_var( $query );*/
125
+
126
+ $ratings = _learn_press_get_ratings( $course_id );
127
+ $total = array_key_exists( $field, $ratings[ $course_id ] ) ? $ratings[ $course_id ][ $field ] : $ratings;
128
+
129
+ return apply_filters( 'learn_press_get_course_rate_total', $total );
130
+ }
131
+
132
+ /**
133
+ * @param $course_id
134
+ * @param $user_id
135
+ *
136
+ * @return string
137
+ */
138
+ function learn_press_get_user_review_title( $course_id, $user_id ) {
139
+ $course_review = get_post_meta( $course_id, '_lpr_course_review', true );
140
+
141
+ if ( $course_review && array_key_exists( $user_id, $course_review['review_title'] ) ) {
142
+ return apply_filters( 'learn_press_get_user_review', $course_review['review_title'][ $user_id ] );
143
+ }
144
+
145
+ return false;
146
+ }
147
+
148
+ /**
149
+ * Get the rating user has posted for a course.
150
+ *
151
+ * @param int $course_id
152
+ * @param int $user_id
153
+ *
154
+ * @return mixed
155
+ */
156
+ function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
157
+ if ( ! $user_id ) {
158
+ $user_id = get_current_user_id();
159
+ }
160
+ if ( ! $course_id ) {
161
+ $course_id = get_the_ID();
162
+ }
163
+
164
+ // Get in cache if it is already get
165
+ if ( ! ( $comment = wp_cache_get( 'user-' . $user_id . '/' . $course_id, 'lp-user-rate' ) ) ) {
166
+ global $wpdb;
167
+ $query = $wpdb->prepare( "
168
+ SELECT *
169
+ FROM {$wpdb->posts} p
170
+ INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
171
+ WHERE c.comment_post_ID = %d
172
+ AND c.user_id = %d
173
+ AND c.comment_type = %s
174
+ ", $course_id, $user_id, 'review' );
175
+
176
+ $comment = $wpdb->get_row( $query );
177
+
178
+ if ( $comment ) {
179
+ $comment->comment_title = get_comment_meta( $comment->comment_ID, '_lpr_review_title', true );
180
+ $comment->rating = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
181
+ }
182
+
183
+ wp_cache_set( 'user-' . $user_id . '/' . $course_id, $comment, 'lp-user-rate' );
184
+ }
185
+
186
+ return $comment;
187
+ }
188
+
189
+ /**
190
+ * Add new review for a course
191
+ *
192
+ * @param array
193
+ *
194
+ * @return int
195
+ */
196
+ function learn_press_add_course_review( $args = array() ) {
197
+ $args = wp_parse_args(
198
+ $args,
199
+ array(
200
+ 'title' => '',
201
+ 'content' => '',
202
+ 'rate' => '',
203
+ 'user_id' => 0,
204
+ 'course_id' => 0
205
+ )
206
+ );
207
+ $user_id = $args['user_id'];
208
+ $course_id = $args['course_id'];
209
+ $user_review = learn_press_get_user_rate( $course_id, $user_id );
210
+ $comment_id = 0;
211
+ if ( ! $user_review ) {
212
+ $user = get_user_by( 'id', $user_id );
213
+ $comment_id = wp_new_comment(
214
+ array(
215
+ 'comment_post_ID' => $course_id,
216
+ 'comment_author' => $user->display_name,
217
+ 'comment_author_email' => $user->user_email,
218
+ 'comment_author_url' => '',
219
+ 'comment_content' => $args['content'],
220
+ 'comment_parent' => 0,
221
+ 'user_id' => $user->ID,
222
+ 'comment_approved' => 1,
223
+ 'comment_type' => 'review' // let filter to not display it as comments
224
+ )
225
+ );
226
+ }
227
+ if ( $comment_id ) {
228
+ add_comment_meta( $comment_id, '_lpr_rating', $args['rate'] );
229
+ add_comment_meta( $comment_id, '_lpr_review_title', $args['title'] );
230
+ }
231
+
232
+ return $comment_id;
233
+ }
234
+
235
+ function learn_press_course_review_template( $name, $args = null ) {
236
+ learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
237
+ }
238
+
239
+ /*
240
+ * If we are viewing archive course page, so load all ratings of courses
241
+ * into cache to reduce queries and time rather than load separate course
242
+ * in loop
243
+ */
244
+ add_filter( 'the_posts', 'learn_press_init_courses_review' );
245
+ function learn_press_init_courses_review( $posts ) {
246
+ if ( $posts ) {
247
+ $pIds = array();
248
+ foreach ( $posts as $p ) {
249
+ $pIds[] = $p->ID;
250
+ }
251
+ _learn_press_get_ratings( $pIds );
252
+ }
253
+
254
+ return $posts;
255
+ }
256
+
257
+ /**
258
+ * Get rating for a course
259
+ *
260
+ * @param int $course_id
261
+ * @param bool $get_items
262
+ *
263
+ * @return array
264
+ */
265
+ function leanr_press_get_ratings_result( $course_id = 0, $get_items = false ) {
266
+ //return learn_press_get_ratings_result_bak($course_id);
267
+ if ( false === ( $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' ) ) ) {
268
+ global $wpdb;
269
+
270
+ $query = $wpdb->prepare( "
271
+ SELECT
272
+ cm.meta_value `rate`, COUNT(1) `count`
273
+ FROM
274
+ {$wpdb->comments} c
275
+ INNER JOIN
276
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
277
+ WHERE
278
+ c.comment_approved = 1
279
+ AND c.comment_type = %s
280
+ AND c.user_id > 0
281
+ AND c.comment_post_ID = %d
282
+ GROUP BY `cm`.`meta_value`
283
+ ", '_lpr_rating', 'review', $course_id );
284
+ $rows = $wpdb->get_results( $query/*, OBJECT_K */ );
285
+
286
+ $count = 0;
287
+ $rate = 0;
288
+ $avg = 0;
289
+ $items = array();
290
+
291
+ for ( $i = 5; $i > 0; $i -- ) {
292
+ $items[ $i ] = array(
293
+ 'rated' => $i,
294
+ 'total' => 0,
295
+ 'percent' => 0
296
+ );
297
+ }
298
+
299
+ if ( $rows ) {
300
+
301
+ $count = wp_list_pluck( $rows, 'count' );
302
+ $count = array_sum( $count );
303
+ $round = array();
304
+ $one_hundred = 0;
305
+
306
+ foreach ( $rows as $row ) {
307
+ $rate += $row->rate * $row->count;
308
+ $percent = $row->count / $count * 100;
309
+ $items[ $row->rate ] = array(
310
+ 'rated' => $row->rate,
311
+ 'total' => $row->count,
312
+ 'percent' => floor( $percent ),
313
+ 'percent_float' => $percent
314
+ );
315
+ $one_hundred += $items[ $row->rate ]['percent'];
316
+ $round[ $row->rate ] = $percent - floor( $percent );
317
+ }
318
+
319
+ if ( $one_hundred < 100 ) {
320
+ arsort( $round );
321
+ foreach ( $round as $key => $value ) {
322
+ $percent = $items[ $key ]['percent'];
323
+ $items[ $key ]['percent'] = ceil( $items[ $key ]['percent_float'] );
324
+
325
+ if ( $percent < $items[ $key ]['percent'] ) {
326
+ $one_hundred ++;
327
+ if ( $one_hundred == 100 ) {
328
+ break;
329
+ }
330
+ }
331
+ }
332
+ }
333
+
334
+
335
+ $avg = $rate / $count;
336
+ }
337
+
338
+ $result = array(
339
+ 'course_id' => $course_id,
340
+ 'total' => $count,
341
+ 'rated' => $avg,
342
+ 'items' => $items
343
+ );
344
+
345
+ wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings' );
346
+ }
347
+
348
+ return $result;
349
+ }
350
+
351
+ function learn_press_get_ratings_result_bak( $course_id = 0, $get_items = false ) {
352
+
353
+ if ( false === ( $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' ) ) ) {
354
+ LP_Debug::timeStart( 'xxxxx' );
355
+ global $wpdb;
356
+ $query = $wpdb->prepare( "
357
+ SELECT
358
+ COUNT(*) `count` ,AVG(cm.meta_value) `avg`
359
+ FROM
360
+ {$wpdb->comments} c
361
+ INNER JOIN
362
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
363
+ WHERE
364
+ c.comment_approved = 1
365
+ AND c.comment_type = %s
366
+ AND c.user_id > 0
367
+ AND c.comment_post_ID = %d
368
+ ", '_lpr_rating', 'review', $course_id );
369
+ $row = $wpdb->get_row( $query );
370
+
371
+ $count = 0;
372
+ $avg = 0;
373
+
374
+ if ( $row ) {
375
+ $count = $row->count;
376
+ $avg = $row->avg;
377
+ }
378
+
379
+ $rows = array();
380
+ if ( $count != 0 ):
381
+
382
+ $query = $wpdb->prepare( "
383
+ SELECT
384
+ cm.meta_value `rate`, COUNT(*) `count`
385
+ FROM
386
+ {$wpdb->comments} c
387
+ INNER JOIN
388
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
389
+ WHERE
390
+ c.comment_approved = 1
391
+ AND c.comment_type = %s
392
+ AND c.user_id > 0
393
+ AND c.comment_post_ID = %d
394
+ GROUP BY `cm`.`meta_value`
395
+ ORDER BY `cm`.`meta_value` DESC
396
+ ", '_lpr_rating', 'review', $course_id );
397
+ $rows = $wpdb->get_results( $query, OBJECT_K );
398
+
399
+ endif;
400
+
401
+ $items = array();
402
+ for ( $i = 5; $i > 0; $i -- ) {
403
+ if ( isset( $rows[ $i ] ) ) {
404
+ $items[] = array(
405
+ 'rated' => $rows[ $i ]->rate,
406
+ 'total' => $rows[ $i ]->count,
407
+ 'percent' => $rows[ $i ]->count / $count * 100
408
+ );
409
+ } else {
410
+ $items[] = array(
411
+ 'rated' => $i,
412
+ 'total' => 0,
413
+ 'percent' => 0
414
+ );
415
+ }
416
+ }
417
+ $result = array(
418
+ 'course_id' => $course_id,
419
+ 'total' => $count,
420
+ 'rated' => $avg,
421
+ 'items' => $items
422
+ );
423
+ LP_Debug::timeEnd( 'xxxxx' );
424
+
425
+ learn_press_debug( $result );
426
+
427
+ wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings' );
428
+ }
429
+
430
+ return $result;
431
  }
inc/load.php CHANGED
@@ -1,320 +1,320 @@
1
- <?php
2
- /**
3
- * Plugin load class.
4
- *
5
- * @author ThimPress
6
- * @package LearnPress/Course-Review/Classes
7
- * @version 3.0.1
8
- */
9
-
10
- // Prevent loading this file directly
11
- defined( 'ABSPATH' ) || exit;
12
-
13
- if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
14
- /**
15
- * Class LP_Addon_Course_Review.
16
- */
17
- class LP_Addon_Course_Review extends LP_Addon {
18
-
19
- /**
20
- * @var string
21
- */
22
- public $version = LP_ADDON_COURSE_REVIEW_VER;
23
-
24
- /**
25
- * @var string
26
- */
27
- public $require_version = LP_ADDON_COURSE_REVIEW_REQUIRE_VER;
28
-
29
- /**
30
- * @var string
31
- */
32
- private static $comment_type = 'review';
33
-
34
- /**
35
- * LP_Addon_Course_Review constructor.
36
- */
37
- public function __construct() {
38
- parent::__construct();
39
- add_action( 'widgets_init', array( $this, 'load_widget' ) );
40
- }
41
-
42
- /**
43
- * Define Learnpress Course Review constants.
44
- *
45
- * @since 3.0.0
46
- */
47
- protected function _define_constants() {
48
- define( 'LP_ADDON_COURSE_REVIEW_PATH', dirname( LP_ADDON_COURSE_REVIEW_FILE ) );
49
- define( 'LP_ADDON_COURSE_REVIEW_PER_PAGE', 5 );
50
- define( 'LP_ADDON_COURSE_REVIEW_TMPL', LP_ADDON_COURSE_REVIEW_PATH . '/templates/' );
51
- define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
52
- define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', dirname( __FILE__ ) ) ) );
53
- }
54
-
55
- /**
56
- * Include required core files used in admin and on the frontend.
57
- *
58
- * @since 3.0.0
59
- */
60
- protected function _includes() {
61
- require_once LP_ADDON_COURSE_REVIEW_PATH . '/inc/functions.php';
62
- require_once LP_ADDON_COURSE_REVIEW_PATH . '/inc/widgets.php';
63
- }
64
-
65
- /**
66
- * Init hooks.
67
- */
68
- protected function _init_hooks() {
69
- add_filter( 'learn-press/course-tabs', array( $this, 'add_course_tab_reviews' ), 5 );
70
-
71
- add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
72
- add_action( 'wp', array( $this, 'course_review_init' ) );
73
-
74
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
75
- LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
76
- LP_Request_Handler::register_ajax( 'learnpress_load_course_review', array(
77
- $this,
78
- 'learnpress_load_course_review'
79
- ) );
80
- add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
81
-
82
- $this->init_comment_table();
83
- }
84
-
85
- /**
86
- * Get html of reviews
87
- */
88
- public function learnpress_load_course_review() {
89
- $paged = LP_Request::get_post( 'paged', 1 ) ? (int) LP_Request::get_post( 'paged', 1 ) : 1;
90
- $response = learn_press_get_course_review( get_the_ID(), $paged );
91
- if ( $response['reviews'] && count( $response['reviews'] ) > 0 ) {
92
- ob_start();
93
- learn_press_course_review_template( 'course-review.php', array( 'review' => $response ) );
94
- ob_end_clean();
95
- }
96
- }
97
-
98
- /**
99
- * Print rate.
100
- */
101
- public function print_rate() {
102
- learn_press_course_review_template( 'course-rate.php' );
103
- }
104
-
105
- /**
106
- * Print review.
107
- */
108
- public function print_review() {
109
- learn_press_course_review_template( 'course-review.php' );
110
- }
111
-
112
- /**
113
- * Add review button.
114
- */
115
- public function add_review_button() {
116
- if ( ! learn_press_get_user_rate( get_the_ID() ) ) {
117
- learn_press_course_review_template( 'review-form.php' );
118
- }
119
- }
120
-
121
- /**
122
- * Admin assets.
123
- */
124
- public function admin_enqueue_assets() {
125
- wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/admin.css' );
126
- }
127
-
128
- /**
129
- * Single course assets.
130
- */
131
- public function review_assets() {
132
- if ( learn_press_is_course() ) {
133
- wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
134
- wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
135
- wp_enqueue_style( 'dashicons' );
136
- wp_localize_script( 'course-review', 'learn_press_course_review',
137
- array(
138
- 'localize' => array(
139
- 'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
140
- 'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
141
- 'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
142
- )
143
- )
144
- );
145
- }
146
- }
147
-
148
- public function course_review_init() {
149
- $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
150
- learn_press_get_course_review( get_the_ID(), $paged );
151
- }
152
-
153
- public function exclude_rating( $query ) {
154
- $query->query_vars['type__not_in'] = 'review';
155
- }
156
-
157
- public function add_review() {
158
- $response = array( 'result' => 'success' );
159
- $nonce = ! empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
160
- $id = ! empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
161
- $rate = ! empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
162
- $title = ! empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
163
- $content = ! empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
164
-
165
- if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
166
- $response['result'] = 'fail';
167
- $response['message'] = __( 'Error', 'learnpress-course-review' );
168
- }
169
-
170
- if ( get_post_type( $id ) != 'lp_course' ) {
171
- $response['result'] = 'fail';
172
- $response['message'] = __( 'Invalid course', 'learnpress-course-review' );
173
- }
174
-
175
- $return = learn_press_add_course_review(
176
- array(
177
- 'user_id' => get_current_user_id(),
178
- 'course_id' => $id,
179
- 'rate' => $rate,
180
- 'title' => $title,
181
- 'content' => $content
182
- )
183
- );
184
- $response['comment'] = $return;
185
- learn_press_send_json( $response );
186
- }
187
-
188
- public function init_comment_table() {
189
- add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
190
- add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
191
- add_filter( 'comment_row_actions', array( $this, 'edit_comment_row_actions' ), 10, 2 );
192
- }
193
-
194
- public function edit_comment_row_actions( $actions, $comment ) {
195
- if ( ! $comment || $comment->comment_type != 'review' ) {
196
- return $actions;
197
- }
198
- unset( $actions['reply'] );
199
-
200
- return $actions;
201
- }
202
-
203
- public function add_comment_type_filter( $cmt_types ) {
204
- $cmt_types[ self::$comment_type ] = __( 'Course review', 'learnpress-course-review' );
205
-
206
- return $cmt_types;
207
- }
208
-
209
- public function add_comment_content_filter( $cmt_text ) {
210
- global $comment;
211
- if ( ! $comment || $comment->comment_type != 'review' ) {
212
- return $cmt_text;
213
- }
214
-
215
- ob_start();
216
- $rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
217
- echo '<div class="course-rate">';
218
- learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
219
- echo '</div>';
220
- $cmt_text .= ob_get_clean();
221
-
222
- return $cmt_text;
223
- }
224
-
225
- public function add_comment_post_type_filter() {
226
- ?>
227
- <label class="screen-reader-text"
228
- for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
229
- <select id="filter-by-comment-post-type" name="post_type">
230
- <?php
231
- $comment_post_types = apply_filters( 'learn_press_admin_comment_post_type_types_dropdown', array(
232
- '' => __( 'All post type', 'learnpress-course-review' ),
233
- 'lp_course' => __( 'Course comments', 'learnpress-course-review' ),
234
- ) );
235
-
236
- foreach ( $comment_post_types as $type => $label ) {
237
- echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
238
- } ?>
239
-
240
- </select>
241
- <?php
242
- }
243
-
244
-
245
- public function shortcode_review( $atts ) {
246
- $atts = shortcode_atts( array(
247
- 'course_id' => 0,
248
- 'show_rate' => 'yes',
249
- 'show_review' => 'yes',
250
- 'display_amount' => '5'
251
- ), $atts, 'shortcode_review' );
252
-
253
- $course_id = $atts['course_id'];
254
- if ( ! $course_id ) {
255
- $course_id = get_the_ID();
256
- }
257
-
258
- ob_start();
259
- if ( $atts['show_rate'] ) {
260
- $course_rate = learn_press_get_course_rate( $course_id, false );
261
- $total = learn_press_get_course_rate_total( $course_id, false );
262
- $rate_args = array(
263
- 'course_id' => $course_id,
264
- 'course_rate' => $course_rate,
265
- 'total' => $total
266
- );
267
- learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
268
- }
269
-
270
- if ( $atts['show_review'] ) {
271
- $course_review = learn_press_get_course_review( $course_id, 1, $atts['display_amount'] );
272
- learn_press_course_review_template( 'shortcode-course-review.php', array(
273
- 'course_id' => $course_id,
274
- 'course_review' => $course_review
275
- ) );
276
- }
277
-
278
- $content = ob_get_contents();
279
- ob_clean();
280
-
281
- return $content;
282
- }
283
-
284
- public function load_widget() {
285
- register_widget( 'LearnPress_Course_Review_Widget' );
286
- }
287
-
288
-
289
- public function add_course_tab_reviews( $tabs ) {
290
- $tabs['reviews'] = array(
291
- 'title' => __( 'Reviews', 'learnpress-course-review' ),
292
- 'priority' => 60,
293
- 'callback' => array( $this, 'add_course_tab_reviews_callback' )
294
- );
295
-
296
-
297
- return $tabs;
298
- }
299
-
300
- public function add_course_tab_reviews_callback() {
301
- $user = learn_press_get_current_user();
302
- $course_id = learn_press_get_course_id();
303
- $this->print_rate();
304
- $this->print_review();
305
- if ( $user->has_course_status( $course_id, array( 'enrolled', 'completed', 'finished' ) ) ) {
306
- $this->add_review_button();
307
- }
308
- }
309
-
310
- public function learnpress_is_active() {
311
- if ( ! function_exists( 'is_plugin_active' ) ) {
312
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
313
- }
314
-
315
- return is_plugin_active( 'learnpress/learnpress.php' );
316
- }
317
- }
318
- }
319
-
320
  add_action( 'plugins_loaded', array( 'LP_Addon_Course_Review', 'instance' ) );
1
+ <?php
2
+ /**
3
+ * Plugin load class.
4
+ *
5
+ * @author ThimPress
6
+ * @package LearnPress/Course-Review/Classes
7
+ * @version 3.0.1
8
+ */
9
+
10
+ // Prevent loading this file directly
11
+ defined( 'ABSPATH' ) || exit;
12
+
13
+ if ( ! function_exists( 'LP_Addon_Course_Review' ) ) {
14
+ /**
15
+ * Class LP_Addon_Course_Review.
16
+ */
17
+ class LP_Addon_Course_Review extends LP_Addon {
18
+
19
+ /**
20
+ * @var string
21
+ */
22
+ public $version = LP_ADDON_COURSE_REVIEW_VER;
23
+
24
+ /**
25
+ * @var string
26
+ */
27
+ public $require_version = LP_ADDON_COURSE_REVIEW_REQUIRE_VER;
28
+
29
+ /**
30
+ * @var string
31
+ */
32
+ private static $comment_type = 'review';
33
+
34
+ /**
35
+ * LP_Addon_Course_Review constructor.
36
+ */
37
+ public function __construct() {
38
+ parent::__construct();
39
+ add_action( 'widgets_init', array( $this, 'load_widget' ) );
40
+ }
41
+
42
+ /**
43
+ * Define Learnpress Course Review constants.
44
+ *
45
+ * @since 3.0.0
46
+ */
47
+ protected function _define_constants() {
48
+ define( 'LP_ADDON_COURSE_REVIEW_PATH', dirname( LP_ADDON_COURSE_REVIEW_FILE ) );
49
+ define( 'LP_ADDON_COURSE_REVIEW_PER_PAGE', 5 );
50
+ define( 'LP_ADDON_COURSE_REVIEW_TMPL', LP_ADDON_COURSE_REVIEW_PATH . '/templates/' );
51
+ define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
52
+ define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', dirname( __FILE__ ) ) ) );
53
+ }
54
+
55
+ /**
56
+ * Include required core files used in admin and on the frontend.
57
+ *
58
+ * @since 3.0.0
59
+ */
60
+ protected function _includes() {
61
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/inc/functions.php';
62
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/inc/widgets.php';
63
+ }
64
+
65
+ /**
66
+ * Init hooks.
67
+ */
68
+ protected function _init_hooks() {
69
+ add_filter( 'learn-press/course-tabs', array( $this, 'add_course_tab_reviews' ), 5 );
70
+
71
+ add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
72
+ add_action( 'wp', array( $this, 'course_review_init' ) );
73
+
74
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
75
+ LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
76
+ LP_Request_Handler::register_ajax( 'learnpress_load_course_review', array(
77
+ $this,
78
+ 'learnpress_load_course_review'
79
+ ) );
80
+ add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
81
+
82
+ $this->init_comment_table();
83
+ }
84
+
85
+ /**
86
+ * Get html of reviews
87
+ */
88
+ public function learnpress_load_course_review() {
89
+ $paged = LP_Request::get_post( 'paged', 1 ) ? (int) LP_Request::get_post( 'paged', 1 ) : 1;
90
+ $response = learn_press_get_course_review( get_the_ID(), $paged );
91
+ if ( $response['reviews'] && count( $response['reviews'] ) > 0 ) {
92
+ ob_start();
93
+ learn_press_course_review_template( 'course-review.php', array( 'review' => $response ) );
94
+ ob_end_clean();
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Print rate.
100
+ */
101
+ public function print_rate() {
102
+ learn_press_course_review_template( 'course-rate.php' );
103
+ }
104
+
105
+ /**
106
+ * Print review.
107
+ */
108
+ public function print_review() {
109
+ learn_press_course_review_template( 'course-review.php' );
110
+ }
111
+
112
+ /**
113
+ * Add review button.
114
+ */
115
+ public function add_review_button() {
116
+ if ( ! learn_press_get_user_rate( get_the_ID() ) ) {
117
+ learn_press_course_review_template( 'review-form.php' );
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Admin assets.
123
+ */
124
+ public function admin_enqueue_assets() {
125
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/admin.css' );
126
+ }
127
+
128
+ /**
129
+ * Single course assets.
130
+ */
131
+ public function review_assets() {
132
+ if ( learn_press_is_course() ) {
133
+ wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
134
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
135
+ wp_enqueue_style( 'dashicons' );
136
+ wp_localize_script( 'course-review', 'learn_press_course_review',
137
+ array(
138
+ 'localize' => array(
139
+ 'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
140
+ 'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
141
+ 'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
142
+ )
143
+ )
144
+ );
145
+ }
146
+ }
147
+
148
+ public function course_review_init() {
149
+ $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
150
+ learn_press_get_course_review( get_the_ID(), $paged );
151
+ }
152
+
153
+ public function exclude_rating( $query ) {
154
+ $query->query_vars['type__not_in'] = 'review';
155
+ }
156
+
157
+ public function add_review() {
158
+ $response = array( 'result' => 'success' );
159
+ $nonce = ! empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
160
+ $id = ! empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
161
+ $rate = ! empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
162
+ $title = ! empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
163
+ $content = ! empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
164
+
165
+ if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
166
+ $response['result'] = 'fail';
167
+ $response['message'] = __( 'Error', 'learnpress-course-review' );
168
+ }
169
+
170
+ if ( get_post_type( $id ) != 'lp_course' ) {
171
+ $response['result'] = 'fail';
172
+ $response['message'] = __( 'Invalid course', 'learnpress-course-review' );
173
+ }
174
+
175
+ $return = learn_press_add_course_review(
176
+ array(
177
+ 'user_id' => get_current_user_id(),
178
+ 'course_id' => $id,
179
+ 'rate' => $rate,
180
+ 'title' => $title,
181
+ 'content' => $content
182
+ )
183
+ );
184
+ $response['comment'] = $return;
185
+ learn_press_send_json( $response );
186
+ }
187
+
188
+ public function init_comment_table() {
189
+ add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
190
+ add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
191
+ add_filter( 'comment_row_actions', array( $this, 'edit_comment_row_actions' ), 10, 2 );
192
+ }
193
+
194
+ public function edit_comment_row_actions( $actions, $comment ) {
195
+ if ( ! $comment || $comment->comment_type != 'review' ) {
196
+ return $actions;
197
+ }
198
+ unset( $actions['reply'] );
199
+
200
+ return $actions;
201
+ }
202
+
203
+ public function add_comment_type_filter( $cmt_types ) {
204
+ $cmt_types[ self::$comment_type ] = __( 'Course review', 'learnpress-course-review' );
205
+
206
+ return $cmt_types;
207
+ }
208
+
209
+ public function add_comment_content_filter( $cmt_text ) {
210
+ global $comment;
211
+ if ( ! $comment || $comment->comment_type != 'review' ) {
212
+ return $cmt_text;
213
+ }
214
+
215
+ ob_start();
216
+ $rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
217
+ echo '<div class="course-rate">';
218
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
219
+ echo '</div>';
220
+ $cmt_text .= ob_get_clean();
221
+
222
+ return $cmt_text;
223
+ }
224
+
225
+ public function add_comment_post_type_filter() {
226
+ ?>
227
+ <label class="screen-reader-text"
228
+ for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
229
+ <select id="filter-by-comment-post-type" name="post_type">
230
+ <?php
231
+ $comment_post_types = apply_filters( 'learn_press_admin_comment_post_type_types_dropdown', array(
232
+ '' => __( 'All post type', 'learnpress-course-review' ),
233
+ 'lp_course' => __( 'Course comments', 'learnpress-course-review' ),
234
+ ) );
235
+
236
+ foreach ( $comment_post_types as $type => $label ) {
237
+ echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
238
+ } ?>
239
+
240
+ </select>
241
+ <?php
242
+ }
243
+
244
+
245
+ public function shortcode_review( $atts ) {
246
+ $atts = shortcode_atts( array(
247
+ 'course_id' => 0,
248
+ 'show_rate' => 'yes',
249
+ 'show_review' => 'yes',
250
+ 'display_amount' => '5'
251
+ ), $atts, 'shortcode_review' );
252
+
253
+ $course_id = $atts['course_id'];
254
+ if ( ! $course_id ) {
255
+ $course_id = get_the_ID();
256
+ }
257
+
258
+ ob_start();
259
+ if ( $atts['show_rate'] ) {
260
+ $course_rate = learn_press_get_course_rate( $course_id, false );
261
+ $total = learn_press_get_course_rate_total( $course_id, false );
262
+ $rate_args = array(
263
+ 'course_id' => $course_id,
264
+ 'course_rate' => $course_rate,
265
+ 'total' => $total
266
+ );
267
+ learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
268
+ }
269
+
270
+ if ( $atts['show_review'] ) {
271
+ $course_review = learn_press_get_course_review( $course_id, 1, $atts['display_amount'] );
272
+ learn_press_course_review_template( 'shortcode-course-review.php', array(
273
+ 'course_id' => $course_id,
274
+ 'course_review' => $course_review
275
+ ) );
276
+ }
277
+
278
+ $content = ob_get_contents();
279
+ ob_clean();
280
+
281
+ return $content;
282
+ }
283
+
284
+ public function load_widget() {
285
+ register_widget( 'LearnPress_Course_Review_Widget' );
286
+ }
287
+
288
+
289
+ public function add_course_tab_reviews( $tabs ) {
290
+ $tabs['reviews'] = array(
291
+ 'title' => __( 'Reviews', 'learnpress-course-review' ),
292
+ 'priority' => 60,
293
+ 'callback' => array( $this, 'add_course_tab_reviews_callback' )
294
+ );
295
+
296
+
297
+ return $tabs;
298
+ }
299
+
300
+ public function add_course_tab_reviews_callback() {
301
+ $user = learn_press_get_current_user();
302
+ $course_id = learn_press_get_course_id();
303
+ $this->print_rate();
304
+ $this->print_review();
305
+ if ( $user->has_course_status( $course_id, array( 'enrolled', 'completed', 'finished' ) ) ) {
306
+ $this->add_review_button();
307
+ }
308
+ }
309
+
310
+ public function learnpress_is_active() {
311
+ if ( ! function_exists( 'is_plugin_active' ) ) {
312
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
313
+ }
314
+
315
+ return is_plugin_active( 'learnpress/learnpress.php' );
316
+ }
317
+ }
318
+ }
319
+
320
  add_action( 'plugins_loaded', array( 'LP_Addon_Course_Review', 'instance' ) );
inc/widgets.php CHANGED
@@ -1,225 +1,225 @@
1
- <?php
2
- /**
3
- * Course review widget class.
4
- *
5
- * @author ThimPress
6
- * @package LearnPress/Course-Review/Classes
7
- * @version 3.0.2
8
- */
9
-
10
- // Prevent loading this file directly
11
- defined( 'ABSPATH' ) || exit;
12
-
13
- // Creating the widget
14
- class LearnPress_Course_Review_Widget extends WP_Widget {
15
-
16
- function __construct() {
17
- parent::__construct(
18
- 'lpr_course_review',
19
- __( 'LearnPress - Course Review', 'learnpress-course-review' ),
20
- array( 'description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ), )
21
- );
22
- add_action( 'wp_ajax_learnpress_reviews_search_course', array(
23
- __CLASS__,
24
- 'learnpress_reviews_search_course'
25
- ) );
26
-
27
- add_action( 'admin_footer', array( $this, 'footer_js' ) );
28
- }
29
-
30
- /**
31
- *
32
- */
33
- public static function learnpress_reviews_search_course() {
34
- $return = array();
35
-
36
- // you can use WP_Query, query_posts() or get_posts() here - it doesn't matter
37
- $search_results = new WP_Query( array(
38
- 's' => $_GET['q'], // the search query
39
- 'post_status' => 'publish', // if you don't want drafts to be returned
40
- 'ignore_sticky_posts' => 1,
41
- 'post_type' => LP_COURSE_CPT,
42
- 'posts_per_page' => 50 // how much to show at once
43
- ) );
44
- if ( $search_results->have_posts() ) :
45
- while ( $search_results->have_posts() ) : $search_results->the_post();
46
- // shorten the title a little
47
- $title = ( mb_strlen( $search_results->post->post_title ) > 50 ) ? mb_substr( $search_results->post->post_title, 0, 49 ) . '...' : $search_results->post->post_title;
48
- $return[] = array( $search_results->post->ID, $title ); // array( Post ID, Post Title )
49
- endwhile;
50
- endif;
51
- echo json_encode( $return );
52
- die;
53
- }
54
-
55
- /**
56
- * @param array $args
57
- * @param array $instance
58
- */
59
- public function widget( $args, $instance ) {
60
- wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
61
- wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
62
- $title = apply_filters( 'widget_title', $instance['title'] );
63
- echo $args['before_widget'];
64
-
65
- if ( ! empty( $title ) ) {
66
- echo $args['before_title'] . $title . $args['after_title'];
67
- }
68
-
69
- $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : 0;
70
- $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
71
- $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
72
- $display_amount = isset( $instance['display_amount'] ) ? $instance['display_amount'] : 5;
73
-
74
- if ( ! $course_id ) {
75
- $course_id = get_the_ID();
76
- }
77
-
78
- ob_start();
79
- if ( $show_rate == 'yes' ) {
80
- $course_rate = learn_press_get_course_rate( $course_id, false );
81
- $rate_args = array(
82
- 'course_id' => $course_id
83
- ,
84
- 'course_rate' => $course_rate
85
- );
86
- learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
87
- }
88
-
89
- if ( $show_review == 'yes' ) {
90
- $course_review = learn_press_get_course_review( $course_id, 1, $display_amount );
91
- learn_press_course_review_template( 'shortcode-course-review.php', array(
92
- 'course_id' => $course_id,
93
- 'course_review' => $course_review
94
- ) );
95
- }
96
-
97
- $content = ob_get_contents();
98
- ob_clean();
99
- echo $content;
100
- echo $args['after_widget'];
101
- }
102
-
103
- public function form( $instance ) {
104
- $title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'wpb_widget_domain' );
105
- $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : '';
106
- $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
107
- $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
108
- $display_amount = isset( $instance['display_amount'] ) ? $instance['display_amount'] : 5;
109
- if ( $course_id ) {
110
- $checked = "selected='selected'";
111
- $review_title = get_the_title( $course_id );
112
- $option = "<option value='{$course_id}' {$checked}>{$review_title}</option>";
113
- } else {
114
- $option = "<option value='0'>" . __( 'Pick up 1 course', 'learnpress-course-review' ) . "</option>";
115
- }
116
- // Reset Post Data
117
- wp_reset_postdata();
118
- wp_enqueue_script( 'select2' );
119
-
120
- ?>
121
- <p>
122
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'learnpress-course-review' ); ?></label>
123
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
124
- name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
125
- value="<?php echo esc_attr( $title ); ?>"/>
126
- </p>
127
- <div class="rwmb-input">
128
- <label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:', 'learnpress-course-review' ); ?></label>
129
- <select class="rwmb-select " name="<?php echo $this->get_field_name( 'course_id' ); ?>"
130
- id="<?php echo $this->get_field_id( 'course_id' ); ?>">
131
- <?php echo $option; ?>
132
- </select>
133
- </div>
134
- <p>
135
- <label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:', 'learnpress-course-review' ); ?></label>
136
- <input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>"
137
- name="<?php echo $this->get_field_name( 'show_rate' ); ?>" type="checkbox"
138
- value="yes" <?php checked( $show_rate, 'yes', true ); ?>/>
139
- </p>
140
- <p>
141
- <label for="<?php echo $this->get_field_id( 'show_review' ); ?>"><?php _e( 'Show Review:', 'learnpress-course-review' ); ?></label>
142
- <input class="widefat" id="<?php echo $this->get_field_id( 'show_review' ); ?>"
143
- name="<?php echo $this->get_field_name( 'show_review' ); ?>" type="checkbox"
144
- value="yes" <?php checked( $show_review, 'yes', true ); ?> />
145
- </p>
146
- <p>
147
- <label for="<?php echo $this->get_field_id( 'display_amount' ); ?>"><?php _e( 'Amount Display:', 'learnpress-course-review' ); ?></label>
148
- <input class="widefat" id="<?php echo $this->get_field_id( 'display_amount' ); ?>"
149
- name="<?php echo $this->get_field_name( 'display_amount' ); ?>" type="number"
150
- value="<?php echo esc_attr( $display_amount ); ?>"/>
151
- </p>
152
-
153
- <?php
154
- }
155
-
156
- // Updating widget replacing old instances with new
157
- public function update( $new_instance, $old_instance ) {
158
- $instance = $old_instance;
159
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
160
- $instance['course_id'] = ( ! empty( $new_instance['course_id'] ) ) ? strip_tags( $new_instance['course_id'] ) : '';
161
- $instance['show_rate'] = ( ! empty( $new_instance['show_rate'] ) ) ? strip_tags( $new_instance['show_rate'] ) : '';
162
- $instance['show_review'] = ( ! empty( $new_instance['show_review'] ) ) ? strip_tags( $new_instance['show_review'] ) : '';
163
- $instance['display_amount'] = ( ! empty( $new_instance['display_amount'] ) ) ? strip_tags( $new_instance['display_amount'] ) : 5;
164
-
165
- return $instance;
166
- }
167
-
168
- public function footer_js() {
169
- ?>
170
- <script>
171
- jQuery(function ($) {
172
- function initWidget(widget) {
173
- $(widget).find('select[id*="course_id"]').select2({
174
- placeholder: '<?php esc_attr_e( 'Select a course', 'learnpress-course-review' );?>',
175
- minimumInputLength: 3,
176
- ajax: {
177
- url: ajaxurl,
178
- dataType: 'json',
179
- quietMillis: 250,
180
- data: function (params) {
181
- return {
182
- q: params.term, // search term
183
- action: 'learnpress_reviews_search_course'
184
- };
185
- },
186
- processResults: function (data) {
187
- var options = [];
188
- if (data) {
189
-
190
- // data is the array of arrays, and each of them contains ID and the Label of the option
191
- $.each(data, function (index, text) { // do not forget that "index" is just auto incremented value
192
- options.push({id: text[0], text: text[1]});
193
- });
194
-
195
- }
196
- return {
197
- results: options
198
- };
199
- },
200
- cache: true
201
- },
202
- language: {
203
- noResults: function (params) {
204
- return '<?php esc_attr_e( 'There is no course to select.', 'learnpress-course-review' );?>';
205
- }
206
- }
207
- });
208
- }
209
-
210
- // Init select2 on widgets are existed
211
- $('#widgets-right').find('[id*="_lpr_course_review"]').each(function () {
212
- initWidget(this);
213
- })
214
-
215
- // Init select2 on new widget after added to sidebar
216
- // Or after press Save button
217
- $(document).on('widget-updated widget-added', function (e, el) {
218
- initWidget(el);
219
- });
220
- });
221
- </script>
222
- <?php
223
- }
224
-
225
  }
1
+ <?php
2
+ /**
3
+ * Course review widget class.
4
+ *
5
+ * @author ThimPress
6
+ * @package LearnPress/Course-Review/Classes
7
+ * @version 3.0.2
8
+ */
9
+
10
+ // Prevent loading this file directly
11
+ defined( 'ABSPATH' ) || exit;
12
+
13
+ // Creating the widget
14
+ class LearnPress_Course_Review_Widget extends WP_Widget {
15
+
16
+ function __construct() {
17
+ parent::__construct(
18
+ 'lpr_course_review',
19
+ __( 'LearnPress - Course Review', 'learnpress-course-review' ),
20
+ array( 'description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ), )
21
+ );
22
+ add_action( 'wp_ajax_learnpress_reviews_search_course', array(
23
+ __CLASS__,
24
+ 'learnpress_reviews_search_course'
25
+ ) );
26
+
27
+ add_action( 'admin_footer', array( $this, 'footer_js' ) );
28
+ }
29
+
30
+ /**
31
+ *
32
+ */
33
+ public static function learnpress_reviews_search_course() {
34
+ $return = array();
35
+
36
+ // you can use WP_Query, query_posts() or get_posts() here - it doesn't matter
37
+ $search_results = new WP_Query( array(
38
+ 's' => $_GET['q'], // the search query
39
+ 'post_status' => 'publish', // if you don't want drafts to be returned
40
+ 'ignore_sticky_posts' => 1,
41
+ 'post_type' => LP_COURSE_CPT,
42
+ 'posts_per_page' => 50 // how much to show at once
43
+ ) );
44
+ if ( $search_results->have_posts() ) :
45
+ while ( $search_results->have_posts() ) : $search_results->the_post();
46
+ // shorten the title a little
47
+ $title = ( mb_strlen( $search_results->post->post_title ) > 50 ) ? mb_substr( $search_results->post->post_title, 0, 49 ) . '...' : $search_results->post->post_title;
48
+ $return[] = array( $search_results->post->ID, $title ); // array( Post ID, Post Title )
49
+ endwhile;
50
+ endif;
51
+ echo json_encode( $return );
52
+ die;
53
+ }
54
+
55
+ /**
56
+ * @param array $args
57
+ * @param array $instance
58
+ */
59
+ public function widget( $args, $instance ) {
60
+ wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
61
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
62
+ $title = apply_filters( 'widget_title', $instance['title'] );
63
+ echo $args['before_widget'];
64
+
65
+ if ( ! empty( $title ) ) {
66
+ echo $args['before_title'] . $title . $args['after_title'];
67
+ }
68
+
69
+ $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : 0;
70
+ $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
71
+ $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
72
+ $display_amount = isset( $instance['display_amount'] ) ? $instance['display_amount'] : 5;
73
+
74
+ if ( ! $course_id ) {
75
+ $course_id = get_the_ID();
76
+ }
77
+
78
+ ob_start();
79
+ if ( $show_rate == 'yes' ) {
80
+ $course_rate = learn_press_get_course_rate( $course_id, false );
81
+ $rate_args = array(
82
+ 'course_id' => $course_id
83
+ ,
84
+ 'course_rate' => $course_rate
85
+ );
86
+ learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
87
+ }
88
+
89
+ if ( $show_review == 'yes' ) {
90
+ $course_review = learn_press_get_course_review( $course_id, 1, $display_amount );
91
+ learn_press_course_review_template( 'shortcode-course-review.php', array(
92
+ 'course_id' => $course_id,
93
+ 'course_review' => $course_review
94
+ ) );
95
+ }
96
+
97
+ $content = ob_get_contents();
98
+ ob_clean();
99
+ echo $content;
100
+ echo $args['after_widget'];
101
+ }
102
+
103
+ public function form( $instance ) {
104
+ $title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'wpb_widget_domain' );
105
+ $course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : '';
106
+ $show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
107
+ $show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
108
+ $display_amount = isset( $instance['display_amount'] ) ? $instance['display_amount'] : 5;
109
+ if ( $course_id ) {
110
+ $checked = "selected='selected'";
111
+ $review_title = get_the_title( $course_id );
112
+ $option = "<option value='{$course_id}' {$checked}>{$review_title}</option>";
113
+ } else {
114
+ $option = "<option value='0'>" . __( 'Pick up 1 course', 'learnpress-course-review' ) . "</option>";
115
+ }
116
+ // Reset Post Data
117
+ wp_reset_postdata();
118
+ wp_enqueue_script( 'select2' );
119
+
120
+ ?>
121
+ <p>
122
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'learnpress-course-review' ); ?></label>
123
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
124
+ name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
125
+ value="<?php echo esc_attr( $title ); ?>"/>
126
+ </p>
127
+ <div class="rwmb-input">
128
+ <label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:', 'learnpress-course-review' ); ?></label>
129
+ <select class="rwmb-select " name="<?php echo $this->get_field_name( 'course_id' ); ?>"
130
+ id="<?php echo $this->get_field_id( 'course_id' ); ?>">
131
+ <?php echo $option; ?>
132
+ </select>
133
+ </div>
134
+ <p>
135
+ <label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:', 'learnpress-course-review' ); ?></label>
136
+ <input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>"
137
+ name="<?php echo $this->get_field_name( 'show_rate' ); ?>" type="checkbox"
138
+ value="yes" <?php checked( $show_rate, 'yes', true ); ?>/>
139
+ </p>
140
+ <p>
141
+ <label for="<?php echo $this->get_field_id( 'show_review' ); ?>"><?php _e( 'Show Review:', 'learnpress-course-review' ); ?></label>
142
+ <input class="widefat" id="<?php echo $this->get_field_id( 'show_review' ); ?>"
143
+ name="<?php echo $this->get_field_name( 'show_review' ); ?>" type="checkbox"
144
+ value="yes" <?php checked( $show_review, 'yes', true ); ?> />
145
+ </p>
146
+ <p>
147
+ <label for="<?php echo $this->get_field_id( 'display_amount' ); ?>"><?php _e( 'Amount Display:', 'learnpress-course-review' ); ?></label>
148
+ <input class="widefat" id="<?php echo $this->get_field_id( 'display_amount' ); ?>"
149
+ name="<?php echo $this->get_field_name( 'display_amount' ); ?>" type="number"
150
+ value="<?php echo esc_attr( $display_amount ); ?>"/>
151
+ </p>
152
+
153
+ <?php
154
+ }
155
+
156
+ // Updating widget replacing old instances with new
157
+ public function update( $new_instance, $old_instance ) {
158
+ $instance = $old_instance;
159
+ $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
160
+ $instance['course_id'] = ( ! empty( $new_instance['course_id'] ) ) ? strip_tags( $new_instance['course_id'] ) : '';
161
+ $instance['show_rate'] = ( ! empty( $new_instance['show_rate'] ) ) ? strip_tags( $new_instance['show_rate'] ) : '';
162
+ $instance['show_review'] = ( ! empty( $new_instance['show_review'] ) ) ? strip_tags( $new_instance['show_review'] ) : '';
163
+ $instance['display_amount'] = ( ! empty( $new_instance['display_amount'] ) ) ? strip_tags( $new_instance['display_amount'] ) : 5;
164
+
165
+ return $instance;
166
+ }
167
+
168
+ public function footer_js() {
169
+ ?>
170
+ <script>
171
+ jQuery(function ($) {
172
+ function initWidget(widget) {
173
+ $(widget).find('select[id*="course_id"]').select2({
174
+ placeholder: '<?php esc_attr_e( 'Select a course', 'learnpress-course-review' );?>',
175
+ minimumInputLength: 3,
176
+ ajax: {
177
+ url: ajaxurl,
178
+ dataType: 'json',
179
+ quietMillis: 250,
180
+ data: function (params) {
181
+ return {
182
+ q: params.term, // search term
183
+ action: 'learnpress_reviews_search_course'
184
+ };
185
+ },
186
+ processResults: function (data) {
187
+ var options = [];
188
+ if (data) {
189
+
190
+ // data is the array of arrays, and each of them contains ID and the Label of the option
191
+ $.each(data, function (index, text) { // do not forget that "index" is just auto incremented value
192
+ options.push({id: text[0], text: text[1]});
193
+ });
194
+
195
+ }
196
+ return {
197
+ results: options
198
+ };
199
+ },
200
+ cache: true
201
+ },
202
+ language: {
203
+ noResults: function (params) {
204
+ return '<?php esc_attr_e( 'There is no course to select.', 'learnpress-course-review' );?>';
205
+ }
206
+ }
207
+ });
208
+ }
209
+
210
+ // Init select2 on widgets are existed
211
+ $('#widgets-right').find('[id*="_lpr_course_review"]').each(function () {
212
+ initWidget(this);
213
+ })
214
+
215
+ // Init select2 on new widget after added to sidebar
216
+ // Or after press Save button
217
+ $(document).on('widget-updated widget-added', function (e, el) {
218
+ initWidget(el);
219
+ });
220
+ });
221
+ </script>
222
+ <?php
223
+ }
224
+
225
  }
languages/learnpress-course-review-vi.po CHANGED
@@ -1,99 +1,99 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: PACKAGE VERSION\n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2016-03-18 16:57+0700\n"
6
- "PO-Revision-Date: Fri Mar 18 2016 16:58:45 GMT+0700 (SE Asia Standard Time)\n"
7
- "Last-Translator: Nguyễn Ngọc Tú <tunnhn@gmail.com>\n"
8
- "Language-Team: LANGUAGE <LL@li.org>\n"
9
- "Language: Vietnamese\n"
10
- "Plural-Forms: nplurals=1; plural=0\n"
11
- "MIME-Version: 1.0\n"
12
- "Content-Type: text/plain; charset=CHARSET\n"
13
- "Content-Transfer-Encoding: 8bit\n"
14
- "X-Poedit-SourceCharset: UTF-8\n"
15
- "X-Poedit-Basepath: .\n"
16
- "X-Poedit-SearchPath-0: ..\n"
17
- "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
18
- "__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
19
- "_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
20
- "esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
21
- "esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
22
- "X-Loco-Target-Locale: vi_VN\n"
23
- "X-Generator: Loco - https://localise.biz/"
24
-
25
- #: learnpress-course-review.php:109
26
- msgid "Error"
27
- msgstr ""
28
-
29
- #: learnpress-course-review.php:114
30
- msgid "Invalid course"
31
- msgstr ""
32
-
33
- #: templates/course-rate.php:13
34
- #, php-format
35
- msgid "%d rating"
36
- msgid_plural "%d ratings"
37
- msgstr[0] ""
38
- msgstr[1] ""
39
-
40
- #: templates/course-review.php:12
41
- msgid "Reviews"
42
- msgstr "Đánh giá"
43
-
44
- #: templates/course-review.php:13
45
- #, php-format
46
- msgid "Average rate: <span>%.1f</span>"
47
- msgstr ""
48
-
49
- #: templates/course-review.php:21
50
- msgid "Loading..."
51
- msgstr ""
52
-
53
- #: templates/course-review.php:24
54
- msgid "No review to load"
55
- msgstr ""
56
-
57
- #: templates/course-review.php:27
58
- msgid "Load More"
59
- msgstr ""
60
-
61
- #: templates/review-form.php:12 templates/review-form.php:18
62
- msgid "Write a review"
63
- msgstr ""
64
-
65
- #: templates/review-form.php:24
66
- msgid "Title"
67
- msgstr ""
68
-
69
- #: templates/review-form.php:28
70
- msgid "Content"
71
- msgstr ""
72
-
73
- #: templates/review-form.php:32
74
- msgid "Rating"
75
- msgstr ""
76
-
77
- #: templates/review-form.php:42
78
- msgid "Add review"
79
- msgstr ""
80
-
81
- #: templates/review-form.php:43
82
- msgid "Cancel"
83
- msgstr ""
84
-
85
- #: learnpress-course-review.php:80
86
- msgid "Please enter the review title"
87
- msgstr "Nhập vào tiêu đề"
88
-
89
- #: learnpress-course-review.php:81
90
- msgid "Please enter the review content"
91
- msgstr "Nhập vào nội dung"
92
-
93
- #: learnpress-course-review.php:82
94
- msgid "Please select your rating"
95
- msgstr "Chọn điểm"
96
-
97
- #: templates/review-form.php:44
98
- msgid "Please wait..."
99
- msgstr "Chờ trong giây lát..."
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: PACKAGE VERSION\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2016-03-18 16:57+0700\n"
6
+ "PO-Revision-Date: Fri Mar 18 2016 16:58:45 GMT+0700 (SE Asia Standard Time)\n"
7
+ "Last-Translator: Nguyễn Ngọc Tú <tunnhn@gmail.com>\n"
8
+ "Language-Team: LANGUAGE <LL@li.org>\n"
9
+ "Language: Vietnamese\n"
10
+ "Plural-Forms: nplurals=1; plural=0\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=CHARSET\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-Basepath: .\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+ "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
18
+ "__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
19
+ "_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
20
+ "esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
21
+ "esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
22
+ "X-Loco-Target-Locale: vi_VN\n"
23
+ "X-Generator: Loco - https://localise.biz/"
24
+
25
+ #: learnpress-course-review.php:109
26
+ msgid "Error"
27
+ msgstr ""
28
+
29
+ #: learnpress-course-review.php:114
30
+ msgid "Invalid course"
31
+ msgstr ""
32
+
33
+ #: templates/course-rate.php:13
34
+ #, php-format
35
+ msgid "%d rating"
36
+ msgid_plural "%d ratings"
37
+ msgstr[0] ""
38
+ msgstr[1] ""
39
+
40
+ #: templates/course-review.php:12
41
+ msgid "Reviews"
42
+ msgstr "Đánh giá"
43
+
44
+ #: templates/course-review.php:13
45
+ #, php-format
46
+ msgid "Average rate: <span>%.1f</span>"
47
+ msgstr ""
48
+
49
+ #: templates/course-review.php:21
50
+ msgid "Loading..."
51
+ msgstr ""
52
+
53
+ #: templates/course-review.php:24
54
+ msgid "No review to load"
55
+ msgstr ""
56
+
57
+ #: templates/course-review.php:27
58
+ msgid "Load More"
59
+ msgstr ""
60
+
61
+ #: templates/review-form.php:12 templates/review-form.php:18
62
+ msgid "Write a review"
63
+ msgstr ""
64
+
65
+ #: templates/review-form.php:24
66
+ msgid "Title"
67
+ msgstr ""
68
+
69
+ #: templates/review-form.php:28
70
+ msgid "Content"
71
+ msgstr ""
72
+
73
+ #: templates/review-form.php:32
74
+ msgid "Rating"
75
+ msgstr ""
76
+
77
+ #: templates/review-form.php:42
78
+ msgid "Add review"
79
+ msgstr ""
80
+
81
+ #: templates/review-form.php:43
82
+ msgid "Cancel"
83
+ msgstr ""
84
+
85
+ #: learnpress-course-review.php:80
86
+ msgid "Please enter the review title"
87
+ msgstr "Nhập vào tiêu đề"
88
+
89
+ #: learnpress-course-review.php:81
90
+ msgid "Please enter the review content"
91
+ msgstr "Nhập vào nội dung"
92
+
93
+ #: learnpress-course-review.php:82
94
+ msgid "Please select your rating"
95
+ msgstr "Chọn điểm"
96
+
97
+ #: templates/review-form.php:44
98
+ msgid "Please wait..."
99
+ msgstr "Chờ trong giây lát..."
languages/learnpress-course-review.pot CHANGED
@@ -1,196 +1,196 @@
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: 2019-05-16 11: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:52
22
- #, php-format
23
- msgid ""
24
- "<strong>%s</strong> addon version %s requires %s version %s or higher is "
25
- "<strong>installed</strong> and <strong>activated</strong>."
26
- msgstr ""
27
-
28
- #: learnpress-course-review.php:53
29
- msgid "LearnPress Course Review"
30
- msgstr ""
31
-
32
- #: learnpress-course-review.php:55
33
- msgid "LearnPress"
34
- msgstr ""
35
-
36
- #: inc/load.php:139
37
- msgid "Please enter the review title"
38
- msgstr ""
39
-
40
- #: inc/load.php:140
41
- msgid "Please enter the review content"
42
- msgstr ""
43
-
44
- #: inc/load.php:141
45
- msgid "Please select your rating"
46
- msgstr ""
47
-
48
- #: inc/load.php:167
49
- msgid "Error"
50
- msgstr ""
51
-
52
- #: inc/load.php:172
53
- msgid "Invalid course"
54
- msgstr ""
55
-
56
- #: inc/load.php:204
57
- msgid "Course review"
58
- msgstr ""
59
-
60
- #: inc/load.php:228
61
- msgid "Filter by post type"
62
- msgstr ""
63
-
64
- #: inc/load.php:232
65
- msgid "All post type"
66
- msgstr ""
67
-
68
- #: inc/load.php:233
69
- msgid "Course comments"
70
- msgstr ""
71
-
72
- #: inc/load.php:291 templates/course-review.php:21
73
- #: templates/shortcode-course-review.php:21
74
- msgid "Reviews"
75
- msgstr ""
76
-
77
- #: inc/widgets.php:19
78
- msgid "LearnPress - Course Review"
79
- msgstr ""
80
-
81
- #: inc/widgets.php:20
82
- msgid "Display ratings and reviews of course"
83
- msgstr ""
84
-
85
- #: inc/widgets.php:104
86
- msgid "New title"
87
- msgstr ""
88
-
89
- #: inc/widgets.php:114
90
- msgid "Pick up 1 course"
91
- msgstr ""
92
-
93
- #: inc/widgets.php:122
94
- msgid "Title:"
95
- msgstr ""
96
-
97
- #: inc/widgets.php:128
98
- msgid "Course Id:"
99
- msgstr ""
100
-
101
- #: inc/widgets.php:135
102
- msgid "Show Rate:"
103
- msgstr ""
104
-
105
- #: inc/widgets.php:141
106
- msgid "Show Review:"
107
- msgstr ""
108
-
109
- #: inc/widgets.php:147
110
- msgid "Amount Display:"
111
- msgstr ""
112
-
113
- #: inc/widgets.php:174
114
- msgid "Select a course"
115
- msgstr ""
116
-
117
- #: inc/widgets.php:204
118
- msgid "There is no course to select."
119
- msgstr ""
120
-
121
- #: templates/course-rate.php:27
122
- #, php-format
123
- msgid " %1.2f average based on "
124
- msgstr ""
125
-
126
- #: templates/course-rate.php:28
127
- #, php-format
128
- msgid " %d rating"
129
- msgid_plural "%d ratings"
130
- msgstr[0] ""
131
- msgstr[1] ""
132
-
133
- #: templates/course-rate.php:37
134
- msgid " Star"
135
- msgstr ""
136
-
137
- #: templates/course-review.php:28
138
- msgid "Loading..."
139
- msgstr ""
140
-
141
- #: templates/course-review.php:35
142
- msgid "Load More"
143
- msgstr ""
144
-
145
- #: templates/rating-stars.php:17
146
- #, php-format
147
- msgid "%s out of 5 stars"
148
- msgstr ""
149
-
150
- #: templates/review-form.php:16 templates/review-form.php:23
151
- msgid "Write a review"
152
- msgstr ""
153
-
154
- #: templates/review-form.php:29
155
- msgid "Title"
156
- msgstr ""
157
-
158
- #: templates/review-form.php:33
159
- msgid "Content"
160
- msgstr ""
161
-
162
- #: templates/review-form.php:37
163
- msgid "Rating"
164
- msgstr ""
165
-
166
- #: templates/review-form.php:48
167
- msgid "Add review"
168
- msgstr ""
169
-
170
- #: templates/review-form.php:50
171
- msgid "Cancel"
172
- msgstr ""
173
-
174
- #: templates/shortcode-course-rate.php:23
175
- #, php-format
176
- msgid "%d rating"
177
- msgid_plural "%d ratings"
178
- msgstr[0] ""
179
- msgstr[1] ""
180
-
181
- #: templates/shortcode-course-rate.php:36
182
- msgid "Star"
183
- msgstr ""
184
-
185
- #: templates/shortcode-course-rate.php:37
186
- msgid "Rate"
187
- msgstr ""
188
-
189
- #: templates/shortcode-course-review.php:22
190
- #, php-format
191
- msgid "Average rate: <span>%.1f</span>"
192
- msgstr ""
193
-
194
- #: templates/shortcode-course-review.php:31
195
- msgid "No review to load"
196
- 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: 2019-05-16 11: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:52
22
+ #, php-format
23
+ msgid ""
24
+ "<strong>%s</strong> addon version %s requires %s version %s or higher is "
25
+ "<strong>installed</strong> and <strong>activated</strong>."
26
+ msgstr ""
27
+
28
+ #: learnpress-course-review.php:53
29
+ msgid "LearnPress Course Review"
30
+ msgstr ""
31
+
32
+ #: learnpress-course-review.php:55
33
+ msgid "LearnPress"
34
+ msgstr ""
35
+
36
+ #: inc/load.php:139
37
+ msgid "Please enter the review title"
38
+ msgstr ""
39
+
40
+ #: inc/load.php:140
41
+ msgid "Please enter the review content"
42
+ msgstr ""
43
+
44
+ #: inc/load.php:141
45
+ msgid "Please select your rating"
46
+ msgstr ""
47
+
48
+ #: inc/load.php:167
49
+ msgid "Error"
50
+ msgstr ""
51
+
52
+ #: inc/load.php:172
53
+ msgid "Invalid course"
54
+ msgstr ""
55
+
56
+ #: inc/load.php:204
57
+ msgid "Course review"
58
+ msgstr ""
59
+
60
+ #: inc/load.php:228
61
+ msgid "Filter by post type"
62
+ msgstr ""
63
+
64
+ #: inc/load.php:232
65
+ msgid "All post type"
66
+ msgstr ""
67
+
68
+ #: inc/load.php:233
69
+ msgid "Course comments"
70
+ msgstr ""
71
+
72
+ #: inc/load.php:291 templates/course-review.php:21
73
+ #: templates/shortcode-course-review.php:21
74
+ msgid "Reviews"
75
+ msgstr ""
76
+
77
+ #: inc/widgets.php:19
78
+ msgid "LearnPress - Course Review"
79
+ msgstr ""
80
+
81
+ #: inc/widgets.php:20
82
+ msgid "Display ratings and reviews of course"
83
+ msgstr ""
84
+
85
+ #: inc/widgets.php:104
86
+ msgid "New title"
87
+ msgstr ""
88
+
89
+ #: inc/widgets.php:114
90
+ msgid "Pick up 1 course"
91
+ msgstr ""
92
+
93
+ #: inc/widgets.php:122
94
+ msgid "Title:"
95
+ msgstr ""
96
+
97
+ #: inc/widgets.php:128
98
+ msgid "Course Id:"
99
+ msgstr ""
100
+
101
+ #: inc/widgets.php:135
102
+ msgid "Show Rate:"
103
+ msgstr ""
104
+
105
+ #: inc/widgets.php:141
106
+ msgid "Show Review:"
107
+ msgstr ""
108
+
109
+ #: inc/widgets.php:147
110
+ msgid "Amount Display:"
111
+ msgstr ""
112
+
113
+ #: inc/widgets.php:174
114
+ msgid "Select a course"
115
+ msgstr ""
116
+
117
+ #: inc/widgets.php:204
118
+ msgid "There is no course to select."
119
+ msgstr ""
120
+
121
+ #: templates/course-rate.php:27
122
+ #, php-format
123
+ msgid " %1.2f average based on "
124
+ msgstr ""
125
+
126
+ #: templates/course-rate.php:28
127
+ #, php-format
128
+ msgid " %d rating"
129
+ msgid_plural "%d ratings"
130
+ msgstr[0] ""
131
+ msgstr[1] ""
132
+
133
+ #: templates/course-rate.php:37
134
+ msgid " Star"
135
+ msgstr ""
136
+
137
+ #: templates/course-review.php:28
138
+ msgid "Loading..."
139
+ msgstr ""
140
+
141
+ #: templates/course-review.php:35
142
+ msgid "Load More"
143
+ msgstr ""
144
+
145
+ #: templates/rating-stars.php:17
146
+ #, php-format
147
+ msgid "%s out of 5 stars"
148
+ msgstr ""
149
+
150
+ #: templates/review-form.php:16 templates/review-form.php:23
151
+ msgid "Write a review"
152
+ msgstr ""
153
+
154
+ #: templates/review-form.php:29
155
+ msgid "Title"
156
+ msgstr ""
157
+
158
+ #: templates/review-form.php:33
159
+ msgid "Content"
160
+ msgstr ""
161
+
162
+ #: templates/review-form.php:37
163
+ msgid "Rating"
164
+ msgstr ""
165
+
166
+ #: templates/review-form.php:48
167
+ msgid "Add review"
168
+ msgstr ""
169
+
170
+ #: templates/review-form.php:50
171
+ msgid "Cancel"
172
+ msgstr ""
173
+
174
+ #: templates/shortcode-course-rate.php:23
175
+ #, php-format
176
+ msgid "%d rating"
177
+ msgid_plural "%d ratings"
178
+ msgstr[0] ""
179
+ msgstr[1] ""
180
+
181
+ #: templates/shortcode-course-rate.php:36
182
+ msgid "Star"
183
+ msgstr ""
184
+
185
+ #: templates/shortcode-course-rate.php:37
186
+ msgid "Rate"
187
+ msgstr ""
188
+
189
+ #: templates/shortcode-course-review.php:22
190
+ #, php-format
191
+ msgid "Average rate: <span>%.1f</span>"
192
+ msgstr ""
193
+
194
+ #: templates/shortcode-course-review.php:31
195
+ msgid "No review to load"
196
+ 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,72 +1,72 @@
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: 3.0.4
8
- Author URI: http://thimpress.com
9
- Tags: learnpress
10
- Requires at least: 3.8
11
- Tested up to: 5.2
12
- Text Domain: learnpress-course-review
13
- Domain Path: /languages/
14
- */
15
-
16
- // Prevent loading this file directly
17
- defined( 'ABSPATH' ) || exit;
18
-
19
- define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
20
- define( 'LP_ADDON_COURSE_REVIEW_VER', '3.0.4' );
21
- define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '3.0.0' );
22
-
23
- /**
24
- * Class LP_Addon_Course_Review_Preload
25
- */
26
- class LP_Addon_Course_Review_Preload {
27
-
28
- /**
29
- * LP_Addon_Course_Review_Preload constructor.
30
- */
31
- public function __construct() {
32
- add_action( 'learn-press/ready', array( $this, 'load' ) );
33
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
34
- }
35
-
36
- /**
37
- * Load addon
38
- */
39
- public function load() {
40
- LP_Addon::load( 'LP_Addon_Course_Review', 'inc/load.php', __FILE__ );
41
- remove_action( 'admin_notices', array( $this, 'admin_notices' ) );
42
- }
43
-
44
- /**
45
- * Admin notice
46
- */
47
- public function admin_notices() {
48
- ?>
49
- <div class="error">
50
- <p><?php echo wp_kses(
51
- sprintf(
52
- __( '<strong>%s</strong> addon version %s requires %s version %s or higher is <strong>installed</strong> and <strong>activated</strong>.', 'learnpress-course-review' ),
53
- __( 'LearnPress Course Review', 'learnpress-course-review' ),
54
- LP_ADDON_COURSE_REVIEW_VER,
55
- sprintf( '<a href="%s" target="_blank"><strong>%s</strong></a>', admin_url( 'plugin-install.php?tab=search&type=term&s=learnpress' ), __( 'LearnPress', 'learnpress-course-review' ) ),
56
- LP_ADDON_COURSE_REVIEW_REQUIRE_VER
57
- ),
58
- array(
59
- 'a' => array(
60
- 'href' => array(),
61
- 'blank' => array()
62
- ),
63
- 'strong' => array()
64
- )
65
- ); ?>
66
- </p>
67
- </div>
68
- <?php
69
- }
70
- }
71
-
72
  new LP_Addon_Course_Review_Preload();
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: 3.0.5
8
+ Author URI: http://thimpress.com
9
+ Tags: learnpress
10
+ Requires at least: 3.8
11
+ Tested up to: 5.2.2
12
+ Text Domain: learnpress-course-review
13
+ Domain Path: /languages/
14
+ */
15
+
16
+ // Prevent loading this file directly
17
+ defined( 'ABSPATH' ) || exit;
18
+
19
+ define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
20
+ define( 'LP_ADDON_COURSE_REVIEW_VER', '3.0.5' );
21
+ define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '3.0.0' );
22
+
23
+ /**
24
+ * Class LP_Addon_Course_Review_Preload
25
+ */
26
+ class LP_Addon_Course_Review_Preload {
27
+
28
+ /**
29
+ * LP_Addon_Course_Review_Preload constructor.
30
+ */
31
+ public function __construct() {
32
+ add_action( 'learn-press/ready', array( $this, 'load' ) );
33
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
34
+ }
35
+
36
+ /**
37
+ * Load addon
38
+ */
39
+ public function load() {
40
+ LP_Addon::load( 'LP_Addon_Course_Review', 'inc/load.php', __FILE__ );
41
+ remove_action( 'admin_notices', array( $this, 'admin_notices' ) );
42
+ }
43
+
44
+ /**
45
+ * Admin notice
46
+ */
47
+ public function admin_notices() {
48
+ ?>
49
+ <div class="error">
50
+ <p><?php echo wp_kses(
51
+ sprintf(
52
+ __( '<strong>%s</strong> addon version %s requires %s version %s or higher is <strong>installed</strong> and <strong>activated</strong>.', 'learnpress-course-review' ),
53
+ __( 'LearnPress Course Review', 'learnpress-course-review' ),
54
+ LP_ADDON_COURSE_REVIEW_VER,
55
+ sprintf( '<a href="%s" target="_blank"><strong>%s</strong></a>', admin_url( 'plugin-install.php?tab=search&type=term&s=learnpress' ), __( 'LearnPress', 'learnpress-course-review' ) ),
56
+ LP_ADDON_COURSE_REVIEW_REQUIRE_VER
57
+ ),
58
+ array(
59
+ 'a' => array(
60
+ 'href' => array(),
61
+ 'blank' => array()
62
+ ),
63
+ 'strong' => array()
64
+ )
65
+ ); ?>
66
+ </p>
67
+ </div>
68
+ <?php
69
+ }
70
+ }
71
+
72
  new LP_Addon_Course_Review_Preload();
readme.txt CHANGED
@@ -1,107 +1,111 @@
1
- === LearnPress - Course Review ===
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: 5.2
7
- Stable tag: 3.0.4
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
-
11
- LearnPress Course Review - An extension plugin for LearnPress.
12
-
13
- == Description ==
14
-
15
- **LearnPress** is a <a href="http://thimpress.com/learnpress">WordPress LMS Plugin</a> by ThimPress.
16
-
17
- LearnPress Course Review bring review feature to your course. Now, student can rate and give review for the course they take on a LearnPress site.
18
-
19
- Review add-on for LearnPress is using on some WordPress Themes: [Education WordPress Theme](http://themeforest.net/item/education-wordpress-theme-education-wp/14058034?utm_source=wporg&utm_medium=course-review&ref=thimpress&utm_campaign=learnpress "Education WordPress Theme") and [LMS WordPress Theme](http://themeforest.net/item/lms-wordpress-theme-elearning-wp/11797847??utm_source=wporg&utm_medium=course-review&ref=thimpress&utm_campaign=learnpress "LMS WordPress Theme"), more is coming.
20
-
21
- **Other free add-ons for LearnPress are available in WordPress:**
22
-
23
- - <a href="https://wordpress.org/plugins/learnpress-wishlist/" target="_blank">LearnPress Wishlist</a> - add courses to a wishlist for students.
24
- - <a href="https://wordpress.org/plugins/learnpress-course-review/" target="_blank">LearnPress Course Review</a> - review course for enrolled students.
25
- - <a href="https://wordpress.org/plugins/learnpress-import-export/" target="_blank">LearnPress Import Export</a> - export or import course or courses out-of-box.
26
- - <a href="https://wordpress.org/plugins/learnpress-prerequisites-courses/" target="_blank">LearnPress Prerequisites Courses</a> - require student to pass some courses in order to enroll other course.
27
- - <a href="https://wordpress.org/plugins/learnpress-bbpress" target="_blank">LearnPress bbPress</a> - add bbPress Forum support for LearnPress.
28
- - <a href="https://wordpress.org/plugins/learnpress-buddypress" target="_blank">LearnPress BuddyPress</a> - add BuddyPress support for LearnPress.
29
-
30
- **Premium Plugins (add-ons) for LearnPress WordPress LMS Plugin**
31
-
32
- - <a href="http://thimpress.com/shop/certificates-add-on-for-learnpress/" target="_blank">Certificates add-on for LearnPress</a> - adding drag & drop certificates builder as well as selecting designed certificate for each LMS course, your student will get particular certificate when they finished a course.
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
-
40
- **From your WordPress dashboard**
41
- 1. Visit 'Plugin > Add new'.
42
- 2. Search for 'LearnPress Course Review'.
43
- 3. Activate LearnPress from your Plugins page.
44
-
45
- **From WordPress.org**
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
-
53
- == Screenshots ==
54
-
55
- 1. LearnPress Course Review screenshot.
56
-
57
- == Changelog ==
58
- = 3.0.4 =
59
- ~ Load select2 in widgets page.
60
- ~ Improve code to implement select2 for widgets.
61
-
62
- = 3.0.3 =
63
- + Fixed displayed name of reviews in Back End Comments page.
64
-
65
- = 3.0.2 =
66
- + Used Select2 field in Widget to avoid memory limit issue when querying too large number of courses.
67
- + Hidden Reply action in back end.
68
- + Fixed bug "Can't use function return value in write context".
69
-
70
- = 3.0.1 =
71
- + Fixed bug with AJAX call when load more reviews.
72
-
73
- = 3.0.0 =
74
- + Compatible with Learnpress 3.0.0
75
-
76
- = 2.1.1 =
77
- ~ Add notices upgrading addon for LP 3.0
78
-
79
- = 2.1 =
80
- ~ Allow all user and guest user can view reviewed
81
- ~ Only allow enrolled user can write new review
82
-
83
- = 2.0.1 =
84
- + Changed text domain to learnpress
85
-
86
- = 2.0 =
87
- + Updated to be compatible with LearnPress 2.0
88
-
89
- = 1.1 =
90
- + Fixed comments do not show in admin
91
-
92
- = 1.0 =
93
- + Compatible with LearnPress version 1.0
94
-
95
- = 0.9.1 =
96
- - Updated languages file
97
- - Fixed PHP5 version 5.3.x error
98
-
99
- = 0.9.0 =
100
- - The first beta release.
101
-
102
- == Upgrade Notice ==
103
- Later :)
104
-
105
- == Other note ==
106
- <a href="http://docs.thimpress.com/learnpress" target="_blank">Documentation</a> is available in ThimPress site.
 
 
 
 
107
  <a href="https://github.com/LearnPress/LearnPress/" target="_blank">LearnPress github repo.</a>
1
+ === LearnPress - Course Review ===
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: 5.2.2
7
+ Stable tag: 3.0.5
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ LearnPress Course Review - An extension plugin for LearnPress.
12
+
13
+ == Description ==
14
+
15
+ **LearnPress** is a <a href="http://thimpress.com/learnpress">WordPress LMS Plugin</a> by ThimPress.
16
+
17
+ LearnPress Course Review bring review feature to your course. Now, student can rate and give review for the course they take on a LearnPress site.
18
+
19
+ Review add-on for LearnPress is using on some WordPress Themes: [Education WordPress Theme](http://themeforest.net/item/education-wordpress-theme-education-wp/14058034?utm_source=wporg&utm_medium=course-review&ref=thimpress&utm_campaign=learnpress "Education WordPress Theme") and [LMS WordPress Theme](http://themeforest.net/item/lms-wordpress-theme-elearning-wp/11797847??utm_source=wporg&utm_medium=course-review&ref=thimpress&utm_campaign=learnpress "LMS WordPress Theme"), more is coming.
20
+
21
+ **Other free add-ons for LearnPress are available in WordPress:**
22
+
23
+ - <a href="https://wordpress.org/plugins/learnpress-wishlist/" target="_blank">LearnPress Wishlist</a> - add courses to a wishlist for students.
24
+ - <a href="https://wordpress.org/plugins/learnpress-course-review/" target="_blank">LearnPress Course Review</a> - review course for enrolled students.
25
+ - <a href="https://wordpress.org/plugins/learnpress-import-export/" target="_blank">LearnPress Import Export</a> - export or import course or courses out-of-box.
26
+ - <a href="https://wordpress.org/plugins/learnpress-prerequisites-courses/" target="_blank">LearnPress Prerequisites Courses</a> - require student to pass some courses in order to enroll other course.
27
+ - <a href="https://wordpress.org/plugins/learnpress-bbpress" target="_blank">LearnPress bbPress</a> - add bbPress Forum support for LearnPress.
28
+ - <a href="https://wordpress.org/plugins/learnpress-buddypress" target="_blank">LearnPress BuddyPress</a> - add BuddyPress support for LearnPress.
29
+
30
+ **Premium Plugins (add-ons) for LearnPress WordPress LMS Plugin**
31
+
32
+ - <a href="http://thimpress.com/shop/certificates-add-on-for-learnpress/" target="_blank">Certificates add-on for LearnPress</a> - adding drag & drop certificates builder as well as selecting designed certificate for each LMS course, your student will get particular certificate when they finished a course.
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
+
40
+ **From your WordPress dashboard**
41
+ 1. Visit 'Plugin > Add new'.
42
+ 2. Search for 'LearnPress Course Review'.
43
+ 3. Activate LearnPress from your Plugins page.
44
+
45
+ **From WordPress.org**
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
+
53
+ == Screenshots ==
54
+
55
+ 1. LearnPress Course Review screenshot.
56
+
57
+ == Changelog ==
58
+
59
+ = 3.0.5 =
60
+ ~ Fixed an issue when checking if the user rated or not!
61
+
62
+ = 3.0.4 =
63
+ ~ Load select2 in widgets page.
64
+ ~ Improve code to implement select2 for widgets.
65
+
66
+ = 3.0.3 =
67
+ + Fixed displayed name of reviews in Back End Comments page.
68
+
69
+ = 3.0.2 =
70
+ + Used Select2 field in Widget to avoid memory limit issue when querying too large number of courses.
71
+ + Hidden Reply action in back end.
72
+ + Fixed bug "Can't use function return value in write context".
73
+
74
+ = 3.0.1 =
75
+ + Fixed bug with AJAX call when load more reviews.
76
+
77
+ = 3.0.0 =
78
+ + Compatible with Learnpress 3.0.0
79
+
80
+ = 2.1.1 =
81
+ ~ Add notices upgrading addon for LP 3.0
82
+
83
+ = 2.1 =
84
+ ~ Allow all user and guest user can view reviewed
85
+ ~ Only allow enrolled user can write new review
86
+
87
+ = 2.0.1 =
88
+ + Changed text domain to learnpress
89
+
90
+ = 2.0 =
91
+ + Updated to be compatible with LearnPress 2.0
92
+
93
+ = 1.1 =
94
+ + Fixed comments do not show in admin
95
+
96
+ = 1.0 =
97
+ + Compatible with LearnPress version 1.0
98
+
99
+ = 0.9.1 =
100
+ - Updated languages file
101
+ - Fixed PHP5 version 5.3.x error
102
+
103
+ = 0.9.0 =
104
+ - The first beta release.
105
+
106
+ == Upgrade Notice ==
107
+ Later :)
108
+
109
+ == Other note ==
110
+ <a href="http://docs.thimpress.com/learnpress" target="_blank">Documentation</a> is available in ThimPress site.
111
  <a href="https://github.com/LearnPress/LearnPress/" target="_blank">LearnPress github repo.</a>
templates/course-rate.php CHANGED
@@ -1,48 +1,48 @@
1
- <?php
2
- /**
3
- * Template for displaying course rate.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/course-rate.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
-
15
- $course_id = get_the_ID();
16
- $course_rate_res = learn_press_get_course_rate( $course_id, false );
17
- $course_rate = $course_rate_res['rated'];
18
- $total = $course_rate_res['total'];
19
- ?>
20
-
21
- <div class="course-rate">
22
- <?php
23
- learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
24
- ?>
25
- <p class="review-number">
26
- <?php do_action( 'learn_press_before_total_review_number' ); ?>
27
- <?php printf( __( ' %1.2f average based on ', 'learnpress-course-review' ), $course_rate ); ?>
28
- <?php printf( _n( ' %d rating', '%d ratings', $total, 'learnpress-course-review' ), $total ); ?>
29
- <?php do_action( 'learn_press_after_total_review_number' ); ?>
30
- </p>
31
- <div>
32
- <?php
33
- if ( isset( $course_rate_res['items'] ) && ! empty( $course_rate_res['items'] ) ):
34
- foreach ( $course_rate_res['items'] as $item ):
35
- ?>
36
- <div class="course-rate">
37
- <span><?php esc_html_e( $item['rated'] ); ?><?php _e( ' Star', 'learnpress-course-review' ); ?></span>
38
- <div class="review-bar">
39
- <div class="rating" style="width:<?php echo $item['percent']; ?>% "></div>
40
- </div>
41
- <span><?php echo esc_html( $item['percent'] ); ?>%</span>
42
- </div>
43
- <?php
44
- endforeach;
45
- endif;
46
- ?>
47
- </div>
48
- </div>
1
+ <?php
2
+ /**
3
+ * Template for displaying course rate.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/course-rate.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ $course_id = get_the_ID();
16
+ $course_rate_res = learn_press_get_course_rate( $course_id, false );
17
+ $course_rate = $course_rate_res['rated'];
18
+ $total = $course_rate_res['total'];
19
+ ?>
20
+
21
+ <div class="course-rate">
22
+ <?php
23
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
24
+ ?>
25
+ <p class="review-number">
26
+ <?php do_action( 'learn_press_before_total_review_number' ); ?>
27
+ <?php printf( __( ' %1.2f average based on ', 'learnpress-course-review' ), $course_rate ); ?>
28
+ <?php printf( _n( ' %d rating', '%d ratings', $total, 'learnpress-course-review' ), $total ); ?>
29
+ <?php do_action( 'learn_press_after_total_review_number' ); ?>
30
+ </p>
31
+ <div>
32
+ <?php
33
+ if ( isset( $course_rate_res['items'] ) && ! empty( $course_rate_res['items'] ) ):
34
+ foreach ( $course_rate_res['items'] as $item ):
35
+ ?>
36
+ <div class="course-rate">
37
+ <span><?php esc_html_e( $item['rated'] ); ?><?php _e( ' Star', 'learnpress-course-review' ); ?></span>
38
+ <div class="review-bar">
39
+ <div class="rating" style="width:<?php echo $item['percent']; ?>% "></div>
40
+ </div>
41
+ <span><?php echo esc_html( $item['percent'] ); ?>%</span>
42
+ </div>
43
+ <?php
44
+ endforeach;
45
+ endif;
46
+ ?>
47
+ </div>
48
+ </div>
templates/course-review.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- /**
3
- * Template for displaying course review.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/course-review.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * @version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
-
15
- $course_id = get_the_ID();
16
- $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
17
- $course_review = learn_press_get_course_review( $course_id, $paged );//echo'<pre>';print_r($course_review);die;
18
- if ( $course_review['total'] ) {
19
- $reviews = $course_review['reviews']; ?>
20
- <div id="course-reviews">
21
- <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
22
- <ul class="course-reviews-list">
23
- <?php foreach ( $reviews as $review ) { ?>
24
- <?php learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) ); ?>
25
- <?php } ?>
26
-
27
- <?php if ( empty( $course_review['finish'] ) ) { ?>
28
- <li class="loading"><?php _e( 'Loading...', 'learnpress-course-review' ); ?></li>
29
- <?php } ?>
30
-
31
- <?php //_e( 'No review to load', 'learnpress-course-review' ); ?>
32
- </ul>
33
- <?php if ( empty( $course_review['finish'] ) ) { ?>
34
- <button class="button course-review-load-more" id="course-review-load-more"
35
- data-paged="<?php echo $course_review['paged']; ?>"><?php _e( 'Load More', 'learnpress-course-review' ); ?></button>
36
- <?php } ?>
37
- </div>
38
  <?php }
1
+ <?php
2
+ /**
3
+ * Template for displaying course review.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/course-review.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * @version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ $course_id = get_the_ID();
16
+ $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
17
+ $course_review = learn_press_get_course_review( $course_id, $paged );//echo'<pre>';print_r($course_review);die;
18
+ if ( $course_review['total'] ) {
19
+ $reviews = $course_review['reviews']; ?>
20
+ <div id="course-reviews">
21
+ <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
22
+ <ul class="course-reviews-list">
23
+ <?php foreach ( $reviews as $review ) { ?>
24
+ <?php learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) ); ?>
25
+ <?php } ?>
26
+
27
+ <?php if ( empty( $course_review['finish'] ) ) { ?>
28
+ <li class="loading"><?php _e( 'Loading...', 'learnpress-course-review' ); ?></li>
29
+ <?php } ?>
30
+
31
+ <?php //_e( 'No review to load', 'learnpress-course-review' ); ?>
32
+ </ul>
33
+ <?php if ( empty( $course_review['finish'] ) ) { ?>
34
+ <button class="button course-review-load-more" id="course-review-load-more"
35
+ data-paged="<?php echo $course_review['paged']; ?>"><?php _e( 'Load More', 'learnpress-course-review' ); ?></button>
36
+ <?php } ?>
37
+ </div>
38
  <?php }
templates/loop-review.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /**
3
- * Template for displaying loop course review.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/loop-review.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
-
15
- ?>
16
-
17
- <li>
18
- <?php #var_dump($review); ?>
19
- <div class="review-author">
20
- <?php echo get_avatar( $review->user_email ) ?>
21
- </div>
22
- <div class="review-author-info">
23
- <h4 class="user-name">
24
- <?php do_action( 'learn_press_before_review_username' ); ?>
25
- <?php echo $review->display_name; ?>
26
- <?php do_action( 'learn_press_after_review_username' ); ?>
27
- </h4>
28
- <?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $review->rate ) ); ?>
29
- <p class="review-title">
30
- <?php do_action( 'learn_press_before_review_title' ); ?>
31
- <?php echo $review->title ?>
32
- <?php do_action( 'learn_press_after_review_title' ); ?>
33
- </p>
34
- </div>
35
- <div class="review-text">
36
- <div class="review-content">
37
- <?php do_action( 'learn_press_before_review_content' ); ?>
38
- <?php echo $review->content ?>
39
- <?php do_action( 'learn_press_after_review_content' ); ?>
40
- </div>
41
- </div>
42
  </li>
1
+ <?php
2
+ /**
3
+ * Template for displaying loop course review.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/loop-review.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ ?>
16
+
17
+ <li>
18
+ <?php #var_dump($review); ?>
19
+ <div class="review-author">
20
+ <?php echo get_avatar( $review->user_email ) ?>
21
+ </div>
22
+ <div class="review-author-info">
23
+ <h4 class="user-name">
24
+ <?php do_action( 'learn_press_before_review_username' ); ?>
25
+ <?php echo $review->display_name; ?>
26
+ <?php do_action( 'learn_press_after_review_username' ); ?>
27
+ </h4>
28
+ <?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $review->rate ) ); ?>
29
+ <p class="review-title">
30
+ <?php do_action( 'learn_press_before_review_title' ); ?>
31
+ <?php echo $review->title ?>
32
+ <?php do_action( 'learn_press_after_review_title' ); ?>
33
+ </p>
34
+ </div>
35
+ <div class="review-text">
36
+ <div class="review-content">
37
+ <?php do_action( 'learn_press_before_review_content' ); ?>
38
+ <?php echo $review->content ?>
39
+ <?php do_action( 'learn_press_after_review_content' ); ?>
40
+ </div>
41
+ </div>
42
  </li>
templates/rating-stars.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
- /**
3
- * Template for displaying rating stars.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/rating-stars.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
- //echo'<pre>alo ';print_r(sprintf(__( '%s out of 5 stars', 'learnpress-course-review'), $rated));die;
15
-
16
- $percent = ( ! $rated ) ? 0 : min( 100, ( round( $rated * 2 ) / 2 ) * 20 );
17
- $title = sprintf( __( '%s out of 5 stars', 'learnpress-course-review' ), $rated );
18
- ?>
19
- <div class="review-stars-rated" title="<?php echo esc_attr( $title ); ?>">
20
- <div class="review-stars empty"></div>
21
- <div class="review-stars filled" style="width:<?php echo $percent; ?>%;"></div>
22
  </div>
1
+ <?php
2
+ /**
3
+ * Template for displaying rating stars.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/rating-stars.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+ //echo'<pre>alo ';print_r(sprintf(__( '%s out of 5 stars', 'learnpress-course-review'), $rated));die;
15
+
16
+ $percent = ( ! $rated ) ? 0 : min( 100, ( round( $rated * 2 ) / 2 ) * 20 );
17
+ $title = sprintf( __( '%s out of 5 stars', 'learnpress-course-review' ), $rated );
18
+ ?>
19
+ <div class="review-stars-rated" title="<?php echo esc_attr( $title ); ?>">
20
+ <div class="review-stars empty"></div>
21
+ <div class="review-stars filled" style="width:<?php echo $percent; ?>%;"></div>
22
  </div>
templates/review-form.php CHANGED
@@ -1,60 +1,60 @@
1
- <?php
2
- /**
3
- * Template for displaying review form.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/review-form.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
- ?>
15
-
16
- <button class="write-a-review"><?php _e( 'Write a review', 'learnpress-course-review' ); ?></button>
17
- <div class="course-review-wrapper" id="course-review">
18
- <div class="review-overlay"></div>
19
- <div class="review-form" id="review-form">
20
- <div class="form-overlay-review"></div>
21
- <form>
22
- <h3>
23
- <?php _e( 'Write a review', 'learnpress-course-review' ); ?>
24
- <a href="" class="close dashicons dashicons-no-alt"></a>
25
- </h3>
26
- <ul class="review-fields">
27
- <?php do_action( 'learn_press_before_review_fields' ); ?>
28
- <li>
29
- <label><?php _e( 'Title', 'learnpress-course-review' ); ?> <span class="required">*</span></label>
30
- <input type="text" name="review_title"/>
31
- </li>
32
- <li>
33
- <label><?php _e( 'Content', 'learnpress-course-review' ); ?><span class="required">*</span></label>
34
- <textarea name="review_content"></textarea>
35
- </li>
36
- <li>
37
- <label><?php _e( 'Rating', 'learnpress-course-review' ); ?><span class="required">*</span></label>
38
- <ul class="review-stars">
39
- <?php for ( $i = 1; $i <= 5; $i ++ ) { ?>
40
- <li class="review-title" title="<?php echo $i; ?>">
41
- <span class="dashicons dashicons-star-empty"></span></li>
42
- <?php } ?>
43
- </ul>
44
- </li>
45
- <?php do_action( 'learn_press_after_review_fields' ); ?>
46
- <li class="review-actions">
47
- <button type="button" class="submit-review"
48
- data-id="<?php the_ID(); ?>"><?php _e( 'Add review', 'learnpress-course-review' ); ?></button>
49
- <span class="ajaxload"></span>
50
- <button type="button" class="close"><?php _e( 'Cancel', 'learnpress-course-review' ); ?></button>
51
- <span class="error"></span>
52
- <?php wp_nonce_field( 'learn_press_course_review_' . get_the_ID(), 'review-nonce' ); ?>
53
- <input type="hidden" name="rating" value="0">
54
- <input type="hidden" name="lp-ajax" value="add_review">
55
- <input type="hidden" name="comment_post_ID" value="<?php echo get_the_ID(); ?>">
56
- </li>
57
- </ul>
58
- </form>
59
- </div>
60
  </div>
1
+ <?php
2
+ /**
3
+ * Template for displaying review form.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/review-form.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+ ?>
15
+
16
+ <button class="write-a-review"><?php _e( 'Write a review', 'learnpress-course-review' ); ?></button>
17
+ <div class="course-review-wrapper" id="course-review">
18
+ <div class="review-overlay"></div>
19
+ <div class="review-form" id="review-form">
20
+ <div class="form-overlay-review"></div>
21
+ <form>
22
+ <h3>
23
+ <?php _e( 'Write a review', 'learnpress-course-review' ); ?>
24
+ <a href="" class="close dashicons dashicons-no-alt"></a>
25
+ </h3>
26
+ <ul class="review-fields">
27
+ <?php do_action( 'learn_press_before_review_fields' ); ?>
28
+ <li>
29
+ <label><?php _e( 'Title', 'learnpress-course-review' ); ?> <span class="required">*</span></label>
30
+ <input type="text" name="review_title"/>
31
+ </li>
32
+ <li>
33
+ <label><?php _e( 'Content', 'learnpress-course-review' ); ?><span class="required">*</span></label>
34
+ <textarea name="review_content"></textarea>
35
+ </li>
36
+ <li>
37
+ <label><?php _e( 'Rating', 'learnpress-course-review' ); ?><span class="required">*</span></label>
38
+ <ul class="review-stars">
39
+ <?php for ( $i = 1; $i <= 5; $i ++ ) { ?>
40
+ <li class="review-title" title="<?php echo $i; ?>">
41
+ <span class="dashicons dashicons-star-empty"></span></li>
42
+ <?php } ?>
43
+ </ul>
44
+ </li>
45
+ <?php do_action( 'learn_press_after_review_fields' ); ?>
46
+ <li class="review-actions">
47
+ <button type="button" class="submit-review"
48
+ data-id="<?php the_ID(); ?>"><?php _e( 'Add review', 'learnpress-course-review' ); ?></button>
49
+ <span class="ajaxload"></span>
50
+ <button type="button" class="close"><?php _e( 'Cancel', 'learnpress-course-review' ); ?></button>
51
+ <span class="error"></span>
52
+ <?php wp_nonce_field( 'learn_press_course_review_' . get_the_ID(), 'review-nonce' ); ?>
53
+ <input type="hidden" name="rating" value="0">
54
+ <input type="hidden" name="lp-ajax" value="add_review">
55
+ <input type="hidden" name="comment_post_ID" value="<?php echo get_the_ID(); ?>">
56
+ </li>
57
+ </ul>
58
+ </form>
59
+ </div>
60
  </div>
templates/shortcode-course-rate.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- /**
3
- * Template for displaying shortcode course rate.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/shortcode-course-rate.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
-
15
- $course_rate_res = $args['course_rate'];
16
- $course_rate = $course_rate_res['rated'];
17
- $total = $course_rate_res['total'];
18
- ?>
19
-
20
- <div class="course-rate">
21
- <?php
22
- learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
23
- $text = sprintf( _n( '%d rating', '%d ratings', $total, 'learnpress-course-review' ), $total );
24
- ?>
25
- <p class="review-number">
26
- <?php do_action( 'learn_press_before_total_review_number' ); ?>
27
- <?php echo $text; ?>
28
- <?php do_action( 'learn_press_after_total_review_number' ); ?>
29
- </p>
30
- <div>
31
- <?php
32
- if ( isset( $course_rate_res['items'] ) && ! empty( $course_rate_res['items'] ) ):
33
- foreach ( $course_rate_res['items'] as $item ):
34
- ?>
35
- <div class="course-rate">
36
- <span><?php esc_html_e( $item['rated'] ); ?><?php _e( 'Star', 'learnpress-course-review' ); ?></span>
37
- <span><?php esc_html_e( $item['total'] ); ?><?php _e( 'Rate', 'learnpress-course-review' ); ?></span>
38
- <span><?php esc_html_e( $item['percent'] ); ?>%</span>
39
- </div>
40
- <?php
41
- endforeach;
42
- endif;
43
- ?>
44
- </div>
45
  </div>
1
+ <?php
2
+ /**
3
+ * Template for displaying shortcode course rate.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/shortcode-course-rate.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ $course_rate_res = $args['course_rate'];
16
+ $course_rate = $course_rate_res['rated'];
17
+ $total = $course_rate_res['total'];
18
+ ?>
19
+
20
+ <div class="course-rate">
21
+ <?php
22
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
23
+ $text = sprintf( _n( '%d rating', '%d ratings', $total, 'learnpress-course-review' ), $total );
24
+ ?>
25
+ <p class="review-number">
26
+ <?php do_action( 'learn_press_before_total_review_number' ); ?>
27
+ <?php echo $text; ?>
28
+ <?php do_action( 'learn_press_after_total_review_number' ); ?>
29
+ </p>
30
+ <div>
31
+ <?php
32
+ if ( isset( $course_rate_res['items'] ) && ! empty( $course_rate_res['items'] ) ):
33
+ foreach ( $course_rate_res['items'] as $item ):
34
+ ?>
35
+ <div class="course-rate">
36
+ <span><?php esc_html_e( $item['rated'] ); ?><?php _e( 'Star', 'learnpress-course-review' ); ?></span>
37
+ <span><?php esc_html_e( $item['total'] ); ?><?php _e( 'Rate', 'learnpress-course-review' ); ?></span>
38
+ <span><?php esc_html_e( $item['percent'] ); ?>%</span>
39
+ </div>
40
+ <?php
41
+ endforeach;
42
+ endif;
43
+ ?>
44
+ </div>
45
  </div>
templates/shortcode-course-review.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- /**
3
- * Template for displaying shortcode course review.
4
- *
5
- * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/shortcode-course-review.php.
6
- *
7
- * @author ThimPress
8
- * @package LearnPress/Course-Review/Templates
9
- * version 3.0.1
10
- */
11
-
12
- // Prevent loading this file directly
13
- defined( 'ABSPATH' ) || exit;
14
-
15
- $course_id = $args['course_id'];
16
- if ( $course_review['total'] ) {
17
- $course_rate = learn_press_get_course_rate( $course_id, false );
18
- $reviews = $course_review['reviews'];
19
- ?>
20
- <div id="course-reviews-shortcode">
21
- <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
22
- <p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress-course-review' ), $course_rate ); ?></p>
23
- <ul class="course-reviews-list-shortcode">
24
- <?php foreach ( $reviews as $review ) { ?>
25
- <?php learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) ); ?>
26
- <?php } ?>
27
- </ul>
28
- </div>
29
- <?php
30
- } else {
31
- _e( 'No review to load', 'learnpress-course-review' );
32
  }
1
+ <?php
2
+ /**
3
+ * Template for displaying shortcode course review.
4
+ *
5
+ * This template can be overridden by copying it to yourtheme/learnpress/addons/course-review/shortcode-course-review.php.
6
+ *
7
+ * @author ThimPress
8
+ * @package LearnPress/Course-Review/Templates
9
+ * version 3.0.1
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ $course_id = $args['course_id'];
16
+ if ( $course_review['total'] ) {
17
+ $course_rate = learn_press_get_course_rate( $course_id, false );
18
+ $reviews = $course_review['reviews'];
19
+ ?>
20
+ <div id="course-reviews-shortcode">
21
+ <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
22
+ <p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress-course-review' ), $course_rate ); ?></p>
23
+ <ul class="course-reviews-list-shortcode">
24
+ <?php foreach ( $reviews as $review ) { ?>
25
+ <?php learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) ); ?>
26
+ <?php } ?>
27
+ </ul>
28
+ </div>
29
+ <?php
30
+ } else {
31
+ _e( 'No review to load', 'learnpress-course-review' );
32
  }