LearnPress – Course Review - Version 4.0.3

Version Description

~ Update review api. ~ Fix minor bugs.

Download this release

Release Info

Developer ThimPress
Plugin Icon 128x128 LearnPress – Course Review
Version 4.0.3
Comparing to
See all releases

Code changes from version 3.0.5 to 4.0.3

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,307 @@
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
+ .course-rate {
2
+ display: flex;
3
+ margin-bottom: 50px;
4
+ flex-wrap: wrap;
5
+ }
6
+ .course-rate .course-rate__details {
7
+ margin-left: 50px;
8
+ flex: 1; }
9
+ .course-rate .course-rate__message {
10
+ width: 100%;
11
+ margin-bottom:15px;
12
+ }
13
+ .course-rate .course-rate__summary-value {
14
+ font-size: 90px;
15
+ text-align: center;
16
+ color: #333;
17
+ line-height: 1; }
18
+ .course-rate .course-rate__summary-stars .review-stars-rated {
19
+ justify-content: center; }
20
+ .course-rate .course-rate__summary-text {
21
+ text-align: center;
22
+ color: #777; }
23
+ .course-rate .course-rate__details-row {
24
+ display: flex;
25
+ margin: 0 0 10px 0; }
26
+ .course-rate .course-rate__details-row .course-rate__details-row-star {
27
+ flex: 0 0 45px;
28
+ text-align: right;
29
+ color: #CCC; }
30
+ .course-rate .course-rate__details-row .course-rate__details-row-star i {
31
+ display: inline-block;
32
+ margin-left: 5px; }
33
+ .course-rate .course-rate__details-row .course-rate__details-row-value {
34
+ flex: 1;
35
+ position: relative;
36
+ margin: 0 50px 0 10px; }
37
+ .course-rate .course-rate__details-row .course-rate__details-row-value .rating,
38
+ .course-rate .course-rate__details-row .course-rate__details-row-value .rating-gray {
39
+ height: 15px;
40
+ background: #ffb608;
41
+ position: absolute;
42
+ top: 50%;
43
+ margin-top: -7px;
44
+ border-radius: 3px; }
45
+ .course-rate .course-rate__details-row .course-rate__details-row-value .rating-gray {
46
+ width: 100%;
47
+ background: #EEE; }
48
+ .course-rate .course-rate__details-row .course-rate__details-row-value .rating-count {
49
+ color: #333;
50
+ display: inline-block;
51
+ position: absolute;
52
+ right: -50px;
53
+ text-align: right;
54
+ line-height: 1;
55
+ font-size: 16px;
56
+ margin: 5px 0; }
57
+
58
+ .review-stars-rated {
59
+ display: flex; }
60
+ .review-stars-rated .review-star {
61
+ position: relative;
62
+ line-height: 1;
63
+ margin: 0 2px; }
64
+ .review-stars-rated .review-star .far {
65
+ position: relative;
66
+ color: #CCC; }
67
+ .review-stars-rated .review-star .fas {
68
+ position: absolute;
69
+ left: 0;
70
+ top: 0;
71
+ overflow: hidden;
72
+ color: #ffb60a; }
73
+ .review-stars-rated.center {
74
+ justify-content: center; }
75
+
76
+ .course-review-wrapper {
77
+ display: none;
78
+ position: fixed;
79
+ top: 0;
80
+ left: 0;
81
+ right: 0;
82
+ bottom: 0;
83
+ z-index: 99999;
84
+ text-align: center; }
85
+
86
+ .review-overlay {
87
+ background: #000;
88
+ bottom: 0;
89
+ left: 0;
90
+ position: fixed;
91
+ top: 0;
92
+ width: 100%;
93
+ opacity: 0.6; }
94
+
95
+ .review-form {
96
+ background-color: white;
97
+ padding: 20px;
98
+ position: relative;
99
+ width: 80%;
100
+ max-width: 600px;
101
+ margin-top: 50px;
102
+ display: inline-block;
103
+ text-align: left; }
104
+
105
+ .review-form .close {
106
+ margin-top: 10px; }
107
+
108
+ .review-form h3 {
109
+ font-size: 16px;
110
+ margin: 0 0 20px; }
111
+
112
+ .review-form h3 .close {
113
+ float: right;
114
+ border: none;
115
+ text-decoration: none;
116
+ width: auto;
117
+ height: auto;
118
+ margin-right: -9px;
119
+ margin-top: -7px; }
120
+
121
+ .review-form h3 .close:before {
122
+ font-size: 32px; }
123
+
124
+ .review-form .review-fields {
125
+ margin: 0 0 -20px;
126
+ list-style: none; }
127
+
128
+ .review-form .review-fields > li {
129
+ margin: 0 0 20px 0; }
130
+
131
+ .review-form .review-fields > li > label {
132
+ display: block;
133
+ margin: 0 0 7px;
134
+ font-size: 15px; }
135
+
136
+ .review-form .review-fields > li > label .required {
137
+ margin-left: 5px;
138
+ display: inline-block;
139
+ vertical-align: middle;
140
+ font-size: 24px;
141
+ line-height: 1;
142
+ height: 15px;
143
+ margin-top: -3px; }
144
+
145
+ .review-form .review-fields > li input[type="text"],
146
+ .review-form .review-fields > li textarea {
147
+ width: 100%; }
148
+
149
+ .review-stars {
150
+ margin: 0 0;
151
+ list-style: none;
152
+ overflow: hidden; }
153
+
154
+ .review-stars:after {
155
+ clear: both;
156
+ content: '';
157
+ display: block; }
158
+
159
+ .review-stars > li {
160
+ width: 24px;
161
+ height: 24px;
162
+ float: left; }
163
+
164
+ .review-stars > li span {
165
+ text-decoration: none;
166
+ font-size: 24px;
167
+ border-bottom: none;
168
+ width: auto;
169
+ height: auto; }
170
+
171
+ .review-stars > li a:visited,
172
+ .review-stars > li a:focus {
173
+ border: none; }
174
+
175
+ .review-stars > li span:before {
176
+ width: 22px;
177
+ height: 24px; }
178
+
179
+ .review-stars > li span.hover:before {
180
+ content: "\f155";
181
+ color: #F05A19;
182
+ cursor: pointer; }
183
+
184
+ .review-form .ajaxload,
185
+ .review-form .message {
186
+ display: none; }
187
+
188
+ .course-review-wrapper.submitting .ajaxload,
189
+ .course-review-wrapper.error .message {
190
+ display: inline-block; }
191
+
192
+ .course-review-wrapper.submitting .ajaxload {
193
+ position: absolute;
194
+ top: 48%;
195
+ left: 48%; }
196
+
197
+ .course-review-wrapper.submitting .review-form {
198
+ position: relative; }
199
+
200
+ .course-review-wrapper.submitting .review-form .form-overlay-review {
201
+ background: #000;
202
+ bottom: 0;
203
+ left: 0;
204
+ position: absolute;
205
+ top: 0;
206
+ width: 100%;
207
+ opacity: 0.3; }
208
+
209
+ .review-stars-rated {
210
+ position: relative;
211
+ margin-bottom: 10px; }
212
+
213
+ .review-stars-rated .review-stars.empty,
214
+ .review-stars-rated .review-stars.filled {
215
+ font-family: dashicons;
216
+ font-size: 18px;
217
+ color: #f2b827;
218
+ display: inline-block;
219
+ position: relative; }
220
+
221
+ .review-stars-rated .review-stars.empty:before,
222
+ .review-stars-rated .review-stars.filled:before {
223
+ content: '\f155';
224
+ line-height: 1;
225
+ vertical-align: top;
226
+ white-space: nowrap; }
227
+
228
+ .review-stars-rated .review-stars.empty:before {
229
+ color: #DDD;
230
+ content: '\f154'; }
231
+
232
+ /*.review-stars-rated .review-stars.filled:before {*/
233
+ /*content: '\f155';*/
234
+ /*line-height: 1;*/
235
+ /*vertical-align: top;*/
236
+ /*white-space: nowrap;*/
237
+ /*}*/
238
+ .review-stars-rated .review-stars.filled {
239
+ position: absolute;
240
+ top: 0;
241
+ left: 0; }
242
+
243
+ .course-rate {
244
+ overflow: hidden;
245
+ margin: 10px 0; }
246
+
247
+ .course-rate .review-bar {
248
+ width: calc(100% - 125px);
249
+ margin-right: 5px;
250
+ height: 15px;
251
+ background: #DDD;
252
+ display: inline-block; }
253
+
254
+ .course-rate .review-bar .rating {
255
+ background: #95e6f9;
256
+ height: 15px; }
257
+
258
+ .course-rate .review-number {
259
+ margin-bottom: 0; }
260
+
261
+ .course-reviews-list, .course-reviews-list-shortcode {
262
+ list-style: none;
263
+ margin: 0; }
264
+
265
+ .course-reviews-list li, .course-reviews-list-shortcode li {
266
+ margin-bottom: 20px;
267
+ padding: 20px;
268
+ background-color: #fafafa;
269
+ border: 1px solid #ddd;
270
+ overflow: hidden; }
271
+
272
+ .course-reviews-list li .review-author, .course-reviews-list-shortcode li .review-author {
273
+ width: 80px;
274
+ float: left;
275
+ margin-right: 20px; }
276
+
277
+ .course-reviews-list li .review-author-info .course-reviews-list-shortcode li .review-author-info {
278
+ float: left; }
279
+
280
+ .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
281
+ width: -webkit-calc(100% - 100px);
282
+ float: right; }
283
+
284
+ .course-reviews-list li .user-name, .course-reviews-list-shortcode li .user-name {
285
+ margin: 5px; }
286
+
287
+ .course-reviews-list li .review-title, .course-reviews-list-shortcode li .review-title {
288
+ clear: both;
289
+ font-size: 14px;
290
+ font-style: italic;
291
+ font-weight: 700;
292
+ line-height: 25px;
293
+ margin: 9px 0 15px; }
294
+
295
+ @media (max-width: 600px) {
296
+ .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
297
+ width: 100%;
298
+ float: left; } }
299
+
300
+ .loading {
301
+ display: none; }
302
+
303
+ .learn-press-courses .course-review {
304
+ float: left; }
305
+
306
+ .learn-press-courses .course-review .review-stars-rated .review-stars {
307
+ font-size: 14px; }
assets/css/course-review.css.map ADDED
@@ -0,0 +1 @@
 
1
+ {"version":3,"sourceRoot":"","sources":["../scss/course-review.scss"],"names":[],"mappings":"AAAA;EACI;EACA;;AAKA;EACI;EACA;;AAGJ;EACI;EACA;EACA;EACA;;AAIA;EACI;;AAIR;EACI;EACA;;AAGJ;EACI;EACA;;AAEA;EACI;EACA;EACA;;AAEA;EACI;EACA;;AAIR;EACI;EACA;EACA;;AAEA;AAAA;EAEI;EACA;EACA;EACA;EACA;EACA;;AAGJ;EACI;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAMhB;EACI;;AACA;EACI;EACA;EACA;;AACA;EACI;EACA;;AAGJ;EACI;EACA;EACA;EACA;EACA;;AAGR;EACI;;;AAIR;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;AAAA;EAEI;;;AAGJ;EACI;EACA;EACA;;;AAGJ;EACI;EACA;EACA;;;AAGJ;EACI;EACA;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;;;AAGJ;AAAA;EAEI;;;AAGJ;EACI;EACA;;;AAGJ;EACI;EACA;EACA;;;AAGJ;AAAA;EAEI;;;AAGJ;AAAA;EAEI;;;AAGJ;EACI;EACA;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;;;AAGJ;AAAA;EAEI;EACA;EACA;EACA;EACA;;;AAGJ;AAAA;EAEI;EACA;EACA;EACA;;;AAGJ;EACI;EACA;;;AAGJ;AACA;AACA;AACA;AACA;AACA;AAEA;EACI;EACA;EACA;;;AAGJ;EACI;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;;;AAGJ;EACI;EACA;EACA;EACA;EACA;;;AAGJ;EACI;EACA;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;;;AAGJ;EACI;;;AAGJ;EACI;EACA;EACA;EACA;EACA;EACA;;;AAGJ;EACI;IACI;IACA;;;AAKP;EACC;;;AAIF;EACI;;;AAEJ;EACI","file":"course-review.css"}
assets/css/rating-stars.css ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .course-rate {
2
+ display: flex;
3
+ margin-bottom: 50px; }
4
+ .course-rate .course-rate__details {
5
+ margin-left: 50px;
6
+ flex: 1; }
7
+ .review-stars-rated {
8
+ display: flex; }
9
+ .review-stars-rated .review-star {
10
+ position: relative;
11
+ line-height: 1;
12
+ margin: 0 2px; }
13
+ .review-stars-rated .review-star .far {
14
+ position: relative;
15
+ color: #CCC; }
16
+ .review-stars-rated .review-star .fas {
17
+ position: absolute;
18
+ left: 0;
19
+ top: 0;
20
+ overflow: hidden;
21
+ color: #ffb60a; }
22
+ .review-stars-rated.center {
23
+ justify-content: center; }
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
  })
assets/scss/course-review.scss ADDED
@@ -0,0 +1,380 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .course-rate {
2
+ display: flex;
3
+ margin-bottom: 50px;
4
+
5
+ .course-rate__summary {
6
+ }
7
+
8
+ .course-rate__details {
9
+ margin-left: 50px;
10
+ flex: 1;
11
+ }
12
+
13
+ .course-rate__summary-value {
14
+ font-size: 90px;
15
+ text-align: center;
16
+ color: #333;
17
+ line-height: 1;
18
+ }
19
+
20
+ .course-rate__summary-stars{
21
+ .review-stars-rated{
22
+ justify-content: center;
23
+ }
24
+ }
25
+
26
+ .course-rate__summary-text {
27
+ text-align: center;
28
+ color: #777;
29
+ }
30
+
31
+ .course-rate__details-row {
32
+ display: flex;
33
+ margin: 0 0 10px 0;
34
+
35
+ .course-rate__details-row-star {
36
+ flex: 0 0 45px;
37
+ text-align: right;
38
+ color: #CCC;
39
+
40
+ i {
41
+ display: inline-block;
42
+ margin-left: 5px;
43
+ }
44
+ }
45
+
46
+ .course-rate__details-row-value {
47
+ flex: 1;
48
+ position: relative;
49
+ margin: 0 50px 0 10px;
50
+
51
+ .rating,
52
+ .rating-gray {
53
+ height: 15px;
54
+ background: #ffb608;
55
+ position: absolute;
56
+ top: 50%;
57
+ margin-top: -7px;
58
+ border-radius: 3px;
59
+ }
60
+
61
+ .rating-gray {
62
+ width: 100%;
63
+ background: #EEE;
64
+ }
65
+
66
+ .rating-count {
67
+ color: #333;
68
+ display: inline-block;
69
+ position: absolute;
70
+ right: -50px;
71
+ text-align: right;
72
+ line-height: 1;
73
+ font-size: 16px;
74
+ margin: 5px 0;
75
+ }
76
+ }
77
+ }
78
+ }
79
+
80
+ .review-stars-rated {
81
+ display: flex;
82
+ .review-star {
83
+ position: relative;
84
+ line-height: 1;
85
+ margin: 0 2px;
86
+ .far {
87
+ position: relative;
88
+ color: #CCC;
89
+ }
90
+
91
+ .fas {
92
+ position: absolute;
93
+ left: 0;
94
+ top: 0;
95
+ overflow: hidden;
96
+ color: #ffb60a;
97
+ }
98
+ }
99
+ &.center{
100
+ justify-content: center;
101
+ }
102
+ }
103
+
104
+ .course-review-wrapper {
105
+ display: none;
106
+ position: fixed;
107
+ top: 0;
108
+ left: 0;
109
+ right: 0;
110
+ bottom: 0;
111
+ z-index: 99999;
112
+ text-align: center;
113
+ }
114
+
115
+ .review-overlay {
116
+ background: #000;
117
+ bottom: 0;
118
+ left: 0;
119
+ position: fixed;
120
+ top: 0;
121
+ width: 100%;
122
+ opacity: 0.6;
123
+ }
124
+
125
+ .review-form {
126
+ background-color: rgb(255, 255, 255);
127
+ padding: 20px;
128
+ position: relative;
129
+ width: 80%;
130
+ max-width: 600px;
131
+ margin-top: 50px;
132
+ display: inline-block;
133
+ text-align: left;
134
+ }
135
+
136
+ .review-form .close {
137
+ margin-top: 10px;
138
+ }
139
+
140
+ .review-form h3 {
141
+ font-size: 16px;
142
+ margin: 0 0 20px;
143
+ }
144
+
145
+ .review-form h3 .close {
146
+ float: right;
147
+ border: none;
148
+ text-decoration: none;
149
+ width: auto;
150
+ height: auto;
151
+ margin-right: -9px;
152
+ margin-top: -7px;
153
+ }
154
+
155
+ .review-form h3 .close:before {
156
+ font-size: 32px;
157
+ }
158
+
159
+ .review-form .review-fields {
160
+ margin: 0 0 -20px;
161
+ list-style: none;
162
+ }
163
+
164
+ .review-form .review-fields > li {
165
+ margin: 0 0 20px 0;
166
+ }
167
+
168
+ .review-form .review-fields > li > label {
169
+ display: block;
170
+ margin: 0 0 7px;
171
+ font-size: 15px;
172
+ }
173
+
174
+ .review-form .review-fields > li > label .required {
175
+ margin-left: 5px;
176
+ display: inline-block;
177
+ vertical-align: middle;
178
+ font-size: 24px;
179
+ line-height: 1;
180
+ height: 15px;
181
+ margin-top: -3px;
182
+ }
183
+
184
+ .review-form .review-fields > li input[type="text"],
185
+ .review-form .review-fields > li textarea {
186
+ width: 100%;
187
+ }
188
+
189
+ .review-stars {
190
+ margin: 0 0;
191
+ list-style: none;
192
+ overflow: hidden;
193
+ }
194
+
195
+ .review-stars:after {
196
+ clear: both;
197
+ content: '';
198
+ display: block;
199
+ }
200
+
201
+ .review-stars > li {
202
+ width: 24px;
203
+ height: 24px;
204
+ float: left;
205
+ }
206
+
207
+ .review-stars > li span {
208
+ text-decoration: none;
209
+ font-size: 24px;
210
+ border-bottom: none;
211
+ width: auto;
212
+ height: auto;
213
+ }
214
+
215
+ .review-stars > li a:visited,
216
+ .review-stars > li a:focus {
217
+ border: none;
218
+ }
219
+
220
+ .review-stars > li span:before {
221
+ width: 22px;
222
+ height: 24px;
223
+ }
224
+
225
+ .review-stars > li span.hover:before {
226
+ content: "\f155";
227
+ color: #F05A19;
228
+ cursor: pointer;
229
+ }
230
+
231
+ .review-form .ajaxload,
232
+ .review-form .message {
233
+ display: none;
234
+ }
235
+
236
+ .course-review-wrapper.submitting .ajaxload,
237
+ .course-review-wrapper.error .message {
238
+ display: inline-block;
239
+ }
240
+
241
+ .course-review-wrapper.submitting .ajaxload {
242
+ position: absolute;
243
+ top: 48%;
244
+ left: 48%;
245
+ }
246
+
247
+ .course-review-wrapper.submitting .review-form {
248
+ position: relative;
249
+ }
250
+
251
+ .course-review-wrapper.submitting .review-form .form-overlay-review {
252
+ background: #000;
253
+ bottom: 0;
254
+ left: 0;
255
+ position: absolute;
256
+ top: 0;
257
+ width: 100%;
258
+ opacity: 0.3;
259
+ }
260
+
261
+ .review-stars-rated {
262
+ position: relative;
263
+ margin-bottom: 10px;
264
+ }
265
+
266
+ .review-stars-rated .review-stars.empty,
267
+ .review-stars-rated .review-stars.filled {
268
+ font-family: dashicons;
269
+ font-size: 18px;
270
+ color: #f2b827;
271
+ display: inline-block;
272
+ position: relative;
273
+ }
274
+
275
+ .review-stars-rated .review-stars.empty:before,
276
+ .review-stars-rated .review-stars.filled:before {
277
+ content: '\f155';
278
+ line-height: 1;
279
+ vertical-align: top;
280
+ white-space: nowrap;
281
+ }
282
+
283
+ .review-stars-rated .review-stars.empty:before {
284
+ color: #DDD;
285
+ content: '\f154';
286
+ }
287
+
288
+ /*.review-stars-rated .review-stars.filled:before {*/
289
+ /*content: '\f155';*/
290
+ /*line-height: 1;*/
291
+ /*vertical-align: top;*/
292
+ /*white-space: nowrap;*/
293
+ /*}*/
294
+
295
+ .review-stars-rated .review-stars.filled {
296
+ position: absolute;
297
+ top: 0;
298
+ left: 0;
299
+ }
300
+
301
+ .course-rate {
302
+ overflow: hidden;
303
+ margin: 10px 0;
304
+ }
305
+
306
+ .course-rate .review-bar {
307
+ width: calc(100% - 125px);
308
+ margin-right: 5px;
309
+ height: 15px;
310
+ background: #DDD;
311
+ display: inline-block;
312
+ }
313
+
314
+ .course-rate .review-bar .rating {
315
+ background: #95e6f9;
316
+ height: 15px;
317
+ }
318
+
319
+ .course-rate .review-number {
320
+ margin-bottom: 0;
321
+ }
322
+
323
+ .course-reviews-list, .course-reviews-list-shortcode {
324
+ list-style: none;
325
+ margin: 0;
326
+ }
327
+
328
+ .course-reviews-list li, .course-reviews-list-shortcode li {
329
+ margin-bottom: 20px;
330
+ padding: 20px;
331
+ background-color: #fafafa;
332
+ border: 1px solid #ddd;
333
+ overflow: hidden;
334
+ }
335
+
336
+ .course-reviews-list li .review-author, .course-reviews-list-shortcode li .review-author {
337
+ width: 80px;
338
+ float: left;
339
+ margin-right: 20px;
340
+ }
341
+
342
+ .course-reviews-list li .review-author-info .course-reviews-list-shortcode li .review-author-info {
343
+ float: left;
344
+ }
345
+
346
+ .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
347
+ width: -webkit-calc(100% - 100px);
348
+ float: right;
349
+ }
350
+
351
+ .course-reviews-list li .user-name, .course-reviews-list-shortcode li .user-name {
352
+ margin: 5px;
353
+ }
354
+
355
+ .course-reviews-list li .review-title, .course-reviews-list-shortcode li .review-title {
356
+ clear: both;
357
+ font-size: 14px;
358
+ font-style: italic;
359
+ font-weight: 700;
360
+ line-height: 25px;
361
+ margin: 9px 0 15px;
362
+ }
363
+
364
+ @media (max-width: 600px) {
365
+ .course-reviews-list li .review-text, .course-reviews-list-shortcode li .review-text {
366
+ width: 100%;
367
+ float: left;
368
+ }
369
+ }
370
+
371
+ .loading {
372
+ display: none;
373
+ }
374
+
375
+ .learn-press-courses .course-review{
376
+ float: left;
377
+ }
378
+ .learn-press-courses .course-review .review-stars-rated .review-stars{
379
+ font-size: 14px;
380
+ }
inc/functions.php CHANGED
@@ -1,431 +1,405 @@
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
- }
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.user_email, u.display_name, 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, $force = false ) {
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' ) ) || $force ) {
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
+ 'force' => 0,
206
+ )
207
+ );
208
+ $user_id = $args['user_id'];
209
+ $course_id = $args['course_id'];
210
+ $user_review = learn_press_get_user_rate( $course_id, $user_id, $args['force'] );
211
+ $comment_id = 0;
212
+
213
+ if ( ! $user_review ) {
214
+ $user = get_user_by( 'id', $user_id );
215
+ $comment_id = wp_new_comment(
216
+ array(
217
+ 'comment_post_ID' => $course_id,
218
+ 'comment_author' => $user->display_name,
219
+ 'comment_author_email' => $user->user_email,
220
+ 'comment_author_url' => '',
221
+ 'comment_content' => $args['content'],
222
+ 'comment_parent' => 0,
223
+ 'user_id' => $user->ID,
224
+ 'comment_approved' => 1,
225
+ 'comment_type' => 'review' // let filter to not display it as comments
226
+ )
227
+ );
228
+ }
229
+ if ( $comment_id ) {
230
+ add_comment_meta( $comment_id, '_lpr_rating', $args['rate'] );
231
+ add_comment_meta( $comment_id, '_lpr_review_title', $args['title'] );
232
+ }
233
+
234
+ return $comment_id;
235
+ }
236
+
237
+ function learn_press_course_review_template( $name, $args = null ) {
238
+ learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
239
+ }
240
+
241
+ /*
242
+ * If we are viewing archive course page, so load all ratings of courses
243
+ * into cache to reduce queries and time rather than load separate course
244
+ * in loop
245
+ */
246
+ add_filter( 'the_posts', 'learn_press_init_courses_review' );
247
+ function learn_press_init_courses_review( $posts ) {
248
+ if ( $posts ) {
249
+ $pIds = array();
250
+ foreach ( $posts as $p ) {
251
+ $pIds[] = $p->ID;
252
+ }
253
+ _learn_press_get_ratings( $pIds );
254
+ }
255
+
256
+ return $posts;
257
+ }
258
+
259
+ /**
260
+ * Get rating for a course
261
+ *
262
+ * @param int $course_id
263
+ * @param bool $get_items
264
+ *
265
+ * @return array
266
+ */
267
+ function leanr_press_get_ratings_result( $course_id = 0, $get_items = false ) {
268
+ $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' );
269
+
270
+ if ( $result === false ) {
271
+ global $wpdb;
272
+
273
+ $query = $wpdb->prepare( "
274
+ SELECT
275
+ cm.meta_value `rate`, COUNT(1) `count`
276
+ FROM
277
+ {$wpdb->comments} c
278
+ INNER JOIN
279
+ {$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
280
+ WHERE
281
+ c.comment_approved = 1
282
+ AND c.comment_type = %s
283
+ AND c.user_id > 0
284
+ AND c.comment_post_ID = %d
285
+ GROUP BY `cm`.`meta_value`
286
+ ", '_lpr_rating', 'review', $course_id );
287
+ $rows = $wpdb->get_results( $query );
288
+
289
+ $count = 0;
290
+ $rate = 0;
291
+ $avg = 0;
292
+ $items = array();
293
+
294
+ for ( $i = 5; $i > 0; $i -- ) {
295
+ $items[ $i ] = array(
296
+ 'rated' => $i,
297
+ 'total' => 0,
298
+ 'percent' => 0
299
+ );
300
+ }
301
+
302
+ if ( $rows ) {
303
+ $count = wp_list_pluck( $rows, 'count' );
304
+ $count = array_sum( $count );
305
+ $round = array();
306
+ $one_hundred = 0;
307
+
308
+ foreach ( $rows as $row ) {
309
+ $rate += $row->rate * $row->count;
310
+ $percent = $row->count / $count * 100;
311
+ $items[ $row->rate ] = array(
312
+ 'rated' => $row->rate,
313
+ 'total' => $row->count,
314
+ 'percent' => floor( $percent ),
315
+ 'percent_float' => $percent
316
+ );
317
+ $one_hundred += $items[ $row->rate ]['percent'];
318
+ $round[ $row->rate ] = $percent - floor( $percent );
319
+ }
320
+
321
+ if ( $one_hundred < 100 ) {
322
+ arsort( $round );
323
+ foreach ( $round as $key => $value ) {
324
+ $percent = $items[ $key ]['percent'];
325
+ $items[ $key ]['percent'] = ceil( $items[ $key ]['percent_float'] );
326
+
327
+ if ( $percent < $items[ $key ]['percent'] ) {
328
+ $one_hundred ++;
329
+ if ( $one_hundred == 100 ) {
330
+ break;
331
+ }
332
+ }
333
+ }
334
+ }
335
+
336
+ $avg = $rate / $count;
337
+ }
338
+
339
+ $result = array(
340
+ 'course_id' => $course_id,
341
+ 'total' => $count,
342
+ 'rated' => $avg,
343
+ 'items' => $items
344
+ );
345
+
346
+ wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings', 6 * HOUR_IN_SECONDS );
347
+ }
348
+
349
+ return $result;
350
+ }
351
+
352
+ function learn_press_course_review_loop_stars() {
353
+ if ( LP_COURSE_CPT !== get_post_type() ) {
354
+ return;
355
+ }
356
+
357
+ $course_rate_res = learn_press_get_course_rate( get_the_ID(), false );
358
+ ?>
359
+
360
+ <div class="course-review">
361
+ <?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate_res['rated'] ) ); ?>
362
+ <div class="clearfix">
363
+
364
+ </div>
365
+ </div>
366
+
367
+ <?php
368
+ }
369
+
370
+ add_action( 'learn-press/after-courses-loop-item', 'learn_press_course_review_loop_stars' );
371
+
372
+ function learn_press_course_meta_primary_review() {
373
+
374
+ /**
375
+ * Template for displaying course instructor in primary-meta section.
376
+ *
377
+ * @version 4.0.0
378
+ * @author ThimPress
379
+ * @package LearnPress/Templates
380
+ */
381
+
382
+ defined( 'ABSPATH' ) or die;
383
+
384
+ /**
385
+ * @var LP_Course $course
386
+ */
387
+ $course = LP_Global::course();
388
+ if ( LP_COURSE_CPT !== get_post_type() ) {
389
+ return;
390
+ }
391
+
392
+ $course_rate_res = learn_press_get_course_rate( get_the_ID(), false );
393
+ ?>
394
+ <div class="meta-item meta-item-review">
395
+ <div class="meta-item__value">
396
+ <label><?php esc_html_e( 'Review', 'learnpress' ); ?></label>
397
+ <div>
398
+ <?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate_res['rated'] ) ); ?>
399
+ </div>
400
+ </div>
401
+ </div>
402
+ <?php
403
+ }
404
+
405
+ add_action( 'learn-press/course-meta-primary-left', 'learn_press_course_meta_primary_review', 30 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/load.php CHANGED
@@ -1,320 +1,350 @@
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
+ // Rest API
65
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/inc/rest-api/class-lp-rest-review-v1-controller.php';
66
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/inc/rest-api/class-rest-api.php';
67
+ }
68
+
69
+ /**
70
+ * Init hooks.
71
+ */
72
+ protected function _init_hooks() {
73
+ add_filter( 'learn-press/course-tabs', array( $this, 'add_course_tab_reviews' ), 5 );
74
+
75
+ add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
76
+ add_action( 'wp', array( $this, 'course_review_init' ) );
77
+
78
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
79
+ LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
80
+ LP_Request_Handler::register_ajax(
81
+ 'learnpress_load_course_review',
82
+ array(
83
+ $this,
84
+ 'learnpress_load_course_review',
85
+ )
86
+ );
87
+ add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
88
+
89
+ $this->init_comment_table();
90
+ }
91
+
92
+ /**
93
+ * Get html of reviews
94
+ */
95
+ public function learnpress_load_course_review() {
96
+ $paged = LP_Request::get_post( 'paged', 1 ) ? (int) LP_Request::get_post( 'paged', 1 ) : 1;
97
+ $response = learn_press_get_course_review( get_the_ID(), $paged );
98
+ if ( $response['reviews'] && count( $response['reviews'] ) > 0 ) {
99
+ ob_start();
100
+ learn_press_course_review_template( 'course-review.php', array( 'review' => $response ) );
101
+ ob_end_clean();
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Print rate.
107
+ */
108
+ public function print_rate() {
109
+ learn_press_course_review_template( 'course-rate.php' );
110
+ }
111
+
112
+ /**
113
+ * Print review.
114
+ */
115
+ public function print_review() {
116
+ learn_press_course_review_template( 'course-review.php' );
117
+ }
118
+
119
+ /**
120
+ * Add review button.
121
+ */
122
+ public function add_review_button() {
123
+ if ( ! learn_press_get_user_rate( get_the_ID() ) ) {
124
+ learn_press_course_review_template( 'review-form.php' );
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Admin assets.
130
+ */
131
+ public function admin_enqueue_assets() {
132
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/admin.css' );
133
+ }
134
+
135
+ /**
136
+ * Single course assets.
137
+ */
138
+ public function review_assets() {
139
+ if ( ! learn_press_is_course_archive() ) {
140
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
141
+ wp_enqueue_style( 'dashicons' );
142
+ }
143
+
144
+ if ( learn_press_is_course() ) {
145
+ wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
146
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
147
+ wp_enqueue_style( 'dashicons' );
148
+ wp_localize_script(
149
+ 'course-review',
150
+ 'learn_press_course_review',
151
+ array(
152
+ 'localize' => array(
153
+ 'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
154
+ 'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
155
+ 'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' ),
156
+ ),
157
+ )
158
+ );
159
+ }
160
+ }
161
+
162
+ public function course_review_init() {
163
+ $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
164
+ learn_press_get_course_review( get_the_ID(), $paged );
165
+ }
166
+
167
+ public function exclude_rating( $query ) {
168
+ $query->query_vars['type__not_in'] = 'review';
169
+ }
170
+
171
+ public function add_review() {
172
+ $response = array( 'result' => 'success' );
173
+ $nonce = ! empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
174
+ $id = ! empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
175
+ $rate = ! empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
176
+ $title = ! empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
177
+ $content = ! empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
178
+
179
+ if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
180
+ $response['result'] = 'fail';
181
+ $response['message'] = __( 'Error', 'learnpress-course-review' );
182
+ }
183
+
184
+ if ( get_post_type( $id ) != 'lp_course' ) {
185
+ $response['result'] = 'fail';
186
+ $response['message'] = __( 'Invalid course', 'learnpress-course-review' );
187
+ }
188
+
189
+ $return = learn_press_add_course_review(
190
+ array(
191
+ 'user_id' => get_current_user_id(),
192
+ 'course_id' => $id,
193
+ 'rate' => $rate,
194
+ 'title' => $title,
195
+ 'content' => $content,
196
+ )
197
+ );
198
+
199
+ // Clear cache
200
+ wp_cache_delete( 'course-' . $id, 'lp-course-ratings' );
201
+
202
+ $response['comment'] = $return;
203
+ learn_press_send_json( $response );
204
+ }
205
+
206
+ public function init_comment_table() {
207
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
208
+
209
+ add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
210
+ add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
211
+ add_filter( 'comment_row_actions', array( $this, 'edit_comment_row_actions' ), 10, 2 );
212
+ }
213
+
214
+ public function edit_comment_row_actions( $actions, $comment ) {
215
+ if ( ! $comment || $comment->comment_type != 'review' ) {
216
+ return $actions;
217
+ }
218
+ unset( $actions['reply'] );
219
+
220
+ return $actions;
221
+ }
222
+
223
+ public function add_comment_type_filter( $cmt_types ) {
224
+ $cmt_types[ self::$comment_type ] = __( 'Course review', 'learnpress-course-review' );
225
+
226
+ return $cmt_types;
227
+ }
228
+
229
+ public function add_comment_content_filter( $cmt_text ) {
230
+ global $comment;
231
+ if ( ! $comment || $comment->comment_type != 'review' ) {
232
+ return $cmt_text;
233
+ }
234
+
235
+ ob_start();
236
+ $rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
237
+ echo '<div class="course-rate">';
238
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
239
+ echo '</div>';
240
+ $cmt_text .= ob_get_clean();
241
+
242
+ return $cmt_text;
243
+ }
244
+
245
+ public function add_comment_post_type_filter() {
246
+ ?>
247
+ <label class="screen-reader-text"
248
+ for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
249
+ <select id="filter-by-comment-post-type" name="post_type">
250
+ <?php
251
+ $comment_post_types = apply_filters(
252
+ 'learn_press_admin_comment_post_type_types_dropdown',
253
+ array(
254
+ '' => __( 'All post type', 'learnpress-course-review' ),
255
+ 'lp_course' => __( 'Course comments', 'learnpress-course-review' ),
256
+ )
257
+ );
258
+
259
+ foreach ( $comment_post_types as $type => $label ) {
260
+ echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
261
+ }
262
+ ?>
263
+
264
+ </select>
265
+ <?php
266
+ }
267
+
268
+
269
+ public function shortcode_review( $atts ) {
270
+ $atts = shortcode_atts(
271
+ array(
272
+ 'course_id' => 0,
273
+ 'show_rate' => 'yes',
274
+ 'show_review' => 'yes',
275
+ 'display_amount' => '5',
276
+ ),
277
+ $atts,
278
+ 'shortcode_review'
279
+ );
280
+
281
+ $course_id = $atts['course_id'];
282
+ if ( ! $course_id ) {
283
+ $course_id = get_the_ID();
284
+ }
285
+
286
+ ob_start();
287
+ if ( $atts['show_rate'] ) {
288
+ $course_rate = learn_press_get_course_rate( $course_id, false );
289
+ $total = learn_press_get_course_rate_total( $course_id, false );
290
+ $rate_args = array(
291
+ 'course_id' => $course_id,
292
+ 'course_rate' => $course_rate,
293
+ 'total' => $total,
294
+ );
295
+ learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
296
+ }
297
+
298
+ if ( $atts['show_review'] ) {
299
+ $course_review = learn_press_get_course_review( $course_id, 1, $atts['display_amount'] );
300
+ learn_press_course_review_template(
301
+ 'shortcode-course-review.php',
302
+ array(
303
+ 'course_id' => $course_id,
304
+ 'course_review' => $course_review,
305
+ )
306
+ );
307
+ }
308
+
309
+ $content = ob_get_contents();
310
+ ob_clean();
311
+
312
+ return $content;
313
+ }
314
+
315
+ public function load_widget() {
316
+ register_widget( 'LearnPress_Course_Review_Widget' );
317
+ }
318
+
319
+
320
+ public function add_course_tab_reviews( $tabs ) {
321
+ $tabs['reviews'] = array(
322
+ 'title' => __( 'Reviews', 'learnpress-course-review' ),
323
+ 'priority' => 60,
324
+ 'callback' => array( $this, 'add_course_tab_reviews_callback' ),
325
+ );
326
+
327
+ return $tabs;
328
+ }
329
+
330
+ public function add_course_tab_reviews_callback() {
331
+ $user = learn_press_get_current_user();
332
+ $course_id = learn_press_get_course_id();
333
+ $this->print_rate();
334
+ $this->print_review();
335
+ if ( $user->has_course_status( $course_id, array( 'enrolled', 'completed', 'finished' ) ) ) {
336
+ $this->add_review_button();
337
+ }
338
+ }
339
+
340
+ public function learnpress_is_active() {
341
+ if ( ! function_exists( 'is_plugin_active' ) ) {
342
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
343
+ }
344
+
345
+ return is_plugin_active( 'learnpress/learnpress.php' );
346
+ }
347
+ }
348
+ }
349
+
350
+ add_action( 'plugins_loaded', array( 'LP_Addon_Course_Review', 'instance' ) );
inc/rest-api/class-lp-rest-review-v1-controller.php ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * REST API for the Course Review Add-on.
4
+ *
5
+ * @package LearnPress/JWT/RESTAPI
6
+ * @author Nhamdv <daonham95@gmail.com>
7
+ */
8
+ if ( class_exists( 'LP_REST_Jwt_Posts_Controller' ) ) {
9
+ class LP_Jwt_Course_Review_V1_Controller extends LP_REST_Jwt_Controller {
10
+ protected $namespace = 'learnpress/v1';
11
+
12
+ protected $rest_base = 'review';
13
+
14
+ public function register_routes() {
15
+ register_rest_route(
16
+ $this->namespace,
17
+ '/' . $this->rest_base . '/course/(?P<id>[\d]+)',
18
+ array(
19
+ array(
20
+ 'methods' => WP_REST_Server::READABLE,
21
+ 'callback' => array( $this, 'get_item_review' ),
22
+ 'permission_callback' => '__return_true',
23
+ 'args' => array(
24
+ 'page' => array(
25
+ 'description' => esc_html__( 'Paged', 'learnpress' ),
26
+ 'type' => 'integer',
27
+ 'sanitize_callback' => 'absint',
28
+ ),
29
+ 'per_page' => array(
30
+ 'description' => esc_html__( 'Per page', 'learnpress' ),
31
+ 'type' => 'integer',
32
+ 'sanitize_callback' => 'absint',
33
+ ),
34
+ ),
35
+ ),
36
+ )
37
+ );
38
+
39
+ register_rest_route(
40
+ $this->namespace,
41
+ '/' . $this->rest_base . '/submit',
42
+ array(
43
+ array(
44
+ 'methods' => WP_REST_Server::CREATABLE,
45
+ 'callback' => array( $this, 'submit_review' ),
46
+ 'permission_callback' => '__return_true',
47
+ 'args' => array(
48
+ 'id' => array(
49
+ 'description' => esc_html__( 'Course ID', 'learnpress' ),
50
+ 'type' => 'integer',
51
+ 'sanitize_callback' => 'absint',
52
+ ),
53
+ 'rate' => array(
54
+ 'description' => esc_html__( 'Rate', 'learnpress' ),
55
+ 'type' => 'integer',
56
+ 'sanitize_callback' => 'absint',
57
+ ),
58
+ 'title' => array(
59
+ 'description' => esc_html__( 'Title', 'learnpress' ),
60
+ 'type' => 'string',
61
+ 'sanitize_callback' => 'sanitize_text_field',
62
+ ),
63
+ 'content' => array(
64
+ 'description' => esc_html__( 'Content', 'learnpress' ),
65
+ 'type' => 'string',
66
+ 'sanitize_callback' => 'sanitize_text_field',
67
+ ),
68
+ ),
69
+ ),
70
+ )
71
+ );
72
+ }
73
+
74
+ protected function check_can_review( $course_id ) {
75
+ $user_id = get_current_user_id();
76
+ $user = learn_press_get_user( $user_id );
77
+
78
+ $can_review = false;
79
+
80
+ if ( $user->has_course_status( $course_id, array( 'enrolled', 'completed', 'finished' ) ) && ! $this->user_get_comment( $course_id ) ) {
81
+ $can_review = true;
82
+ }
83
+
84
+ return $can_review;
85
+ }
86
+
87
+ protected function user_get_comment( $course_id ) {
88
+ static $comments;
89
+
90
+ if ( ! isset( $comments ) ) {
91
+ $comments = learn_press_get_user_rate( $course_id, get_current_user_id(), true );
92
+ }
93
+
94
+ return $comments;
95
+ }
96
+
97
+ public function get_item_review( $request ) {
98
+ $course_id = $request->get_param( 'id' );
99
+ $paged = ! empty( $request->get_param( 'page' ) ) ? absint( $request->get_param( 'page' ) ) : 1;
100
+ $per_page = ! empty( $request->get_param( 'per_page' ) ) ? absint( $request->get_param( 'per_page' ) ) : LP_ADDON_COURSE_REVIEW_PER_PAGE;
101
+
102
+ $response = new LP_REST_Response();
103
+ $response->data = new stdClass();
104
+
105
+ try {
106
+ if ( empty( $course_id ) ) {
107
+ throw new Exception( esc_html__( 'No Course ID param.', 'learnpress' ) );
108
+ }
109
+
110
+ $course = learn_press_get_course( $course_id );
111
+
112
+ if ( ! $course ) {
113
+ throw new Exception( esc_html__( 'Course not found.', 'learnpress' ) );
114
+ }
115
+
116
+ $user = learn_press_get_current_user();
117
+
118
+ $course_rate = learn_press_get_course_rate( $course_id, false );
119
+
120
+ $course_review = learn_press_get_course_review( $course_id, $paged, $per_page, true );
121
+
122
+ $response->data->rated = ! empty( $course_rate['rated'] ) ? number_format( $course_rate['rated'], 1 ) : 0;
123
+ $response->data->total = ! empty( $course_rate['total'] ) ? absint( $course_rate['total'] ) : 0;
124
+ $response->data->items = ! empty( $course_rate['items'] ) ? $course_rate['items'] : array();
125
+ $response->data->reviews = ! empty( $course_review ) ? $course_review : array();
126
+
127
+ $can_review = $this->check_can_review( $course_id );
128
+ $response->data->can_review = $can_review;
129
+
130
+ if ( ! $can_review ) {
131
+ $review = $this->user_get_comment( $course_id );
132
+
133
+ if ( $review && ! $review->comment_approved ) {
134
+ $response->data->comment_approved = 0;
135
+ $response->message = esc_html__( 'You have already reviewed this course. It will be visible after it has been approved', 'learnpress' );
136
+ }
137
+ }
138
+
139
+ $response->status = 'success';
140
+ } catch ( \Throwable $th ) {
141
+ $response->message = $th->getMessage();
142
+ }
143
+
144
+ return rest_ensure_response( $response );
145
+ }
146
+
147
+ public function submit_review( $request ) {
148
+ $course_id = $request->get_param( 'id' );
149
+ $rate = $request->get_param( 'rate' );
150
+ $title = $request->get_param( 'title' );
151
+ $content = $request->get_param( 'content' );
152
+
153
+ $user_id = get_current_user_id();
154
+ $response = new LP_REST_Response();
155
+
156
+ try {
157
+ if ( empty( $course_id ) ) {
158
+ throw new Exception( esc_html__( 'No Course ID param.', 'learnpress' ) );
159
+ }
160
+
161
+ if ( empty( $user_id ) ) {
162
+ throw new Exception( esc_html__( 'No User.', 'learnpress' ) );
163
+ }
164
+
165
+ if ( ! $this->check_can_review( $course_id ) ) {
166
+ throw new Exception( esc_html__( 'You can not submit review.', 'learnpress' ) );
167
+ }
168
+
169
+ $add_review = learn_press_add_course_review(
170
+ array(
171
+ 'user_id' => $user_id,
172
+ 'course_id' => $course_id,
173
+ 'rate' => ! empty( $rate ) ? $rate : 0,
174
+ 'title' => ! empty( $title ) ? $title : '',
175
+ 'content' => ! empty( $content ) ? $content : '',
176
+ 'force' => true, // Not use cache.
177
+ )
178
+ );
179
+
180
+ if ( $add_review ) {
181
+ $response->data->comment_id = $add_review;
182
+ $response->message = is_admin() ? esc_html__( 'Your review submitted successfully', 'learnpress' ) : esc_html__( 'Thank you for your review. Your review will be visible after it has been approved', 'learnpress' );
183
+ $response->status = 'success';
184
+
185
+ // Clear cache
186
+ wp_cache_delete( 'course-' . $course_id, 'lp-course-ratings' );
187
+ } else {
188
+ throw new Exception( esc_html__( 'Cannot submit your review.', 'learnpress' ) );
189
+ }
190
+ } catch ( \Throwable $th ) {
191
+ $response->message = $th->getMessage();
192
+ }
193
+
194
+ return rest_ensure_response( $response );
195
+ }
196
+ }
197
+ }
inc/rest-api/class-rest-api.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Register Rest API
4
+ *
5
+ * @author Nhamdv <daonham95@gmail.com>
6
+ *
7
+ */
8
+ class LP_Course_Review_Rest_API {
9
+ protected static $instance = null;
10
+
11
+ public function __construct() {
12
+ add_filter( 'lp_rest_api_get_rest_namespaces', array( $this, 'rest_api_init' ) );
13
+ }
14
+
15
+ public function rest_api_init( $data ) {
16
+ $data['learnpress/v1']['review'] = 'LP_Jwt_Course_Review_V1_Controller';
17
+
18
+ return $data;
19
+ }
20
+
21
+ public static function instance() {
22
+ if ( null === static::$instance ) {
23
+ static::$instance = new static();
24
+ }
25
+ return static::$instance;
26
+ }
27
+ }
28
+
29
+ LP_Course_Review_Rest_API::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,86 @@
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();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 4.0.3
8
+ * Author URI: http://thimpress.com
9
+ * Tags: learnpress
10
+ * Requires at least: 3.8
11
+ * Tested up to: 5.7
12
+ * Text Domain: learnpress-course-review
13
+ * Domain Path: /languages/
14
+ * Require_LP_Version: 3.0.0
15
+ *
16
+ * @package learnpress-course-review
17
+ */
18
+
19
+ defined( 'ABSPATH' ) || exit;
20
+
21
+ const LP_ADDON_COURSE_REVIEW_FILE = __FILE__;
22
+
23
+ /**
24
+ * Class LP_Addon_Course_Review_Preload
25
+ */
26
+ class LP_Addon_Course_Review_Preload {
27
+ /**
28
+ * @var array|string[]
29
+ */
30
+ public static $addon_info = array();
31
+
32
+ /**
33
+ * LP_Addon_Course_Review_Preload constructor.
34
+ */
35
+ public function __construct() {
36
+ // Set Base name plugin.
37
+ define( 'LP_ADDON_COURSE_REVIEW_BASENAME', plugin_basename( LP_ADDON_COURSE_REVIEW_FILE ) );
38
+
39
+ // Set version addon for LP check .
40
+ include_once ABSPATH . 'wp-admin/includes/plugin.php';
41
+ self::$addon_info = get_file_data(
42
+ LP_ADDON_COURSE_REVIEW_FILE,
43
+ array(
44
+ 'Name' => 'Plugin Name',
45
+ 'Require_LP_Version' => 'Require_LP_Version',
46
+ 'Version' => 'Version',
47
+ )
48
+ );
49
+
50
+ define( 'LP_ADDON_COURSE_REVIEW_VER', self::$addon_info['Version'] );
51
+ define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', self::$addon_info['Require_LP_Version'] );
52
+
53
+ // Check LP activated .
54
+ if ( ! is_plugin_active( 'learnpress/learnpress.php' ) ) {
55
+ add_action( 'admin_notices', array( $this, 'show_note_errors_require_lp' ) );
56
+
57
+ deactivate_plugins( LP_ADDON_COURSE_REVIEW_BASENAME );
58
+
59
+ if ( isset( $_GET['activate'] ) ) {
60
+ unset( $_GET['activate'] );
61
+ }
62
+
63
+ return;
64
+ }
65
+
66
+ // Sure LP loaded.
67
+ add_action( 'learn-press/ready', array( $this, 'load' ) );
68
+ }
69
+
70
+ /**
71
+ * Load addon
72
+ */
73
+ public function load() {
74
+ LP_Addon::load( 'LP_Addon_Course_Review', 'inc/load.php', __FILE__ );
75
+ }
76
+
77
+ public function show_note_errors_require_lp() {
78
+ ?>
79
+ <div class="notice notice-error">
80
+ <p><?php echo( 'Please active <strong>LearnPress version ' . LP_ADDON_COURSE_REVIEW_REQUIRE_VER . ' or later</strong> before active <strong>' . self::$addon_info['Name'] . '</strong>' ); ?></p>
81
+ </div>
82
+ <?php
83
+ }
84
+ }
85
+
86
+ new LP_Addon_Course_Review_Preload();
readme.txt CHANGED
@@ -1,61 +1,75 @@
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
 
@@ -96,16 +110,16 @@ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPr
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>
1
+ === LearnPress - Course Review ===
2
+ Contributors: thimpress
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
+ Requires PHP: 7.0
7
+ Tested up to: 6.0
8
+ Stable tag: 4.0.3
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
+ LearnPress Course Review - An extension plugin for LearnPress.
13
 
14
+ == Description ==
15
 
16
  **LearnPress** is a <a href="http://thimpress.com/learnpress">WordPress LMS Plugin</a> by ThimPress.
17
 
18
+ 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.
19
 
20
  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.
21
 
22
+ **Other free add-ons for LearnPress are available in WordPress:**
23
 
24
+ - <a href="https://wordpress.org/plugins/learnpress-wishlist/" target="_blank">LearnPress Wishlist</a> - add courses to a wishlist for students.
25
+ - <a href="https://wordpress.org/plugins/learnpress-course-review/" target="_blank">LearnPress Course Review</a> - review course for enrolled students.
26
+ - <a href="https://wordpress.org/plugins/learnpress-import-export/" target="_blank">LearnPress Import Export</a> - export or import course or courses out-of-box.
27
+ - <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.
28
+ - <a href="https://wordpress.org/plugins/learnpress-bbpress" target="_blank">LearnPress bbPress</a> - add bbPress Forum support for LearnPress.
29
+ - <a href="https://wordpress.org/plugins/learnpress-buddypress" target="_blank">LearnPress BuddyPress</a> - add BuddyPress support for LearnPress.
30
 
31
  **Premium Plugins (add-ons) for LearnPress WordPress LMS Plugin**
32
 
33
+ - <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.
34
+ - <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.
35
+ - <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.
36
+ - <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.
37
  - <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.
38
 
39
+ == Installation ==
40
 
41
+ **From your WordPress dashboard**
42
+ 1. Visit 'Plugin > Add new'.
43
+ 2. Search for 'LearnPress Course Review'.
44
+ 3. Activate LearnPress from your Plugins page.
45
 
46
+ **From WordPress.org**
47
+ 1. Search, select and download LearnPress Course Review.
48
  2. Activate the plugin through the 'Plugins' menu in WordPress Dashboard.
49
 
50
  == Frequently Asked Questions ==
51
 
52
+ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPress</a> sites.
53
 
54
+ == Screenshots ==
55
 
56
+ 1. LearnPress Course Review screenshot.
57
 
58
  == Changelog ==
59
 
60
+ = 4.0.3 =
61
+ ~ Update review api.
62
+ ~ Fix minor bugs.
63
+
64
+ = 4.0.2 =
65
+ ~ Fix minor bug.
66
+
67
+ = 4.0.1 =
68
+ ~ Fix show icon star on the shortcode.
69
+
70
+ = 4.0.0 =
71
+ ~ Fix compatible LP4.
72
+
73
  = 3.0.5 =
74
  ~ Fixed an issue when checking if the user rated or not!
75
 
110
  = 1.0 =
111
  + Compatible with LearnPress version 1.0
112
 
113
+ = 0.9.1 =
114
+ - Updated languages file
115
  - Fixed PHP5 version 5.3.x error
116
 
117
+ = 0.9.0 =
118
+ - The first beta release.
119
 
120
+ == Upgrade Notice ==
121
  Later :)
122
 
123
+ == Other note ==
124
+ <a href="http://docs.thimpress.com/learnpress" target="_blank">Documentation</a> is available in ThimPress site.
125
+ <a href="https://github.com/LearnPress/LearnPress/" target="_blank">LearnPress github repo.</a>
templates/course-rate-old.php ADDED
@@ -0,0 +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>
templates/course-rate.php CHANGED
@@ -1,48 +1,81 @@
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
+ <div class="course-rate__message">
23
+ <?php
24
+ $user_id = learn_press_get_current_user_id();
25
+ if ( ! empty( $user_id ) ) {
26
+ $args = array(
27
+ 'user_id' => $user_id,
28
+ 'post_id' => $course_id,
29
+ );
30
+ $comments = get_comments( $args );
31
+
32
+ if ( ! empty( $comments ) ) {
33
+ $comment_id = $comments[0]->comment_ID;
34
+ $status = wp_get_comment_status( $comment_id );
35
+ if ( 'approved' !== $status ) {
36
+ echo learn_press_get_message( __('Thank you for your review. Your review will be visible after it has been approved!'), 'success' );
37
+ }
38
+ }
39
+ }
40
+
41
+ ?>
42
+ </div>
43
+ <div class="course-rate__summary">
44
+ <div class="course-rate__summary-value"><?php echo number_format( $course_rate, 1 ); ?></div>
45
+ <div class="course-rate__summary-stars">
46
+ <?php
47
+ learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
48
+ ?>
49
+ </div>
50
+ <div class="course-rate__summary-text">
51
+ <?php printf( __( '<span>%d</span> total', 'learnpress-course-review' ), $total ); ?>
52
+ </div>
53
+
54
+ </div>
55
+
56
+ <div class="course-rate__details">
57
+ <?php
58
+ foreach ( $course_rate_res['items'] as $item ) :
59
+ ?>
60
+ <div class="course-rate__details-row">
61
+ <span class="course-rate__details-row-star">
62
+ <?php esc_html_e( $item['rated'] ); ?>
63
+ <i class="fas" style="color: #ffb60a">
64
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
65
+ <path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
66
+ </svg>
67
+ </i>
68
+ </span>
69
+ <div class="course-rate__details-row-value">
70
+ <div class="rating-gray"></div>
71
+ <div class="rating" style="width:<?php echo $item['percent']; ?>%;"
72
+ title="<?php echo esc_attr( $item['percent'] ); ?>%">
73
+ </div>
74
+ <span class="rating-count"><?php echo $item['total']; ?></span>
75
+ </div>
76
+ </div>
77
+ <?php
78
+ endforeach;
79
+ ?>
80
+ </div>
81
+ </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,34 @@
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.6
10
+ */
11
+
12
+ // Prevent loading this file directly
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ $percent = ( ! isset( $rated ) ) ? 0 : min( 100, ( round( ( int ) $rated * 2 ) / 2 ) * 20 );
16
+ $title = sprintf( __( '%s out of 5 stars', 'learnpress-course-review' ), round( ( int ) $rated, 2 ) );
17
+
18
+ ?>
19
+ <div class="review-stars-rated" title="<?php echo esc_attr( $title ); ?>">
20
+ <?php for ( $i = 1; $i <= 5; $i ++ ) {
21
+ $p = ( $i * 20 );
22
+ $r = max( $p <= $percent ? 100 : ( $percent - ( $i - 1 ) * 20 ) * 5, 0 );
23
+
24
+ ?>
25
+ <div class="review-star">
26
+ <i class="far"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
27
+ <path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
28
+ </svg></i>
29
+ <i class="fas" style="width:<?php echo $r; ?>%;"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
30
+ <path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
31
+ </svg></i>
32
+ </div>
33
+ <?php } ?>
34
+ </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
  }