Version Description
- Compatible with Learnpress 3.0.0
Download this release
Release Info
Developer | leehld |
Plugin | LearnPress – Course Review |
Version | 3.0.0 |
Comparing to | |
See all releases |
Code changes from version 2.0 to 3.0.0
- assets/course-review.css +0 -225
- assets/{admin.css → css/admin.css} +0 -0
- assets/css/course-review.css +262 -0
- assets/{course-review.js → js/course-review.js} +1 -1
- inc/functions.php +431 -0
- inc/load.php +292 -0
- inc/widgets.php +131 -0
- incs/review-functions.php +0 -328
- incs/review-widgets.php +0 -99
- languages/learnpress-course-review.pot +94 -25
- languages/learnpress-course-review.temp +99 -99
- learnpress-course-review.php +43 -264
- readme.txt +15 -7
- templates/course-rate.php +27 -22
- templates/course-review.php +28 -20
- templates/loop-review.php +38 -21
- templates/rating-stars.php +20 -3
- templates/review-form.php +45 -40
- templates/shortcode-course-rate.php +32 -21
- templates/shortcode-course-review.php +26 -17
assets/course-review.css
DELETED
@@ -1,225 +0,0 @@
|
|
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 h3 {
|
35 |
-
font-size: 16px;
|
36 |
-
margin: 0 0 20px;
|
37 |
-
}
|
38 |
-
|
39 |
-
.review-form h3 .close {
|
40 |
-
float: right;
|
41 |
-
border: none;
|
42 |
-
text-decoration: none;
|
43 |
-
width: auto;
|
44 |
-
height: auto;
|
45 |
-
margin-right: -9px;
|
46 |
-
margin-top: -7px;
|
47 |
-
}
|
48 |
-
|
49 |
-
.review-form h3 .close:before {
|
50 |
-
font-size: 32px;
|
51 |
-
}
|
52 |
-
|
53 |
-
.review-form .review-fields {
|
54 |
-
margin: 0 0 -20px;
|
55 |
-
list-style: none;
|
56 |
-
}
|
57 |
-
|
58 |
-
.review-form .review-fields > li {
|
59 |
-
margin: 0 0 20px 0;
|
60 |
-
}
|
61 |
-
|
62 |
-
.review-form .review-fields > li > label {
|
63 |
-
display: block;
|
64 |
-
margin: 0 0 7px;
|
65 |
-
font-size: 15px;
|
66 |
-
}
|
67 |
-
|
68 |
-
.review-form .review-fields > li > label .required {
|
69 |
-
margin-left: 5px;
|
70 |
-
display: inline-block;
|
71 |
-
vertical-align: middle;
|
72 |
-
font-size: 24px;
|
73 |
-
line-height: 1;
|
74 |
-
height: 15px;
|
75 |
-
margin-top: -3px;
|
76 |
-
}
|
77 |
-
|
78 |
-
.review-form .review-fields > li input[type="text"],
|
79 |
-
.review-form .review-fields > li textarea {
|
80 |
-
width: 100%;
|
81 |
-
}
|
82 |
-
|
83 |
-
.review-stars {
|
84 |
-
margin: 0 0;
|
85 |
-
list-style: none;
|
86 |
-
overflow: hidden;
|
87 |
-
}
|
88 |
-
|
89 |
-
.review-stars:after {
|
90 |
-
clear: both;
|
91 |
-
content: '';
|
92 |
-
display: block;
|
93 |
-
}
|
94 |
-
|
95 |
-
.review-stars > li {
|
96 |
-
width: 24px;
|
97 |
-
height: 24px;
|
98 |
-
float: left;
|
99 |
-
}
|
100 |
-
|
101 |
-
.review-stars > li span {
|
102 |
-
text-decoration: none;
|
103 |
-
font-size: 24px;
|
104 |
-
border-bottom: none;
|
105 |
-
width: auto;
|
106 |
-
height: auto;
|
107 |
-
}
|
108 |
-
|
109 |
-
.review-stars > li a:visited,
|
110 |
-
.review-stars > li a:focus {
|
111 |
-
border: none;
|
112 |
-
}
|
113 |
-
|
114 |
-
.review-stars > li span:before {
|
115 |
-
width: 22px;
|
116 |
-
height: 24px;
|
117 |
-
}
|
118 |
-
|
119 |
-
.review-stars > li span.hover:before {
|
120 |
-
content: "\f155";
|
121 |
-
color: #F05A19;
|
122 |
-
cursor: pointer;
|
123 |
-
}
|
124 |
-
|
125 |
-
.review-form .ajaxload,
|
126 |
-
.review-form .message {
|
127 |
-
display: none;
|
128 |
-
}
|
129 |
-
|
130 |
-
.course-review-wrapper.submitting .ajaxload,
|
131 |
-
.course-review-wrapper.error .message {
|
132 |
-
display: inline-block;
|
133 |
-
}
|
134 |
-
|
135 |
-
.review-stars-rated {
|
136 |
-
width: 90px;
|
137 |
-
position: relative;
|
138 |
-
display: inline-block;
|
139 |
-
}
|
140 |
-
|
141 |
-
.review-stars-rated .review-stars.empty,
|
142 |
-
.review-stars-rated .review-stars.filled {
|
143 |
-
width: 120px;
|
144 |
-
height: 24px;
|
145 |
-
font-family: dashicons;
|
146 |
-
font-size: 18px;
|
147 |
-
color: #f2b827;
|
148 |
-
}
|
149 |
-
|
150 |
-
.review-stars-rated .review-stars.empty:before {
|
151 |
-
content: '\f154\f154\f154\f154\f154';
|
152 |
-
line-height: 1;
|
153 |
-
vertical-align: top;
|
154 |
-
}
|
155 |
-
|
156 |
-
.review-stars-rated .review-stars.filled:before {
|
157 |
-
content: '\f155\f155\f155\f155\f155';
|
158 |
-
line-height: 1;
|
159 |
-
vertical-align: top;
|
160 |
-
}
|
161 |
-
|
162 |
-
.review-stars-rated .review-stars.filled {
|
163 |
-
position: absolute;
|
164 |
-
top: 0;
|
165 |
-
left: 0;
|
166 |
-
}
|
167 |
-
|
168 |
-
.course-rate {
|
169 |
-
overflow: hidden;
|
170 |
-
margin: 10px 0;
|
171 |
-
}
|
172 |
-
|
173 |
-
.course-rate .review-bar {
|
174 |
-
width: calc(100% - 125px);
|
175 |
-
margin-right: 5px;
|
176 |
-
height: 15px;
|
177 |
-
background: #DDD;
|
178 |
-
display: inline-block;
|
179 |
-
}
|
180 |
-
|
181 |
-
.course-rate .review-bar .rating {
|
182 |
-
background: #95e6f9;
|
183 |
-
height: 15px;
|
184 |
-
}
|
185 |
-
|
186 |
-
.course-rate .review-number {
|
187 |
-
margin-bottom: 0;
|
188 |
-
}
|
189 |
-
|
190 |
-
.course-reviews-list {
|
191 |
-
list-style: none;
|
192 |
-
margin: 0;
|
193 |
-
}
|
194 |
-
|
195 |
-
.course-reviews-list li {
|
196 |
-
margin-bottom: 20px;
|
197 |
-
padding: 20px;
|
198 |
-
background-color: #fafafa;
|
199 |
-
border: 1px solid #ddd;
|
200 |
-
overflow: hidden;
|
201 |
-
}
|
202 |
-
|
203 |
-
.course-reviews-list li .review-author {
|
204 |
-
width: 80px;
|
205 |
-
float: left;
|
206 |
-
margin-right: 20px;
|
207 |
-
}
|
208 |
-
|
209 |
-
.course-reviews-list li .review-text {
|
210 |
-
width: -webkit-calc(100% - 100px);
|
211 |
-
float: left;
|
212 |
-
}
|
213 |
-
|
214 |
-
.course-reviews-list li .user-name {
|
215 |
-
margin: 5px;
|
216 |
-
}
|
217 |
-
|
218 |
-
.course-reviews-list li .review-title {
|
219 |
-
clear: both;
|
220 |
-
font-size: 14px;
|
221 |
-
font-style: italic;
|
222 |
-
font-weight: 700;
|
223 |
-
line-height: 25px;
|
224 |
-
margin: 9px 0 15px;
|
225 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assets/{admin.css → css/admin.css}
RENAMED
File without changes
|
assets/css/course-review.css
ADDED
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 {
|
217 |
+
list-style: none;
|
218 |
+
margin: 0;
|
219 |
+
}
|
220 |
+
|
221 |
+
.course-reviews-list 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 {
|
230 |
+
width: 80px;
|
231 |
+
float: left;
|
232 |
+
margin-right: 20px;
|
233 |
+
}
|
234 |
+
|
235 |
+
.course-reviews-list li .review-author-info {
|
236 |
+
float: left;
|
237 |
+
}
|
238 |
+
|
239 |
+
.course-reviews-list li .review-text {
|
240 |
+
width: -webkit-calc(100% - 100px);
|
241 |
+
float: right;
|
242 |
+
}
|
243 |
+
|
244 |
+
.course-reviews-list li .user-name {
|
245 |
+
margin: 5px;
|
246 |
+
}
|
247 |
+
|
248 |
+
.course-reviews-list 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 {
|
259 |
+
width: 100%;
|
260 |
+
float: left;
|
261 |
+
}
|
262 |
+
}
|
assets/{course-review.js → js/course-review.js}
RENAMED
@@ -83,7 +83,7 @@
|
|
83 |
return;
|
84 |
}
|
85 |
|
86 |
-
if (
|
87 |
alert(learn_press_course_review.localize.empty_rating)
|
88 |
return;
|
89 |
}
|
83 |
return;
|
84 |
}
|
85 |
|
86 |
+
if (0 == rating) {
|
87 |
alert(learn_press_course_review.localize.empty_rating)
|
88 |
return;
|
89 |
}
|
inc/functions.php
ADDED
@@ -0,0 +1,431 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* LearnPress Course Review Functions
|
4 |
+
*
|
5 |
+
* Define common functions for both front-end and back-end
|
6 |
+
*
|
7 |
+
* @author ThimPress
|
8 |
+
* @package LearnPress/Course-Review/Functions
|
9 |
+
* @version 3.0.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
// Prevent loading this file directly
|
13 |
+
defined( 'ABSPATH' ) || exit;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @param int $course_id
|
17 |
+
* @param int $paged
|
18 |
+
* @param int $per_page
|
19 |
+
* @param boolean $force
|
20 |
+
*
|
21 |
+
* @return mixed
|
22 |
+
*/
|
23 |
+
function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_ADDON_COURSE_REVIEW_PER_PAGE, $force = false ) {
|
24 |
+
|
25 |
+
$key = 'course-' . md5( serialize( array( $course_id, $paged, $per_page ) ) );
|
26 |
+
|
27 |
+
if ( false === ( $results = wp_cache_get( $key, 'lp-course-review' ) ) || $force ) {
|
28 |
+
|
29 |
+
global $wpdb;
|
30 |
+
$per_page = absint( apply_filters( 'learn_press_course_reviews_per_page', $per_page ) );
|
31 |
+
$paged = absint( $paged );
|
32 |
+
|
33 |
+
if ( $per_page == 0 ) {
|
34 |
+
$per_page = 9999999;
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( $paged == 0 ) {
|
38 |
+
$paged = 1;
|
39 |
+
}
|
40 |
+
|
41 |
+
$start = ( $paged - 1 ) * $per_page;
|
42 |
+
$start = max( $start, 0 );
|
43 |
+
$per_page = max( $per_page, 1 );
|
44 |
+
$results = array(
|
45 |
+
'reviews' => array(),
|
46 |
+
'paged' => $paged,
|
47 |
+
'total' => 0,
|
48 |
+
'per_page' => $per_page
|
49 |
+
);
|
50 |
+
|
51 |
+
$query = $wpdb->prepare( "
|
52 |
+
SELECT SQL_CALC_FOUND_ROWS u.*, c.comment_ID as comment_id, cm1.meta_value as title, c.comment_content as content, cm2.meta_value as rate
|
53 |
+
FROM {$wpdb->posts} p
|
54 |
+
INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
|
55 |
+
INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
|
56 |
+
INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key = %s
|
57 |
+
INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key = %s
|
58 |
+
WHERE p.ID = %d AND c.comment_type = %s AND c.comment_approved = %d
|
59 |
+
ORDER BY c.comment_date DESC
|
60 |
+
LIMIT %d, %d
|
61 |
+
", '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1, $start, $per_page );
|
62 |
+
|
63 |
+
$course_review = $wpdb->get_results( $query );
|
64 |
+
|
65 |
+
if ( $course_review ) {
|
66 |
+
$ratings = _learn_press_get_ratings( $course_id );
|
67 |
+
$results['reviews'] = $course_review;
|
68 |
+
$results['total'] = $ratings[ $course_id ]['total'];
|
69 |
+
if ( $results['total'] <= $start + $per_page ) {
|
70 |
+
$results['finish'] = true;
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
wp_cache_set( $key, $results, 'lp-course-review' );
|
75 |
+
}
|
76 |
+
|
77 |
+
return $results;
|
78 |
+
}
|
79 |
+
|
80 |
+
function _learn_press_get_ratings( $course_id ) {
|
81 |
+
|
82 |
+
static $course_rates = array();
|
83 |
+
if ( ! is_array( $course_id ) ) {
|
84 |
+
$ids = array( $course_id );
|
85 |
+
} else {
|
86 |
+
$ids = $course_id;
|
87 |
+
}
|
88 |
+
foreach ( $ids as $cid ) {
|
89 |
+
if ( ! isset( $course_rates[ $cid ] ) ) {
|
90 |
+
$course_rates[ $cid ] = leanr_press_get_ratings_result( $cid );
|
91 |
+
}
|
92 |
+
}
|
93 |
+
|
94 |
+
return $course_rates;
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @param $course_id
|
100 |
+
* @param $field
|
101 |
+
*
|
102 |
+
* @return mixed
|
103 |
+
*/
|
104 |
+
function learn_press_get_course_rate( $course_id, $field = 'rated' ) {
|
105 |
+
$ratings = _learn_press_get_ratings( $course_id );
|
106 |
+
$rate = ( $field && array_key_exists( $field, $ratings[ $course_id ] ) ) ? $ratings[ $course_id ][ $field ] : $ratings[ $course_id ];
|
107 |
+
|
108 |
+
return apply_filters( 'learn_press_get_course_rate', $rate );
|
109 |
+
}
|
110 |
+
|
111 |
+
function learn_press_get_course_rate_total( $course_id, $field = 'total' ) {
|
112 |
+
/*global $wpdb;
|
113 |
+
$query = $wpdb->prepare( "
|
114 |
+
SELECT COUNT(*)
|
115 |
+
FROM {$wpdb->posts} p
|
116 |
+
INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
|
117 |
+
INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
|
118 |
+
INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
|
119 |
+
INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
|
120 |
+
WHERE p.ID=%d AND c.comment_type=%s and c.comment_approved = %d
|
121 |
+
ORDER BY c.comment_date DESC",
|
122 |
+
'_lpr_review_title', '_lpr_rating', $course_id, 'review', 1
|
123 |
+
);
|
124 |
+
$total = $wpdb->get_var( $query );*/
|
125 |
+
|
126 |
+
$ratings = _learn_press_get_ratings( $course_id );
|
127 |
+
$total = array_key_exists( $field, $ratings[ $course_id ] ) ? $ratings[ $course_id ][ $field ] : $ratings;
|
128 |
+
|
129 |
+
return apply_filters( 'learn_press_get_course_rate_total', $total );
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* @param $course_id
|
134 |
+
* @param $user_id
|
135 |
+
*
|
136 |
+
* @return string
|
137 |
+
*/
|
138 |
+
function learn_press_get_user_review_title( $course_id, $user_id ) {
|
139 |
+
$course_review = get_post_meta( $course_id, '_lpr_course_review', true );
|
140 |
+
|
141 |
+
if ( $course_review && array_key_exists( $user_id, $course_review['review_title'] ) ) {
|
142 |
+
return apply_filters( 'learn_press_get_user_review', $course_review['review_title'][ $user_id ] );
|
143 |
+
}
|
144 |
+
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Get the rating user has posted for a course.
|
150 |
+
*
|
151 |
+
* @param int $course_id
|
152 |
+
* @param int $user_id
|
153 |
+
*
|
154 |
+
* @return mixed
|
155 |
+
*/
|
156 |
+
function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
|
157 |
+
if ( ! $user_id ) {
|
158 |
+
$user_id = get_current_user_id();
|
159 |
+
}
|
160 |
+
if ( ! $course_id ) {
|
161 |
+
$course_id = get_the_ID();
|
162 |
+
}
|
163 |
+
|
164 |
+
// Get in cache if it is already get
|
165 |
+
if ( false === ( $comment = wp_cache_get( 'user-' . $user_id . '/' . $course_id, 'lp-user-rate' ) ) ) {
|
166 |
+
global $wpdb;
|
167 |
+
$query = $wpdb->prepare( "
|
168 |
+
SELECT *
|
169 |
+
FROM {$wpdb->posts} p
|
170 |
+
INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
|
171 |
+
WHERE c.comment_post_ID = %d
|
172 |
+
AND c.user_id = %d
|
173 |
+
AND c.comment_type = %s
|
174 |
+
", $course_id, $user_id, 'review' );
|
175 |
+
|
176 |
+
$comment = $wpdb->get_row( $query );
|
177 |
+
|
178 |
+
if ( $comment ) {
|
179 |
+
$comment->comment_title = get_comment_meta( $comment->comment_ID, '_lpr_review_title', true );
|
180 |
+
$comment->rating = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
|
181 |
+
}
|
182 |
+
|
183 |
+
wp_cache_set( 'user-' . $user_id . '/' . $course_id, $comment, 'lp-user-rate' );
|
184 |
+
}
|
185 |
+
|
186 |
+
return $comment;
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Add new review for a course
|
191 |
+
*
|
192 |
+
* @param array
|
193 |
+
*
|
194 |
+
* @return int
|
195 |
+
*/
|
196 |
+
function learn_press_add_course_review( $args = array() ) {
|
197 |
+
$args = wp_parse_args(
|
198 |
+
$args,
|
199 |
+
array(
|
200 |
+
'title' => '',
|
201 |
+
'content' => '',
|
202 |
+
'rate' => '',
|
203 |
+
'user_id' => 0,
|
204 |
+
'course_id' => 0
|
205 |
+
)
|
206 |
+
);
|
207 |
+
$user_id = $args['user_id'];
|
208 |
+
$course_id = $args['course_id'];
|
209 |
+
$user_review = learn_press_get_user_rate( $course_id, $user_id );
|
210 |
+
$comment_id = 0;
|
211 |
+
if ( ! $user_review ) {
|
212 |
+
$user = get_user_by( 'id', $user_id );
|
213 |
+
$comment_id = wp_new_comment(
|
214 |
+
array(
|
215 |
+
'comment_post_ID' => $course_id,
|
216 |
+
'comment_author' => 'LearnPress',
|
217 |
+
'comment_author_email' => $user->user_email,
|
218 |
+
'comment_author_url' => '',
|
219 |
+
'comment_content' => $args['content'],
|
220 |
+
'comment_parent' => 0,
|
221 |
+
'user_id' => $user->ID,
|
222 |
+
'comment_approved' => 1,
|
223 |
+
'comment_type' => 'review' // let filter to not display it as comments
|
224 |
+
)
|
225 |
+
);
|
226 |
+
}
|
227 |
+
if ( $comment_id ) {
|
228 |
+
add_comment_meta( $comment_id, '_lpr_rating', $args['rate'] );
|
229 |
+
add_comment_meta( $comment_id, '_lpr_review_title', $args['title'] );
|
230 |
+
}
|
231 |
+
|
232 |
+
return $comment_id;
|
233 |
+
}
|
234 |
+
|
235 |
+
function learn_press_course_review_template( $name, $args = null ) {
|
236 |
+
learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
|
237 |
+
}
|
238 |
+
|
239 |
+
/*
|
240 |
+
* If we are viewing archive course page, so load all ratings of courses
|
241 |
+
* into cache to reduce queries and time rather than load separate course
|
242 |
+
* in loop
|
243 |
+
*/
|
244 |
+
add_filter( 'the_posts', 'learn_press_init_courses_review' );
|
245 |
+
function learn_press_init_courses_review( $posts ) {
|
246 |
+
if ( $posts ) {
|
247 |
+
$pIds = array();
|
248 |
+
foreach ( $posts as $p ) {
|
249 |
+
$pIds[] = $p->ID;
|
250 |
+
}
|
251 |
+
_learn_press_get_ratings( $pIds );
|
252 |
+
}
|
253 |
+
|
254 |
+
return $posts;
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Get rating for a course
|
259 |
+
*
|
260 |
+
* @param int $course_id
|
261 |
+
* @param bool $get_items
|
262 |
+
*
|
263 |
+
* @return array
|
264 |
+
*/
|
265 |
+
function leanr_press_get_ratings_result( $course_id = 0, $get_items = false ) {
|
266 |
+
//return learn_press_get_ratings_result_bak($course_id);
|
267 |
+
if ( false === ( $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' ) ) ) {
|
268 |
+
global $wpdb;
|
269 |
+
|
270 |
+
$query = $wpdb->prepare( "
|
271 |
+
SELECT
|
272 |
+
cm.meta_value `rate`, COUNT(1) `count`
|
273 |
+
FROM
|
274 |
+
{$wpdb->comments} c
|
275 |
+
INNER JOIN
|
276 |
+
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
|
277 |
+
WHERE
|
278 |
+
c.comment_approved = 1
|
279 |
+
AND c.comment_type = %s
|
280 |
+
AND c.user_id > 0
|
281 |
+
AND c.comment_post_ID = %d
|
282 |
+
GROUP BY `cm`.`meta_value`
|
283 |
+
", '_lpr_rating', 'review', $course_id );
|
284 |
+
$rows = $wpdb->get_results( $query/*, OBJECT_K */ );
|
285 |
+
|
286 |
+
$count = 0;
|
287 |
+
$rate = 0;
|
288 |
+
$avg = 0;
|
289 |
+
$items = array();
|
290 |
+
|
291 |
+
for ( $i = 5; $i > 0; $i -- ) {
|
292 |
+
$items[ $i ] = array(
|
293 |
+
'rated' => $i,
|
294 |
+
'total' => 0,
|
295 |
+
'percent' => 0
|
296 |
+
);
|
297 |
+
}
|
298 |
+
|
299 |
+
if ( $rows ) {
|
300 |
+
|
301 |
+
$count = wp_list_pluck( $rows, 'count' );
|
302 |
+
$count = array_sum( $count );
|
303 |
+
$round = array();
|
304 |
+
$one_hundred = 0;
|
305 |
+
|
306 |
+
foreach ( $rows as $row ) {
|
307 |
+
$rate += $row->rate * $row->count;
|
308 |
+
$percent = $row->count / $count * 100;
|
309 |
+
$items[ $row->rate ] = array(
|
310 |
+
'rated' => $row->rate,
|
311 |
+
'total' => $row->count,
|
312 |
+
'percent' => floor( $percent ),
|
313 |
+
'percent_float' => $percent
|
314 |
+
);
|
315 |
+
$one_hundred += $items[ $row->rate ]['percent'];
|
316 |
+
$round[ $row->rate ] = $percent - floor( $percent );
|
317 |
+
}
|
318 |
+
|
319 |
+
if ( $one_hundred < 100 ) {
|
320 |
+
arsort( $round );
|
321 |
+
foreach ( $round as $key => $value ) {
|
322 |
+
$percent = $items[ $key ]['percent'];
|
323 |
+
$items[ $key ]['percent'] = ceil( $items[ $key ]['percent_float'] );
|
324 |
+
|
325 |
+
if ( $percent < $items[ $key ]['percent'] ) {
|
326 |
+
$one_hundred ++;
|
327 |
+
if ( $one_hundred == 100 ) {
|
328 |
+
break;
|
329 |
+
}
|
330 |
+
}
|
331 |
+
}
|
332 |
+
}
|
333 |
+
|
334 |
+
|
335 |
+
$avg = $rate / $count;
|
336 |
+
}
|
337 |
+
|
338 |
+
$result = array(
|
339 |
+
'course_id' => $course_id,
|
340 |
+
'total' => $count,
|
341 |
+
'rated' => $avg,
|
342 |
+
'items' => $items
|
343 |
+
);
|
344 |
+
|
345 |
+
wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings' );
|
346 |
+
}
|
347 |
+
|
348 |
+
return $result;
|
349 |
+
}
|
350 |
+
|
351 |
+
function learn_press_get_ratings_result_bak( $course_id = 0, $get_items = false ) {
|
352 |
+
|
353 |
+
if ( false === ( $result = wp_cache_get( 'course-' . $course_id, 'lp-course-ratings' ) ) ) {
|
354 |
+
LP_Debug::timeStart( 'xxxxx' );
|
355 |
+
global $wpdb;
|
356 |
+
$query = $wpdb->prepare( "
|
357 |
+
SELECT
|
358 |
+
COUNT(*) `count` ,AVG(cm.meta_value) `avg`
|
359 |
+
FROM
|
360 |
+
{$wpdb->comments} c
|
361 |
+
INNER JOIN
|
362 |
+
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
|
363 |
+
WHERE
|
364 |
+
c.comment_approved = 1
|
365 |
+
AND c.comment_type = %s
|
366 |
+
AND c.user_id > 0
|
367 |
+
AND c.comment_post_ID = %d
|
368 |
+
", '_lpr_rating', 'review', $course_id );
|
369 |
+
$row = $wpdb->get_row( $query );
|
370 |
+
|
371 |
+
$count = 0;
|
372 |
+
$avg = 0;
|
373 |
+
|
374 |
+
if ( $row ) {
|
375 |
+
$count = $row->count;
|
376 |
+
$avg = $row->avg;
|
377 |
+
}
|
378 |
+
|
379 |
+
$rows = array();
|
380 |
+
if ( $count != 0 ):
|
381 |
+
|
382 |
+
$query = $wpdb->prepare( "
|
383 |
+
SELECT
|
384 |
+
cm.meta_value `rate`, COUNT(*) `count`
|
385 |
+
FROM
|
386 |
+
{$wpdb->comments} c
|
387 |
+
INNER JOIN
|
388 |
+
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key = %s
|
389 |
+
WHERE
|
390 |
+
c.comment_approved = 1
|
391 |
+
AND c.comment_type = %s
|
392 |
+
AND c.user_id > 0
|
393 |
+
AND c.comment_post_ID = %d
|
394 |
+
GROUP BY `cm`.`meta_value`
|
395 |
+
ORDER BY `cm`.`meta_value` DESC
|
396 |
+
", '_lpr_rating', 'review', $course_id );
|
397 |
+
$rows = $wpdb->get_results( $query, OBJECT_K );
|
398 |
+
|
399 |
+
endif;
|
400 |
+
|
401 |
+
$items = array();
|
402 |
+
for ( $i = 5; $i > 0; $i -- ) {
|
403 |
+
if ( isset( $rows[ $i ] ) ) {
|
404 |
+
$items[] = array(
|
405 |
+
'rated' => $rows[ $i ]->rate,
|
406 |
+
'total' => $rows[ $i ]->count,
|
407 |
+
'percent' => $rows[ $i ]->count / $count * 100
|
408 |
+
);
|
409 |
+
} else {
|
410 |
+
$items[] = array(
|
411 |
+
'rated' => $i,
|
412 |
+
'total' => 0,
|
413 |
+
'percent' => 0
|
414 |
+
);
|
415 |
+
}
|
416 |
+
}
|
417 |
+
$result = array(
|
418 |
+
'course_id' => $course_id,
|
419 |
+
'total' => $count,
|
420 |
+
'rated' => $avg,
|
421 |
+
'items' => $items
|
422 |
+
);
|
423 |
+
LP_Debug::timeEnd( 'xxxxx' );
|
424 |
+
|
425 |
+
learn_press_debug( $result );
|
426 |
+
|
427 |
+
wp_cache_set( 'course-' . $course_id, $result, 'lp-course-ratings' );
|
428 |
+
}
|
429 |
+
|
430 |
+
return $result;
|
431 |
+
}
|
inc/load.php
ADDED
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Plugin load class.
|
4 |
+
*
|
5 |
+
* @author ThimPress
|
6 |
+
* @package LearnPress/Course-Review/Classes
|
7 |
+
* @version 3.0.0
|
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 |
+
add_shortcode( 'learnpress', array( $this, 'shortcode_review' ) );
|
77 |
+
|
78 |
+
$this->init_comment_table();
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Print rate.
|
83 |
+
*/
|
84 |
+
public function print_rate() {
|
85 |
+
learn_press_course_review_template( 'course-rate.php' );
|
86 |
+
}
|
87 |
+
|
88 |
+
/**
|
89 |
+
* Print review.
|
90 |
+
*/
|
91 |
+
public function print_review() {
|
92 |
+
learn_press_course_review_template( 'course-review.php' );
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Add review button.
|
97 |
+
*/
|
98 |
+
public function add_review_button() {
|
99 |
+
if ( ! learn_press_get_user_rate( get_the_ID() ) ) {
|
100 |
+
learn_press_course_review_template( 'review-form.php' );
|
101 |
+
}
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Admin assets.
|
106 |
+
*/
|
107 |
+
public function admin_enqueue_assets() {
|
108 |
+
wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/admin.css' );
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Single course assets.
|
113 |
+
*/
|
114 |
+
public function review_assets() {
|
115 |
+
if ( learn_press_is_course() ) {
|
116 |
+
wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
|
117 |
+
wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
|
118 |
+
wp_enqueue_style( 'dashicons' );
|
119 |
+
wp_localize_script( 'course-review', 'learn_press_course_review',
|
120 |
+
array(
|
121 |
+
'localize' => array(
|
122 |
+
'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
|
123 |
+
'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
|
124 |
+
'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
|
125 |
+
)
|
126 |
+
)
|
127 |
+
);
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
public function course_review_init() {
|
132 |
+
$paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
|
133 |
+
learn_press_get_course_review( get_the_ID(), $paged );
|
134 |
+
}
|
135 |
+
|
136 |
+
public function exclude_rating( $query ) {
|
137 |
+
$query->query_vars['type__not_in'] = 'review';
|
138 |
+
}
|
139 |
+
|
140 |
+
public function add_review() {
|
141 |
+
$response = array( 'result' => 'success' );
|
142 |
+
$nonce = ! empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
|
143 |
+
$id = ! empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
|
144 |
+
$rate = ! empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
|
145 |
+
$title = ! empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
|
146 |
+
$content = ! empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
|
147 |
+
|
148 |
+
if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
|
149 |
+
$response['result'] = 'fail';
|
150 |
+
$response['message'] = __( 'Error', 'learnpress-course-review' );
|
151 |
+
}
|
152 |
+
|
153 |
+
if ( get_post_type( $id ) != 'lp_course' ) {
|
154 |
+
$response['result'] = 'fail';
|
155 |
+
$response['message'] = __( 'Invalid course', 'learnpress-course-review' );
|
156 |
+
}
|
157 |
+
|
158 |
+
$return = learn_press_add_course_review(
|
159 |
+
array(
|
160 |
+
'user_id' => get_current_user_id(),
|
161 |
+
'course_id' => $id,
|
162 |
+
'rate' => $rate,
|
163 |
+
'title' => $title,
|
164 |
+
'content' => $content
|
165 |
+
)
|
166 |
+
);
|
167 |
+
$response['comment'] = $return;
|
168 |
+
learn_press_send_json( $response );
|
169 |
+
}
|
170 |
+
|
171 |
+
public function init_comment_table() {
|
172 |
+
add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
|
173 |
+
add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
|
174 |
+
}
|
175 |
+
|
176 |
+
public function add_comment_type_filter( $cmt_types ) {
|
177 |
+
$cmt_types[ self::$comment_type ] = __( 'Course review', 'learnpress-course-review' );
|
178 |
+
|
179 |
+
return $cmt_types;
|
180 |
+
}
|
181 |
+
|
182 |
+
public function add_comment_content_filter( $cmt_text ) {
|
183 |
+
global $comment;
|
184 |
+
if ( ! $comment || $comment->comment_type != 'review' ) {
|
185 |
+
return $cmt_text;
|
186 |
+
}
|
187 |
+
|
188 |
+
ob_start();
|
189 |
+
$rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
|
190 |
+
echo '<div class="course-rate">';
|
191 |
+
learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
|
192 |
+
echo '</div>';
|
193 |
+
$cmt_text .= ob_get_clean();
|
194 |
+
|
195 |
+
return $cmt_text;
|
196 |
+
}
|
197 |
+
|
198 |
+
public function add_comment_post_type_filter() {
|
199 |
+
?>
|
200 |
+
<label class="screen-reader-text"
|
201 |
+
for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
|
202 |
+
<select id="filter-by-comment-post-type" name="post_type">
|
203 |
+
<?php
|
204 |
+
$comment_post_types = apply_filters( 'learn_press_admin_comment_post_type_types_dropdown', array(
|
205 |
+
'' => __( 'All post type', 'learnpress-course-review' ),
|
206 |
+
'lp_course' => __( 'Course comments', 'learnpress-course-review' ),
|
207 |
+
) );
|
208 |
+
|
209 |
+
foreach ( $comment_post_types as $type => $label ) {
|
210 |
+
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
|
211 |
+
} ?>
|
212 |
+
|
213 |
+
</select>
|
214 |
+
<?php
|
215 |
+
}
|
216 |
+
|
217 |
+
|
218 |
+
public function shortcode_review( $atts ) {
|
219 |
+
$atts = shortcode_atts( array(
|
220 |
+
'course_id' => 0,
|
221 |
+
'show_rate' => 'yes',
|
222 |
+
'show_review' => 'yes'
|
223 |
+
), $atts, 'shortcode_review' );
|
224 |
+
|
225 |
+
$course_id = $atts['course_id'];
|
226 |
+
if ( ! $course_id ) {
|
227 |
+
$course_id = get_the_ID();
|
228 |
+
}
|
229 |
+
|
230 |
+
ob_start();
|
231 |
+
if ( $atts['show_rate'] ) {
|
232 |
+
$course_rate = learn_press_get_course_rate( $course_id, false );
|
233 |
+
$total = learn_press_get_course_rate_total( $course_id, false );
|
234 |
+
$rate_args = array(
|
235 |
+
'course_id' => $course_id,
|
236 |
+
'course_rate' => $course_rate,
|
237 |
+
'total' => $total
|
238 |
+
);
|
239 |
+
learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
|
240 |
+
}
|
241 |
+
|
242 |
+
if ( $atts['show_review'] ) {
|
243 |
+
$course_review = learn_press_get_course_review( $course_id );
|
244 |
+
learn_press_course_review_template( 'shortcode-course-review.php', array(
|
245 |
+
'course_id' => $course_id,
|
246 |
+
'course_review' => $course_review
|
247 |
+
) );
|
248 |
+
}
|
249 |
+
|
250 |
+
$content = ob_get_contents();
|
251 |
+
ob_clean();
|
252 |
+
|
253 |
+
return $content;
|
254 |
+
}
|
255 |
+
|
256 |
+
public function load_widget() {
|
257 |
+
register_widget( 'LearnPress_Course_Review_Widget' );
|
258 |
+
}
|
259 |
+
|
260 |
+
|
261 |
+
public function add_course_tab_reviews( $tabs ) {
|
262 |
+
$tabs['reviews'] = array(
|
263 |
+
'title' => __( 'Reviews', 'learnpress-course-review' ),
|
264 |
+
'priority' => 60,
|
265 |
+
'callback' => array( $this, 'add_course_tab_reviews_callback' )
|
266 |
+
);
|
267 |
+
|
268 |
+
|
269 |
+
return $tabs;
|
270 |
+
}
|
271 |
+
|
272 |
+
public function add_course_tab_reviews_callback() {
|
273 |
+
$user = learn_press_get_current_user();
|
274 |
+
$course_id = learn_press_get_course_id();
|
275 |
+
$this->print_rate();
|
276 |
+
$this->print_review();
|
277 |
+
if ( $user->has_course_status( $course_id, array( 'enrolled', 'completed', 'finished' ) ) ) {
|
278 |
+
$this->add_review_button();
|
279 |
+
}
|
280 |
+
}
|
281 |
+
|
282 |
+
public function learnpress_is_active() {
|
283 |
+
if ( ! function_exists( 'is_plugin_active' ) ) {
|
284 |
+
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
285 |
+
}
|
286 |
+
|
287 |
+
return is_plugin_active( 'learnpress/learnpress.php' );
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
|
292 |
+
add_action( 'plugins_loaded', array( 'LP_Addon_Course_Review', 'instance' ) );
|
inc/widgets.php
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Course review widget class.
|
4 |
+
*
|
5 |
+
* @author ThimPress
|
6 |
+
* @package LearnPress/Course-Review/Classes
|
7 |
+
* @version 3.0.0
|
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 |
+
__( 'Course Review', 'learnpress-course-review' ),
|
20 |
+
array( 'description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ), )
|
21 |
+
);
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
public function widget( $args, $instance ) {
|
26 |
+
wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/js/course-review.js', array( 'jquery' ), '', true );
|
27 |
+
wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/css/course-review.css' );
|
28 |
+
$title = apply_filters( 'widget_title', $instance['title'] );
|
29 |
+
echo $args['before_widget'];
|
30 |
+
|
31 |
+
if ( ! empty( $title ) ) {
|
32 |
+
echo $args['before_title'] . $title . $args['after_title'];
|
33 |
+
}
|
34 |
+
|
35 |
+
$course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : 0;
|
36 |
+
$show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
|
37 |
+
$show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
|
38 |
+
|
39 |
+
if ( ! $course_id ) {
|
40 |
+
$course_id = get_the_ID();
|
41 |
+
}
|
42 |
+
|
43 |
+
ob_start();
|
44 |
+
if ( $show_rate == 'yes' ) {
|
45 |
+
$course_rate = learn_press_get_course_rate( $course_id, false );
|
46 |
+
$rate_args = array(
|
47 |
+
'course_id' => $course_id
|
48 |
+
,
|
49 |
+
'course_rate' => $course_rate
|
50 |
+
);
|
51 |
+
learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
|
52 |
+
}
|
53 |
+
|
54 |
+
if ( $show_review == 'yes' ) {
|
55 |
+
$course_review = learn_press_get_course_review( $course_id );
|
56 |
+
learn_press_course_review_template( 'shortcode-course-review.php', array(
|
57 |
+
'course_id' => $course_id,
|
58 |
+
'course_review' => $course_review
|
59 |
+
) );
|
60 |
+
}
|
61 |
+
|
62 |
+
$content = ob_get_contents();
|
63 |
+
ob_clean();
|
64 |
+
echo $content;
|
65 |
+
echo $args['after_widget'];
|
66 |
+
}
|
67 |
+
|
68 |
+
public function form( $instance ) {
|
69 |
+
$arg = array(
|
70 |
+
'post_type' => 'lp_course',
|
71 |
+
'posts_per_page' => - 1,
|
72 |
+
'post_status' => 'publish'
|
73 |
+
);
|
74 |
+
$the_query = new WP_Query( $arg );
|
75 |
+
$title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'wpb_widget_domain' );
|
76 |
+
$course_id = isset( $instance['course_id'] ) ? $instance['course_id'] : '';
|
77 |
+
$show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
|
78 |
+
$show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
|
79 |
+
$option = '';
|
80 |
+
if ( $the_query->have_posts() ) {
|
81 |
+
while ( $the_query->have_posts() ) {
|
82 |
+
$the_query->the_post();
|
83 |
+
$checked = '';
|
84 |
+
if ( $the_query->post->ID == $course_id ) {
|
85 |
+
$checked = "selected='selected'";
|
86 |
+
}
|
87 |
+
$option .= "<option value='{$the_query->post->ID}' {$checked}>{$the_query->post->post_title}</option>";
|
88 |
+
}
|
89 |
+
}
|
90 |
+
// Reset Post Data
|
91 |
+
wp_reset_postdata();
|
92 |
+
?>
|
93 |
+
<p>
|
94 |
+
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'learnpress-course-review' ); ?></label>
|
95 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
|
96 |
+
name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
|
97 |
+
value="<?php echo esc_attr( $title ); ?>"/>
|
98 |
+
</p>
|
99 |
+
<p>
|
100 |
+
<label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:', 'learnpress-course-review' ); ?></label>
|
101 |
+
<select name="<?php echo $this->get_field_name( 'course_id' ); ?>">
|
102 |
+
<?php echo $option; ?>
|
103 |
+
</select>
|
104 |
+
</p>
|
105 |
+
<p>
|
106 |
+
<label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:', 'learnpress-course-review' ); ?></label>
|
107 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>"
|
108 |
+
name="<?php echo $this->get_field_name( 'show_rate' ); ?>" type="checkbox"
|
109 |
+
value="yes" <?php checked( $show_rate, 'yes', true ); ?>/>
|
110 |
+
</p>
|
111 |
+
<p>
|
112 |
+
<label for="<?php echo $this->get_field_id( 'show_review' ); ?>"><?php _e( 'Show Review:', 'learnpress-course-review' ); ?></label>
|
113 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'show_review' ); ?>"
|
114 |
+
name="<?php echo $this->get_field_name( 'show_review' ); ?>" type="checkbox"
|
115 |
+
value="yes" <?php checked( $show_review, 'yes', true ); ?> />
|
116 |
+
</p>
|
117 |
+
<?php
|
118 |
+
}
|
119 |
+
|
120 |
+
// Updating widget replacing old instances with new
|
121 |
+
public function update( $new_instance, $old_instance ) {
|
122 |
+
$instance = $old_instance;
|
123 |
+
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
124 |
+
$instance['course_id'] = ( ! empty( $new_instance['course_id'] ) ) ? strip_tags( $new_instance['course_id'] ) : '';
|
125 |
+
$instance['show_rate'] = ( ! empty( $new_instance['show_rate'] ) ) ? strip_tags( $new_instance['show_rate'] ) : '';
|
126 |
+
$instance['show_review'] = ( ! empty( $new_instance['show_review'] ) ) ? strip_tags( $new_instance['show_review'] ) : '';
|
127 |
+
|
128 |
+
return $instance;
|
129 |
+
}
|
130 |
+
|
131 |
+
}
|
incs/review-functions.php
DELETED
@@ -1,328 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Reviews functions
|
4 |
-
*/
|
5 |
-
|
6 |
-
if ( !defined( 'ABSPATH' ) ) {
|
7 |
-
exit; // Exit if accessed directly
|
8 |
-
}
|
9 |
-
/**
|
10 |
-
* @param int $course_id
|
11 |
-
* @param int $paged
|
12 |
-
* @param int $per_page
|
13 |
-
* @param boolean $force
|
14 |
-
*
|
15 |
-
* @return mixed|void
|
16 |
-
*/
|
17 |
-
function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_ADDON_COURSE_REVIEW_PER_PAGE, $force = false ) {
|
18 |
-
static $course_reviews = array();
|
19 |
-
if ( !$force && !empty( $course_reviews[$course_id] ) ) {
|
20 |
-
return $course_reviews[$course_id];
|
21 |
-
}
|
22 |
-
global $wpdb;
|
23 |
-
$per_page = absint( apply_filters( 'learn_press_course_reviews_per_page', $per_page ) );
|
24 |
-
$paged = absint( $paged );
|
25 |
-
if ( $per_page == 0 ) {
|
26 |
-
$per_page = 9999999;
|
27 |
-
}
|
28 |
-
if ( $paged == 0 ) {
|
29 |
-
$paged = 1;
|
30 |
-
}
|
31 |
-
$start = ( $paged - 1 ) * $per_page;
|
32 |
-
$start = max( $start, 0 );
|
33 |
-
$per_page = max( $per_page, 1 );
|
34 |
-
$results = array(
|
35 |
-
'reviews' => array(),
|
36 |
-
'paged' => $paged,
|
37 |
-
'total' => 0,
|
38 |
-
'per_page' => $per_page
|
39 |
-
);
|
40 |
-
|
41 |
-
$query = $wpdb->prepare( "
|
42 |
-
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
|
43 |
-
FROM {$wpdb->posts} p
|
44 |
-
INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
|
45 |
-
INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
|
46 |
-
INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key = %s
|
47 |
-
INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key = %s
|
48 |
-
WHERE p.ID = %d AND c.comment_type = %s AND c.comment_approved = %d
|
49 |
-
ORDER BY c.comment_date DESC
|
50 |
-
LIMIT %d, %d
|
51 |
-
", '_lpr_review_title', '_lpr_rating', $course_id, 'review', 1, $start, $per_page );
|
52 |
-
$course_review = $wpdb->get_results( $query );
|
53 |
-
if ( $course_review ) {
|
54 |
-
$ratings = _learn_press_get_ratings( $course_id );
|
55 |
-
$results['reviews'] = $course_review;
|
56 |
-
$results['total'] = $ratings[$course_id]['total'];// $wpdb->get_var( "SELECT FOUND_ROWS();" );
|
57 |
-
if ( $results['total'] <= $start + $per_page ) {
|
58 |
-
$results['finish'] = true;
|
59 |
-
}
|
60 |
-
}
|
61 |
-
$course_reviews[$course_id] = $results;
|
62 |
-
return $results;
|
63 |
-
}
|
64 |
-
|
65 |
-
function _learn_press_get_ratings( $course_id ) {
|
66 |
-
global $wpdb;
|
67 |
-
static $course_rates = array();
|
68 |
-
if ( !is_array( $course_id ) ) {
|
69 |
-
$ids = array( $course_id );
|
70 |
-
} else {
|
71 |
-
$ids = $course_id;
|
72 |
-
}
|
73 |
-
foreach ( $ids as $cid ) {
|
74 |
-
if ( !isset( $course_rates[$cid] ) ) {
|
75 |
-
$course_rates[$cid] = leanr_press_get_ratings_result( $cid );
|
76 |
-
}
|
77 |
-
}
|
78 |
-
return $course_rates;
|
79 |
-
}
|
80 |
-
|
81 |
-
|
82 |
-
/**
|
83 |
-
* @param $course_id
|
84 |
-
* @param $field
|
85 |
-
*
|
86 |
-
* @return mixed|void
|
87 |
-
*/
|
88 |
-
function learn_press_get_course_rate( $course_id, $field = 'rated' ) {
|
89 |
-
$ratings = _learn_press_get_ratings( $course_id );
|
90 |
-
$rate = ($field && array_key_exists( $field, $ratings[$course_id] )) ? $ratings[$course_id][$field] : $ratings[$course_id];
|
91 |
-
return apply_filters( 'learn_press_get_course_rate', $rate );
|
92 |
-
}
|
93 |
-
|
94 |
-
function learn_press_get_course_rate_total( $course_id, $field = 'total' ) {
|
95 |
-
/*global $wpdb;
|
96 |
-
$query = $wpdb->prepare( "
|
97 |
-
SELECT COUNT(*)
|
98 |
-
FROM {$wpdb->posts} p
|
99 |
-
INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
|
100 |
-
INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
|
101 |
-
INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
|
102 |
-
INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
|
103 |
-
WHERE p.ID=%d AND c.comment_type=%s and c.comment_approved = %d
|
104 |
-
ORDER BY c.comment_date DESC",
|
105 |
-
'_lpr_review_title', '_lpr_rating', $course_id, 'review', 1
|
106 |
-
);
|
107 |
-
$total = $wpdb->get_var( $query );*/
|
108 |
-
|
109 |
-
$ratings = _learn_press_get_ratings( $course_id );
|
110 |
-
$total = array_key_exists( $field, $ratings[$course_id] ) ? $ratings[$course_id][$field] : $ratings;
|
111 |
-
return apply_filters( 'learn_press_get_course_rate_total', $total );
|
112 |
-
}
|
113 |
-
|
114 |
-
/**
|
115 |
-
* @param $course_id
|
116 |
-
* @param $user_id
|
117 |
-
*
|
118 |
-
* @return mixed|void
|
119 |
-
*/
|
120 |
-
function learn_press_get_user_review_title( $course_id, $user_id ) {
|
121 |
-
$course_review = get_post_meta( $course_id, '_lpr_course_review', true );
|
122 |
-
if ( $course_review && array_key_exists( $user_id, $course_review['review_title'] ) ) {
|
123 |
-
return apply_filters( 'learn_press_get_user_review', $course_review['review_title'][$user_id] );
|
124 |
-
}
|
125 |
-
return false;
|
126 |
-
}
|
127 |
-
|
128 |
-
/**
|
129 |
-
* @param $course_id
|
130 |
-
* @param $user_id
|
131 |
-
*
|
132 |
-
* @return mixed|void
|
133 |
-
*/
|
134 |
-
function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
|
135 |
-
if ( !$user_id ) $user_id = get_current_user_id();
|
136 |
-
if ( !$course_id ) $course_id = get_the_ID();
|
137 |
-
|
138 |
-
$comment = false;
|
139 |
-
global $wpdb;
|
140 |
-
$query = $wpdb->prepare( "
|
141 |
-
SELECT *
|
142 |
-
FROM {$wpdb->posts} p
|
143 |
-
INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
|
144 |
-
WHERE c.comment_post_ID = %d AND user_id = %d
|
145 |
-
", $course_id, $user_id );
|
146 |
-
$comments = $wpdb->get_results( $query );
|
147 |
-
if ( $comments ) {
|
148 |
-
$comment = $comments[0];
|
149 |
-
$comment->comment_title = get_comment_meta( $comment->comment_ID, '_lpr_review_title', true );
|
150 |
-
$comment->rating = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
|
151 |
-
}
|
152 |
-
return $comment;
|
153 |
-
}
|
154 |
-
|
155 |
-
/**
|
156 |
-
* @param array
|
157 |
-
*
|
158 |
-
* @return int
|
159 |
-
*/
|
160 |
-
function learn_press_add_course_review( $args = array() ) {
|
161 |
-
$args = wp_parse_args(
|
162 |
-
$args,
|
163 |
-
array(
|
164 |
-
'title' => '',
|
165 |
-
'content' => '',
|
166 |
-
'rate' => '',
|
167 |
-
'user_id' => 0,
|
168 |
-
'course_id' => 0
|
169 |
-
)
|
170 |
-
);
|
171 |
-
$user_id = $args['user_id'];
|
172 |
-
$course_id = $args['course_id'];
|
173 |
-
$user_review = learn_press_get_user_rate( $course_id, $user_id );
|
174 |
-
$comment_id = 0;
|
175 |
-
if ( !$user_review ) {
|
176 |
-
$user = get_user_by( 'id', $user_id );
|
177 |
-
$comment_id = wp_new_comment(
|
178 |
-
array(
|
179 |
-
'comment_post_ID' => $course_id,
|
180 |
-
'comment_author' => 'LearnPress',
|
181 |
-
'comment_author_email' => $user->user_email,
|
182 |
-
'comment_author_url' => '',
|
183 |
-
'comment_content' => $args['content'],
|
184 |
-
'comment_parent' => 0,
|
185 |
-
'user_id' => $user->ID,
|
186 |
-
'comment_approved' => 1,
|
187 |
-
'comment_type' => 'review' // let filter to not display it as comments
|
188 |
-
)
|
189 |
-
);
|
190 |
-
}
|
191 |
-
if ( $comment_id ) {
|
192 |
-
add_comment_meta( $comment_id, '_lpr_rating', $args['rate'] );
|
193 |
-
add_comment_meta( $comment_id, '_lpr_review_title', $args['title'] );
|
194 |
-
}
|
195 |
-
|
196 |
-
return $comment_id;
|
197 |
-
}
|
198 |
-
|
199 |
-
function learn_press_course_review_template( $name, $args = null ) {
|
200 |
-
learn_press_get_template( $name, $args, learn_press_template_path() . '/addons/course-review/', LP_ADDON_COURSE_REVIEW_TMPL );
|
201 |
-
}
|
202 |
-
|
203 |
-
/*
|
204 |
-
add_action( 'learn_press_after_courses_loop_item', function () {
|
205 |
-
global $post;
|
206 |
-
echo "[", learn_press_get_course_rate_total( $post->ID ), "]";
|
207 |
-
} );*/
|
208 |
-
|
209 |
-
/*
|
210 |
-
* If we are viewing archive course page, so load all ratings of courses
|
211 |
-
* into cache to reduce queries and time rather than load separate course
|
212 |
-
* in loop
|
213 |
-
*/
|
214 |
-
add_filter( 'the_posts', 'learn_press_init_courses_review' );
|
215 |
-
function learn_press_init_courses_review( $posts ) {
|
216 |
-
if ( $posts ) {
|
217 |
-
$pIds = array();
|
218 |
-
foreach ( $posts as $p ) {
|
219 |
-
$pIds[] = $p->ID;
|
220 |
-
}
|
221 |
-
_learn_press_get_ratings( $pIds );
|
222 |
-
}
|
223 |
-
return $posts;
|
224 |
-
}
|
225 |
-
|
226 |
-
/*
|
227 |
-
function learn_press_add_course_review( $args = array() ) {
|
228 |
-
$args = wp_parse_args(
|
229 |
-
$args,
|
230 |
-
array(
|
231 |
-
'title' => '',
|
232 |
-
'content' => '',
|
233 |
-
'rate' => '',
|
234 |
-
'user_id' => 0,
|
235 |
-
'course_id' => 0
|
236 |
-
)
|
237 |
-
);
|
238 |
-
$user_id = $args['user_id'];
|
239 |
-
$course_id = $args['course_id'];
|
240 |
-
$user_review = learn_press_get_user_rate( $course_id, $user_id );//learn_press_get_user_review_title( $course_id, $user_id );
|
241 |
-
if ( !$user_review ) {
|
242 |
-
$review_title = $_POST['review_title'];
|
243 |
-
$review_content = $_POST['review_content'];
|
244 |
-
$review_rate = $_POST['review_rate'];
|
245 |
-
learn_press_save_course_review( $course_id, $review_rate, $review_title, $review_content );
|
246 |
-
}
|
247 |
-
global $post;
|
248 |
-
$post = get_post( $course_id );
|
249 |
-
setup_postdata( $post );
|
250 |
-
learn_press_course_review_template( 'course-rate.php' );
|
251 |
-
die();
|
252 |
-
}
|
253 |
-
|
254 |
-
add_action( 'wp_ajax_learn_press_add_course_review', 'learn_press_add_course_review' );
|
255 |
-
*/
|
256 |
-
/**
|
257 |
-
* Print rate for course
|
258 |
-
*/
|
259 |
-
function leanr_press_get_ratings_result( $course_id = '', $get_items = false ) {
|
260 |
-
global $wpdb;
|
261 |
-
$query = $wpdb->prepare( "
|
262 |
-
SELECT
|
263 |
-
COUNT(*) `count` ,AVG(cm.meta_value) `avg`
|
264 |
-
FROM
|
265 |
-
{$wpdb->comments} c
|
266 |
-
INNER JOIN
|
267 |
-
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key='_lpr_rating'
|
268 |
-
WHERE
|
269 |
-
c.comment_approved = 1
|
270 |
-
AND c.comment_type = 'review'
|
271 |
-
AND c.user_id > 0
|
272 |
-
AND c.comment_post_ID =%d "
|
273 |
-
, $course_id );
|
274 |
-
$row = $wpdb->get_row( $query );
|
275 |
-
|
276 |
-
$count = 0;
|
277 |
-
$avg = 0;
|
278 |
-
if ( $row ) {
|
279 |
-
$count = $row->count;
|
280 |
-
$avg = $row->avg;
|
281 |
-
}
|
282 |
-
|
283 |
-
$rows = array();
|
284 |
-
if ( $count != 0 ):
|
285 |
-
$query = $wpdb->prepare( "
|
286 |
-
SELECT
|
287 |
-
cm.meta_value `rate`, COUNT(*) `count`
|
288 |
-
FROM
|
289 |
-
{$wpdb->comments} c
|
290 |
-
INNER JOIN
|
291 |
-
{$wpdb->commentmeta} cm ON c.comment_ID = cm.comment_id AND meta_key='_lpr_rating'
|
292 |
-
WHERE
|
293 |
-
c.comment_approved = 1
|
294 |
-
AND c.comment_type = 'review'
|
295 |
-
AND c.user_id > 0
|
296 |
-
AND c.comment_post_ID =%d
|
297 |
-
GROUP BY `cm`.`meta_value`
|
298 |
-
ORDER BY `cm`.`meta_value` DESC
|
299 |
-
"
|
300 |
-
, $course_id );
|
301 |
-
$rows = $wpdb->get_results( $query, OBJECT_K );
|
302 |
-
endif;
|
303 |
-
|
304 |
-
$items = array();
|
305 |
-
for ( $i = 5; $i > 0; $i -- ) {
|
306 |
-
if ( isset( $rows[$i] ) ) {
|
307 |
-
$items[] = array(
|
308 |
-
'rated' => $rows[$i]->rate
|
309 |
-
, 'total' => $rows[$i]->count
|
310 |
-
, 'percent' => $rows[$i]->count / $count * 100
|
311 |
-
);
|
312 |
-
} else {
|
313 |
-
$items[] = array(
|
314 |
-
'rated' => $i
|
315 |
-
, 'total' => 0
|
316 |
-
, 'percent' => 0
|
317 |
-
);
|
318 |
-
}
|
319 |
-
}
|
320 |
-
$result = array(
|
321 |
-
'course_id' => $course_id
|
322 |
-
, 'total' => $count
|
323 |
-
, 'rated' => $avg
|
324 |
-
, 'items' => $items
|
325 |
-
);
|
326 |
-
|
327 |
-
return $result;
|
328 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
incs/review-widgets.php
DELETED
@@ -1,99 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Reviews functions
|
4 |
-
*/
|
5 |
-
|
6 |
-
if ( !defined( 'ABSPATH' ) ) {
|
7 |
-
exit; // Exit if accessed directly
|
8 |
-
}
|
9 |
-
// Creating the widget
|
10 |
-
class LearnPress_Course_Review_Widget extends WP_Widget {
|
11 |
-
|
12 |
-
function __construct() {
|
13 |
-
parent::__construct(
|
14 |
-
'lpr_course_review',
|
15 |
-
__( 'Course Review', 'learnpress-course-review' ),
|
16 |
-
array('description' => __( 'Display ratings and reviews of course', 'learnpress-course-review' ),)
|
17 |
-
);
|
18 |
-
}
|
19 |
-
|
20 |
-
|
21 |
-
public function widget( $args, $instance ) {
|
22 |
-
$title = apply_filters( 'widget_title', $instance['title'] );
|
23 |
-
echo $args['before_widget'];
|
24 |
-
|
25 |
-
if ( !empty( $title ) ) {
|
26 |
-
echo $args['before_title'] . $title . $args['after_title'];
|
27 |
-
}
|
28 |
-
|
29 |
-
$course_id = isset($instance['course_id'] ) ? $instance['course_id'] : 0;
|
30 |
-
$show_rate = isset( $instance['show_rate'] ) ? $instance['show_rate'] : 'no';
|
31 |
-
$show_review = isset( $instance['show_review'] ) ? $instance['show_review'] : 'no';
|
32 |
-
|
33 |
-
if( !$course_id ) {
|
34 |
-
$course_id = get_the_ID();
|
35 |
-
}
|
36 |
-
|
37 |
-
ob_start();
|
38 |
-
if( $show_rate == 'yes' ) {
|
39 |
-
$course_rate = learn_press_get_course_rate( $course_id, false );
|
40 |
-
$rate_args = array(
|
41 |
-
'course_id' => $course_id
|
42 |
-
, 'course_rate' => $course_rate
|
43 |
-
);
|
44 |
-
learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
|
45 |
-
}
|
46 |
-
|
47 |
-
if( $show_review == 'yes' ){
|
48 |
-
$course_review = learn_press_get_course_review( $course_id );
|
49 |
-
learn_press_course_review_template( 'shortcode-course-review.php', array('course_id'=>$course_id, 'course_review'=>$course_review) );
|
50 |
-
}
|
51 |
-
|
52 |
-
$content = ob_get_contents();
|
53 |
-
ob_clean();
|
54 |
-
echo $content;
|
55 |
-
echo $args['after_widget'];
|
56 |
-
}
|
57 |
-
|
58 |
-
public function form( $instance ) {
|
59 |
-
$title = isset( $instance['title'] )?$instance['title']:__( 'New title', 'wpb_widget_domain' );
|
60 |
-
$course_id = isset($instance['course_id'])?$instance['course_id']:'';
|
61 |
-
$show_rate = isset($instance['show_rate'])?$instance['show_rate']:'no';
|
62 |
-
$show_review = isset($instance['show_review'])?$instance['show_review']:'no';
|
63 |
-
?>
|
64 |
-
<p>
|
65 |
-
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
|
66 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
|
67 |
-
</p>
|
68 |
-
<p>
|
69 |
-
<label for="<?php echo $this->get_field_id( 'course_id' ); ?>"><?php _e( 'Course Id:' ); ?></label>
|
70 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'course_id' ); ?>" name="<?php echo $this->get_field_name( 'course_id' ); ?>" type="text" value="<?php echo esc_attr( $course_id ); ?>" />
|
71 |
-
</p>
|
72 |
-
<p>
|
73 |
-
<label for="<?php echo $this->get_field_id( 'show_rate' ); ?>"><?php _e( 'Show Rate:' ); ?></label>
|
74 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'show_rate' ); ?>" name="<?php echo $this->get_field_name( 'show_rate' ); ?>" type="checkbox" value="yes" <?php checked( $show_rate, 'yes', true); ?>/>
|
75 |
-
</p>
|
76 |
-
<p>
|
77 |
-
<label for="<?php echo $this->get_field_id( 'show_review' ); ?>"><?php _e( 'Show Review:' ); ?></label>
|
78 |
-
<input class="widefat" id="<?php echo $this->get_field_id( 'show_review' ); ?>" name="<?php echo $this->get_field_name( 'show_review' ); ?>" type="checkbox" value="yes" <?php checked( $show_review, 'yes', true); ?> />
|
79 |
-
</p>
|
80 |
-
<?php
|
81 |
-
}
|
82 |
-
|
83 |
-
// Updating widget replacing old instances with new
|
84 |
-
public function update( $new_instance, $old_instance ) {
|
85 |
-
$instance = array();
|
86 |
-
var_dump($new_instance);
|
87 |
-
$instance['title'] = (!empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
88 |
-
$instance['course_id'] = (!empty( $new_instance['course_id'] ) ) ? strip_tags( $new_instance['course_id'] ) : '';
|
89 |
-
$instance['show_rate'] = (!empty( $new_instance['show_rate'] ) ) ? strip_tags( $new_instance['show_rate'] ) : '';
|
90 |
-
$instance['show_review'] = (!empty( $new_instance['show_review'] ) ) ? strip_tags( $new_instance['show_review'] ) : '';
|
91 |
-
var_dump($instance);
|
92 |
-
return $instance;
|
93 |
-
}
|
94 |
-
|
95 |
-
}
|
96 |
-
|
97 |
-
// Class wpb_widget ends here
|
98 |
-
// Register and load the widget
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/learnpress-course-review.pot
CHANGED
@@ -8,7 +8,7 @@ msgid ""
|
|
8 |
msgstr ""
|
9 |
"Project-Id-Version: PACKAGE VERSION\n"
|
10 |
"Report-Msgid-Bugs-To: \n"
|
11 |
-
"POT-Creation-Date:
|
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"
|
@@ -18,78 +18,147 @@ msgstr ""
|
|
18 |
"Content-Transfer-Encoding: 8bit\n"
|
19 |
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
20 |
|
21 |
-
#:
|
22 |
msgid "Please enter the review title"
|
23 |
msgstr ""
|
24 |
|
25 |
-
#:
|
26 |
msgid "Please enter the review content"
|
27 |
msgstr ""
|
28 |
|
29 |
-
#:
|
30 |
msgid "Please select your rating"
|
31 |
msgstr ""
|
32 |
|
33 |
-
#:
|
34 |
msgid "Error"
|
35 |
msgstr ""
|
36 |
|
37 |
-
#:
|
38 |
msgid "Invalid course"
|
39 |
msgstr ""
|
40 |
|
41 |
-
#:
|
42 |
-
|
43 |
-
|
44 |
-
msgid_plural "%d ratings"
|
45 |
-
msgstr[0] ""
|
46 |
-
msgstr[1] ""
|
47 |
|
48 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
msgid "Reviews"
|
50 |
msgstr ""
|
51 |
|
52 |
-
#:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
#, php-format
|
54 |
-
msgid "
|
55 |
msgstr ""
|
56 |
|
57 |
-
#: templates/course-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
msgid "Loading..."
|
59 |
msgstr ""
|
60 |
|
61 |
-
#: templates/course-review.php:
|
62 |
msgid "No review to load"
|
63 |
msgstr ""
|
64 |
|
65 |
-
#: templates/course-review.php:
|
66 |
msgid "Load More"
|
67 |
msgstr ""
|
68 |
|
69 |
-
#: templates/review-form.php:
|
70 |
msgid "Write a review"
|
71 |
msgstr ""
|
72 |
|
73 |
-
#: templates/review-form.php:
|
74 |
msgid "Title"
|
75 |
msgstr ""
|
76 |
|
77 |
-
#: templates/review-form.php:
|
78 |
msgid "Content"
|
79 |
msgstr ""
|
80 |
|
81 |
-
#: templates/review-form.php:
|
82 |
msgid "Rating"
|
83 |
msgstr ""
|
84 |
|
85 |
-
#: templates/review-form.php:
|
86 |
msgid "Add review"
|
87 |
msgstr ""
|
88 |
|
89 |
-
#: templates/review-form.php:
|
90 |
msgid "Cancel"
|
91 |
msgstr ""
|
92 |
|
93 |
-
#: templates/review-form.php:
|
94 |
msgid "Please wait..."
|
95 |
msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
msgstr ""
|
9 |
"Project-Id-Version: PACKAGE VERSION\n"
|
10 |
"Report-Msgid-Bugs-To: \n"
|
11 |
+
"POT-Creation-Date: 2017-12-14 15: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"
|
18 |
"Content-Transfer-Encoding: 8bit\n"
|
19 |
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
20 |
|
21 |
+
#: inc/load.php:129
|
22 |
msgid "Please enter the review title"
|
23 |
msgstr ""
|
24 |
|
25 |
+
#: inc/load.php:130
|
26 |
msgid "Please enter the review content"
|
27 |
msgstr ""
|
28 |
|
29 |
+
#: inc/load.php:131
|
30 |
msgid "Please select your rating"
|
31 |
msgstr ""
|
32 |
|
33 |
+
#: inc/load.php:157
|
34 |
msgid "Error"
|
35 |
msgstr ""
|
36 |
|
37 |
+
#: inc/load.php:162
|
38 |
msgid "Invalid course"
|
39 |
msgstr ""
|
40 |
|
41 |
+
#: inc/load.php:184
|
42 |
+
msgid "Course review"
|
43 |
+
msgstr ""
|
|
|
|
|
|
|
44 |
|
45 |
+
#: inc/load.php:208
|
46 |
+
msgid "Filter by post type"
|
47 |
+
msgstr ""
|
48 |
+
|
49 |
+
#: inc/load.php:212
|
50 |
+
msgid "All post type"
|
51 |
+
msgstr ""
|
52 |
+
|
53 |
+
#: inc/load.php:213
|
54 |
+
msgid "Course comments"
|
55 |
+
msgstr ""
|
56 |
+
|
57 |
+
#: inc/load.php:271 templates/course-review.php:11
|
58 |
+
#: templates/shortcode-course-review.php:13
|
59 |
msgid "Reviews"
|
60 |
msgstr ""
|
61 |
|
62 |
+
#: inc/widgets.php:16
|
63 |
+
msgid "Course Review"
|
64 |
+
msgstr ""
|
65 |
+
|
66 |
+
#: inc/widgets.php:17
|
67 |
+
msgid "Display ratings and reviews of course"
|
68 |
+
msgstr ""
|
69 |
+
|
70 |
+
#: inc/widgets.php:69
|
71 |
+
msgid "New title"
|
72 |
+
msgstr ""
|
73 |
+
|
74 |
+
#: inc/widgets.php:88
|
75 |
+
msgid "Title:"
|
76 |
+
msgstr ""
|
77 |
+
|
78 |
+
#: inc/widgets.php:94
|
79 |
+
msgid "Course Id:"
|
80 |
+
msgstr ""
|
81 |
+
|
82 |
+
#: inc/widgets.php:100
|
83 |
+
msgid "Show Rate:"
|
84 |
+
msgstr ""
|
85 |
+
|
86 |
+
#: inc/widgets.php:106
|
87 |
+
msgid "Show Review:"
|
88 |
+
msgstr ""
|
89 |
+
|
90 |
+
#: templates/course-rate.php:18
|
91 |
#, php-format
|
92 |
+
msgid " %1.2f average based on "
|
93 |
msgstr ""
|
94 |
|
95 |
+
#: templates/course-rate.php:19
|
96 |
+
#, php-format
|
97 |
+
msgid " %d rating"
|
98 |
+
msgid_plural "%d ratings"
|
99 |
+
msgstr[0] ""
|
100 |
+
msgstr[1] ""
|
101 |
+
|
102 |
+
#: templates/course-rate.php:29
|
103 |
+
msgid " Star"
|
104 |
+
msgstr ""
|
105 |
+
|
106 |
+
#: templates/course-review.php:19 templates/shortcode-course-review.php:22
|
107 |
msgid "Loading..."
|
108 |
msgstr ""
|
109 |
|
110 |
+
#: templates/course-review.php:22 templates/shortcode-course-review.php:25
|
111 |
msgid "No review to load"
|
112 |
msgstr ""
|
113 |
|
114 |
+
#: templates/course-review.php:25 templates/shortcode-course-review.php:28
|
115 |
msgid "Load More"
|
116 |
msgstr ""
|
117 |
|
118 |
+
#: templates/review-form.php:13 templates/review-form.php:19
|
119 |
msgid "Write a review"
|
120 |
msgstr ""
|
121 |
|
122 |
+
#: templates/review-form.php:25
|
123 |
msgid "Title"
|
124 |
msgstr ""
|
125 |
|
126 |
+
#: templates/review-form.php:29
|
127 |
msgid "Content"
|
128 |
msgstr ""
|
129 |
|
130 |
+
#: templates/review-form.php:33
|
131 |
msgid "Rating"
|
132 |
msgstr ""
|
133 |
|
134 |
+
#: templates/review-form.php:43
|
135 |
msgid "Add review"
|
136 |
msgstr ""
|
137 |
|
138 |
+
#: templates/review-form.php:44
|
139 |
msgid "Cancel"
|
140 |
msgstr ""
|
141 |
|
142 |
+
#: templates/review-form.php:45
|
143 |
msgid "Please wait..."
|
144 |
msgstr ""
|
145 |
+
|
146 |
+
#: templates/shortcode-course-rate.php:12
|
147 |
+
#, php-format
|
148 |
+
msgid "%d rating"
|
149 |
+
msgid_plural "%d ratings"
|
150 |
+
msgstr[0] ""
|
151 |
+
msgstr[1] ""
|
152 |
+
|
153 |
+
#: templates/shortcode-course-rate.php:25
|
154 |
+
msgid "Star"
|
155 |
+
msgstr ""
|
156 |
+
|
157 |
+
#: templates/shortcode-course-rate.php:26
|
158 |
+
msgid "Rate"
|
159 |
+
msgstr ""
|
160 |
+
|
161 |
+
#: templates/shortcode-course-review.php:14
|
162 |
+
#, php-format
|
163 |
+
msgid "Average rate: <span>%.1f</span>"
|
164 |
+
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
@@ -2,292 +2,71 @@
|
|
2 |
/*
|
3 |
Plugin Name: LearnPress - Course Review
|
4 |
Plugin URI: http://thimpress.com/learnpress
|
5 |
-
Description: Adding review for course
|
6 |
Author: ThimPress
|
7 |
-
Version:
|
8 |
Author URI: http://thimpress.com
|
9 |
Tags: learnpress
|
|
|
|
|
10 |
Text Domain: learnpress-course-review
|
11 |
Domain Path: /languages/
|
12 |
*/
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
|
17 |
define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
|
18 |
-
define( '
|
19 |
-
define( '
|
20 |
-
define( 'LP_ADDON_COURSE_REVIEW_VER', '2.0' );
|
21 |
-
define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '2.0' );
|
22 |
|
23 |
/**
|
24 |
-
* Class
|
25 |
*/
|
26 |
-
class
|
27 |
-
/**
|
28 |
-
* @var null
|
29 |
-
*/
|
30 |
-
protected static $_instance = null;
|
31 |
-
|
32 |
-
/**
|
33 |
-
* @var null
|
34 |
-
*/
|
35 |
-
|
36 |
-
private static $comment_type = 'review';
|
37 |
|
38 |
/**
|
39 |
-
*
|
40 |
*/
|
41 |
-
function __construct() {
|
42 |
-
|
43 |
-
|
44 |
-
}
|
45 |
-
if ( self::$_instance || defined( 'LP_ADDON_COURSE_REVIEW_TMPL' ) ) {
|
46 |
-
return;
|
47 |
-
}
|
48 |
-
|
49 |
-
define( 'LP_ADDON_COURSE_REVIEW_TMPL', LP_ADDON_COURSE_REVIEW_PATH . '/templates/' );
|
50 |
-
define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
|
51 |
-
define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
|
52 |
-
|
53 |
-
add_filter( 'learn_press_course_tabs', array( $this, 'add_course_tab_reviews' ), 5 );
|
54 |
-
|
55 |
-
// add_action( 'learn_press_content_landing_summary', array( $this, 'print_rate' ), 75, 1 );
|
56 |
-
// add_action( 'learn_press_content_learning_summary', array( $this, 'print_rate' ), 75, 1 );
|
57 |
-
// add_action( 'learn_press_content_landing_summary', array( $this, 'print_review' ), 80 );
|
58 |
-
// add_action( 'learn_press_content_learning_summary', array( $this, 'print_review' ), 80 );
|
59 |
-
// add_action( 'learn_press_content_learning_summary', array( $this, 'add_review_button' ), 5 );
|
60 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
|
61 |
-
add_action( 'wp', array( $this, 'course_review_init' ) );
|
62 |
-
//add_action( 'parse_comment_query', array( $this, 'exclude_rating' ) );
|
63 |
-
|
64 |
-
add_action( 'init', array( $this, 'load_text_domain' ) );
|
65 |
-
|
66 |
-
//add_action('restrict_manage_comments', array($this, 'add_comment_post_type_filter'));
|
67 |
-
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_assets' ) );
|
68 |
-
|
69 |
-
require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-functions.php';
|
70 |
-
require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-widgets.php';
|
71 |
-
|
72 |
-
LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
|
73 |
-
|
74 |
-
$this->init_comment_table();
|
75 |
-
|
76 |
-
add_shortcode( 'learnpress-course-review', array( $this, 'shortcode_review' ) );
|
77 |
-
add_action( 'widgets_init', array( $this, 'load_widget' ) );
|
78 |
-
self::$_instance = $this;
|
79 |
-
}
|
80 |
-
|
81 |
-
function print_rate() {
|
82 |
-
learn_press_course_review_template( 'course-rate.php' );
|
83 |
-
}
|
84 |
-
|
85 |
-
function print_review() {
|
86 |
-
learn_press_course_review_template( 'course-review.php' );
|
87 |
-
}
|
88 |
-
|
89 |
-
function add_review_button() {
|
90 |
-
if ( !learn_press_get_user_rate( get_the_ID() ) ) {
|
91 |
-
learn_press_course_review_template( 'review-form.php' );
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
function admin_enqueue_assets() {
|
96 |
-
wp_enqueue_style( 'ourse-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/admin.css' );
|
97 |
-
}
|
98 |
-
|
99 |
-
function review_assets() {
|
100 |
-
if ( learn_press_is_course() ) {
|
101 |
-
wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.js', array( 'jquery' ), '', true );
|
102 |
-
wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.css' );
|
103 |
-
wp_enqueue_style( 'dashicons' );
|
104 |
-
wp_localize_script( 'course-review', 'learn_press_course_review',
|
105 |
-
array(
|
106 |
-
'localize' => array(
|
107 |
-
'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
|
108 |
-
'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
|
109 |
-
'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
|
110 |
-
)
|
111 |
-
)
|
112 |
-
);
|
113 |
-
}
|
114 |
-
}
|
115 |
-
|
116 |
-
function course_review_init() {
|
117 |
-
|
118 |
-
$paged = !empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
|
119 |
-
learn_press_get_course_review( get_the_ID(), $paged );
|
120 |
-
}
|
121 |
-
|
122 |
-
function exclude_rating( $query ) {
|
123 |
-
$query->query_vars['type__not_in'] = 'review';
|
124 |
-
}
|
125 |
-
|
126 |
-
function add_review() {
|
127 |
-
$response = array( 'result' => 'success' );
|
128 |
-
$nonce = !empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
|
129 |
-
$id = !empty( $_REQUEST['comment_post_ID'] ) ? absint( $_REQUEST['comment_post_ID'] ) : 0;
|
130 |
-
$rate = !empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
|
131 |
-
$title = !empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
|
132 |
-
$content = !empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
|
133 |
-
|
134 |
-
if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
|
135 |
-
$response['result'] = 'fail';
|
136 |
-
$response['message'] = __( 'Error', 'learnpress-course-review' );
|
137 |
-
}
|
138 |
-
|
139 |
-
if ( get_post_type( $id ) != 'lp_course' ) {
|
140 |
-
$response['result'] = 'fail';
|
141 |
-
$response['message'] = __( 'Invalid course', 'learnpress-course-review' );
|
142 |
-
}
|
143 |
-
|
144 |
-
$return = learn_press_add_course_review(
|
145 |
-
array(
|
146 |
-
'user_id' => get_current_user_id(),
|
147 |
-
'course_id' => $id,
|
148 |
-
'rate' => $rate,
|
149 |
-
'title' => $title,
|
150 |
-
'content' => $content
|
151 |
-
)
|
152 |
-
);
|
153 |
-
$response['comment'] = $return;
|
154 |
-
learn_press_send_json( $response );
|
155 |
-
}
|
156 |
-
|
157 |
-
function init_comment_table() {
|
158 |
-
add_filter( 'admin_comment_types_dropdown', array( $this, 'add_comment_type_filter' ) );
|
159 |
-
add_filter( 'comment_text', array( $this, 'add_comment_content_filter' ) );
|
160 |
-
}
|
161 |
-
|
162 |
-
function add_comment_type_filter( $cmt_types ) {
|
163 |
-
$cmt_types[self::$comment_type] = __( 'Course review', 'earnpress-course-review' );
|
164 |
-
return $cmt_types;
|
165 |
-
}
|
166 |
-
|
167 |
-
function add_comment_content_filter( $cmt_text ) {
|
168 |
-
global $comment;
|
169 |
-
if ( !$comment || $comment->comment_type != 'review' ) return $cmt_text;
|
170 |
-
|
171 |
-
ob_start();
|
172 |
-
$rated = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
|
173 |
-
echo '<div class="course-rate">';
|
174 |
-
learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $rated ) );
|
175 |
-
echo '</div>';
|
176 |
-
$cmt_text .= ob_get_clean();
|
177 |
-
return $cmt_text;
|
178 |
-
}
|
179 |
-
|
180 |
-
function add_comment_post_type_filter() {
|
181 |
-
?>
|
182 |
-
<label class="screen-reader-text" for="filter-by-comment-post-type"><?php _e( 'Filter by post type' ); ?></label>
|
183 |
-
<select id="filter-by-comment-post-type" name="post_type">
|
184 |
-
<?php
|
185 |
-
$comment_post_types = apply_filters( 'learn_press_admin_comment_post_type_types_dropdown', array(
|
186 |
-
'' => __( 'All post type' ),
|
187 |
-
'lp_course' => __( 'Course comments' ),
|
188 |
-
) );
|
189 |
-
|
190 |
-
foreach ( $comment_post_types as $type => $label ) {
|
191 |
-
echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_post_types, $type, false ) . ">$label</option>\n";
|
192 |
-
}
|
193 |
-
|
194 |
-
?>
|
195 |
-
|
196 |
-
</select>
|
197 |
-
<?php
|
198 |
-
}
|
199 |
-
|
200 |
-
|
201 |
-
function shortcode_review( $atts ) {
|
202 |
-
|
203 |
-
$atts = shortcode_atts( array(
|
204 |
-
'course_id' => 0,
|
205 |
-
'show_rate' => 'yes',
|
206 |
-
'show_review' => 'yes'
|
207 |
-
), $atts, 'shortcode_review' );
|
208 |
-
|
209 |
-
$course_id = $atts['course_id'];
|
210 |
-
if ( !$course_id ) {
|
211 |
-
$course_id = get_the_ID();
|
212 |
-
}
|
213 |
-
|
214 |
-
ob_start();
|
215 |
-
if ( $atts['show_rate'] ) {
|
216 |
-
$course_rate = learn_press_get_course_rate( $course_id, false );
|
217 |
-
$total = learn_press_get_course_rate_total( $course_id, false );
|
218 |
-
$rate_args = array(
|
219 |
-
'course_id' => $course_id
|
220 |
-
, 'course_rate' => $course_rate
|
221 |
-
, 'total' => $total
|
222 |
-
);
|
223 |
-
learn_press_course_review_template( 'shortcode-course-rate.php', $rate_args );
|
224 |
-
}
|
225 |
-
|
226 |
-
if ( $atts['show_review'] ) {
|
227 |
-
$course_review = learn_press_get_course_review( $course_id );
|
228 |
-
learn_press_course_review_template( 'shortcode-course-review.php', array( 'course_id' => $course_id, 'course_review' => $course_review ) );
|
229 |
-
}
|
230 |
-
|
231 |
-
$content = ob_get_contents();
|
232 |
-
ob_clean();
|
233 |
-
return $content;
|
234 |
-
}
|
235 |
-
|
236 |
-
function load_widget() {
|
237 |
-
register_widget( 'LearnPress_Course_Review_Widget' );
|
238 |
-
}
|
239 |
-
|
240 |
-
|
241 |
-
public function add_course_tab_reviews( $tabs ) {
|
242 |
-
$tabs['reviews'] = array(
|
243 |
-
'title' => __( 'Reviews', 'learnpres-course-review' )
|
244 |
-
, 'priority' => 0
|
245 |
-
, 'callback' => array( $this, 'add_course_tab_reviews_callback' )
|
246 |
-
);
|
247 |
-
|
248 |
-
return $tabs;
|
249 |
-
}
|
250 |
-
|
251 |
-
public function add_course_tab_reviews_callback() {
|
252 |
-
$course_id = learn_press_get_course_id();
|
253 |
-
$this->print_rate();
|
254 |
-
$this->print_review();
|
255 |
-
$this->add_review_button();
|
256 |
-
}
|
257 |
-
|
258 |
-
public static function admin_notice() {
|
259 |
-
?>
|
260 |
-
<div class="error">
|
261 |
-
<p><?php printf( __( '<strong>Course Review</strong> addon version %s requires LearnPress version %s or higher', 'learnpress-course-review' ), LP_ADDON_COURSE_REVIEW_VER, LP_ADDON_COURSE_REVIEW_REQUIRE_VER ); ?></p>
|
262 |
-
</div>
|
263 |
-
<?php
|
264 |
}
|
265 |
|
266 |
/**
|
267 |
-
*
|
268 |
*/
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
return false;
|
273 |
-
}
|
274 |
-
|
275 |
-
if ( !self::$_instance ) {
|
276 |
-
self::$_instance = new self();
|
277 |
-
|
278 |
-
}
|
279 |
-
return self::$_instance;
|
280 |
}
|
281 |
|
282 |
/**
|
283 |
-
*
|
284 |
*/
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
}
|
290 |
-
|
291 |
}
|
292 |
|
293 |
-
|
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.0
|
8 |
Author URI: http://thimpress.com
|
9 |
Tags: learnpress
|
10 |
+
Requires at least: 3.8
|
11 |
+
Tested up to: 4.9.1
|
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.0' );
|
21 |
+
define( 'LP_ADDON_COURSE_REVIEW_REQUIRE_VER', '3.0.0' );
|
|
|
|
|
22 |
|
23 |
/**
|
24 |
+
* Class LP_Addon_Course_Review_Preload
|
25 |
*/
|
26 |
+
class LP_Addon_Course_Review_Preload {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
/**
|
29 |
+
* LP_Addon_Course_Review_Preload constructor.
|
30 |
*/
|
31 |
+
public function __construct() {
|
32 |
+
add_action( 'learn-press/ready', array( $this, 'load' ) );
|
33 |
+
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
+
* Load addon
|
38 |
*/
|
39 |
+
public function load() {
|
40 |
+
LP_Addon::load( 'LP_Addon_Course_Review', 'inc/load.php', __FILE__ );
|
41 |
+
remove_action( 'admin_notices', array( $this, 'admin_notices' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
/**
|
45 |
+
* Admin notice
|
46 |
*/
|
47 |
+
public function admin_notices() {
|
48 |
+
?>
|
49 |
+
<div class="error">
|
50 |
+
<p><?php echo wp_kses(
|
51 |
+
sprintf(
|
52 |
+
__( '<strong>%s</strong> addon version %s requires %s version %s or higher is <strong>installed</strong> and <strong>activated</strong>.', 'learnpress-course-review' ),
|
53 |
+
__( 'LearnPress Course Review', 'learnpress-course-review' ),
|
54 |
+
LP_ADDON_COURSE_REVIEW_VER,
|
55 |
+
sprintf( '<a href="%s" target="_blank"><strong>%s</strong></a>', admin_url( 'plugin-install.php?tab=search&type=term&s=learnpress' ), __( 'LearnPress', 'learnpress-course-review' ) ),
|
56 |
+
LP_ADDON_COURSE_REVIEW_REQUIRE_VER
|
57 |
+
),
|
58 |
+
array(
|
59 |
+
'a' => array(
|
60 |
+
'href' => array(),
|
61 |
+
'blank' => array()
|
62 |
+
),
|
63 |
+
'strong' => array()
|
64 |
+
)
|
65 |
+
); ?>
|
66 |
+
</p>
|
67 |
+
</div>
|
68 |
+
<?php
|
69 |
}
|
|
|
70 |
}
|
71 |
|
72 |
+
new LP_Addon_Course_Review_Preload();
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
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: 4.
|
7 |
-
Stable tag:
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -33,10 +33,7 @@ Review add-on for LearnPress is using on some WordPress Themes: [Education WordP
|
|
33 |
- <a href="http://thimpress.com/shop/co-instructors-add-on-for-learnpress/" target="_blank">Co-instructors add-on for LearnPress</a> - multiple instructors support for each LMS course.
|
34 |
- <a href="http://thimpress.com/shop/collections-add-on-for-learnpress/" target="_blank">Collections add-on for LearnPress</a> - making LMS courses collection by selecting number of courses, this is helpful if you want to combine multiple LMS courses into a collection for a group of skills.
|
35 |
- <a href="http://thimpress.com/shop/stripe-add-on-for-learnpress/" target="_blank">Stripe Payment method for LearnPress</a> - Stripe payment method for LearnPress WordPress LMS Plugin.
|
36 |
-
- <a href="http://thimpress.com/shop/woocommerce-add-on-for-learnpress/" target="_blank">WooCommerce add-on for LearnPress</a> - using WooCommerce as payment gateway for LearnPrss WordPress LMS Plugin.
|
37 |
-
|
38 |
-
**Credit**
|
39 |
-
halink0803
|
40 |
|
41 |
== Installation ==
|
42 |
|
@@ -59,7 +56,18 @@ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPr
|
|
59 |
|
60 |
== Changelog ==
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
= 2.1 =
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
= 2.0 =
|
65 |
+ Updated to be compatible with LearnPress 2.0
|
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: 4.9.4
|
7 |
+
Stable tag: 3.0.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
33 |
- <a href="http://thimpress.com/shop/co-instructors-add-on-for-learnpress/" target="_blank">Co-instructors add-on for LearnPress</a> - multiple instructors support for each LMS course.
|
34 |
- <a href="http://thimpress.com/shop/collections-add-on-for-learnpress/" target="_blank">Collections add-on for LearnPress</a> - making LMS courses collection by selecting number of courses, this is helpful if you want to combine multiple LMS courses into a collection for a group of skills.
|
35 |
- <a href="http://thimpress.com/shop/stripe-add-on-for-learnpress/" target="_blank">Stripe Payment method for LearnPress</a> - Stripe payment method for LearnPress WordPress LMS Plugin.
|
36 |
+
- <a href="http://thimpress.com/shop/woocommerce-add-on-for-learnpress/" target="_blank">WooCommerce add-on for LearnPress</a> - using WooCommerce as payment gateway for LearnPrss WordPress LMS Plugin.
|
|
|
|
|
|
|
37 |
|
38 |
== Installation ==
|
39 |
|
56 |
|
57 |
== Changelog ==
|
58 |
|
59 |
+
= 3.0.0 =
|
60 |
+
+ Compatible with Learnpress 3.0.0
|
61 |
+
|
62 |
+
= 2.1.1 =
|
63 |
+
~ Add notices upgrading addon for LP 3.0
|
64 |
+
|
65 |
= 2.1 =
|
66 |
+
~ Allow all user and guest user can view reviewed
|
67 |
+
~ Only allow enrolled user can write new review
|
68 |
+
|
69 |
+
= 2.0.1 =
|
70 |
+
+ Changed text domain to learnpress
|
71 |
|
72 |
= 2.0 =
|
73 |
+ Updated to be compatible with LearnPress 2.0
|
templates/course-rate.php
CHANGED
@@ -1,43 +1,48 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
$course_id = get_the_ID();
|
7 |
$course_rate_res = learn_press_get_course_rate( $course_id, false );
|
8 |
$course_rate = $course_rate_res['rated'];
|
9 |
$total = $course_rate_res['total'];
|
10 |
-
|
11 |
?>
|
|
|
12 |
<div class="course-rate">
|
13 |
<?php
|
14 |
learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
|
15 |
?>
|
16 |
-
|
17 |
<?php do_action( 'learn_press_before_total_review_number' ); ?>
|
18 |
-
<?php printf( __( ' %1.2f average
|
19 |
<?php printf( _n( ' %d rating', '%d ratings', $total, 'learnpress-course-review' ), $total ); ?>
|
20 |
<?php do_action( 'learn_press_after_total_review_number' ); ?>
|
21 |
-
|
22 |
-
|
23 |
<?php
|
24 |
-
if ( isset( $course_rate_res['items'] ) && !empty( $course_rate_res['items'] ) ):
|
25 |
foreach ( $course_rate_res['items'] as $item ):
|
26 |
-
$percent = round( $item['percent'], 0 );
|
27 |
?>
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
<span><?php echo esc_html( $percent ); ?>%</span>
|
37 |
-
</div>
|
38 |
-
<?php
|
39 |
endforeach;
|
40 |
endif;
|
41 |
?>
|
42 |
-
|
43 |
</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.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
// Prevent loading this file directly
|
13 |
+
defined( 'ABSPATH' ) || exit;
|
14 |
|
15 |
$course_id = get_the_ID();
|
16 |
$course_rate_res = learn_press_get_course_rate( $course_id, false );
|
17 |
$course_rate = $course_rate_res['rated'];
|
18 |
$total = $course_rate_res['total'];
|
|
|
19 |
?>
|
20 |
+
|
21 |
<div class="course-rate">
|
22 |
<?php
|
23 |
learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
|
24 |
?>
|
25 |
+
<p class="review-number">
|
26 |
<?php do_action( 'learn_press_before_total_review_number' ); ?>
|
27 |
+
<?php printf( __( ' %1.2f average based on ', 'learnpress-course-review' ), $course_rate ); ?>
|
28 |
<?php printf( _n( ' %d rating', '%d ratings', $total, 'learnpress-course-review' ), $total ); ?>
|
29 |
<?php do_action( 'learn_press_after_total_review_number' ); ?>
|
30 |
+
</p>
|
31 |
+
<div>
|
32 |
<?php
|
33 |
+
if ( isset( $course_rate_res['items'] ) && ! empty( $course_rate_res['items'] ) ):
|
34 |
foreach ( $course_rate_res['items'] as $item ):
|
|
|
35 |
?>
|
36 |
+
<div class="course-rate">
|
37 |
+
<span><?php esc_html_e( $item['rated'] ); ?><?php _e( ' Star', 'learnpress-course-review' ); ?></span>
|
38 |
+
<div class="review-bar">
|
39 |
+
<div class="rating" style="width:<?php echo $item['percent']; ?>% "></div>
|
40 |
+
</div>
|
41 |
+
<span><?php echo esc_html( $item['percent'] ); ?>%</span>
|
42 |
+
</div>
|
43 |
+
<?php
|
|
|
|
|
|
|
44 |
endforeach;
|
45 |
endif;
|
46 |
?>
|
47 |
+
</div>
|
48 |
</div>
|
templates/course-review.php
CHANGED
@@ -1,29 +1,37 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
$course_id = get_the_ID();
|
6 |
$course_review = learn_press_get_course_review( $course_id );
|
7 |
if ( $course_review['total'] ) {
|
8 |
-
$reviews = $course_review['reviews'];
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
<ul class="course-reviews-list">
|
13 |
<?php foreach ( $reviews as $review ) { ?>
|
14 |
-
<?php
|
15 |
-
learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) );
|
16 |
-
?>
|
17 |
<?php } ?>
|
|
|
18 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
19 |
-
|
20 |
-
<?php }
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
25 |
-
|
|
|
26 |
<?php } ?>
|
27 |
-
|
28 |
-
|
29 |
-
}
|
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.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
// Prevent loading this file directly
|
13 |
+
defined( 'ABSPATH' ) || exit;
|
14 |
+
|
15 |
$course_id = get_the_ID();
|
16 |
$course_review = learn_press_get_course_review( $course_id );
|
17 |
if ( $course_review['total'] ) {
|
18 |
+
$reviews = $course_review['reviews']; ?>
|
19 |
+
<div id="course-reviews">
|
20 |
+
<h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
|
21 |
+
<ul class="course-reviews-list">
|
|
|
22 |
<?php foreach ( $reviews as $review ) { ?>
|
23 |
+
<?php learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) ); ?>
|
|
|
|
|
24 |
<?php } ?>
|
25 |
+
|
26 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
27 |
+
<li class="loading"><?php _e( 'Loading...', 'learnpress-course-review' ); ?></li>
|
28 |
+
<?php } ?>
|
29 |
+
|
30 |
+
<?php //_e( 'No review to load', 'learnpress-course-review' ); ?>
|
31 |
+
</ul>
|
32 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
33 |
+
<button class="button" id="course-review-load-more"
|
34 |
+
data-paged="<?php echo $course_review['paged']; ?>"><?php _e( 'Load More', 'learnpress-course-review' ); ?></button>
|
35 |
<?php } ?>
|
36 |
+
</div>
|
37 |
+
<?php }
|
|
templates/loop-review.php
CHANGED
@@ -1,23 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<li>
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
</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.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
// Prevent loading this file directly
|
13 |
+
defined( 'ABSPATH' ) || exit;
|
14 |
+
?>
|
15 |
+
|
16 |
<li>
|
17 |
+
<div class="review-author">
|
18 |
+
<?php echo get_avatar( $review->user_email ) ?>
|
19 |
+
</div>
|
20 |
+
<div class="review-author-info">
|
21 |
+
<h4 class="user-name">
|
22 |
+
<?php do_action( 'learn_press_before_review_username' ); ?>
|
23 |
+
<?php echo $review->user_login; ?>
|
24 |
+
<?php do_action( 'learn_press_after_review_username' ); ?>
|
25 |
+
</h4>
|
26 |
+
<?php learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $review->rate ) ); ?>
|
27 |
+
<p class="review-title">
|
28 |
+
<?php do_action( 'learn_press_before_review_title' ); ?>
|
29 |
+
<?php echo $review->title ?>
|
30 |
+
<?php do_action( 'learn_press_after_review_title' ); ?>
|
31 |
+
</p>
|
32 |
+
</div>
|
33 |
+
<div class="review-text">
|
34 |
+
<div class="review-content">
|
35 |
+
<?php do_action( 'learn_press_before_review_content' ); ?>
|
36 |
+
<?php echo $review->content ?>
|
37 |
+
<?php do_action( 'learn_press_after_review_content' ); ?>
|
38 |
+
</div>
|
39 |
+
</div>
|
40 |
</li>
|
templates/rating-stars.php
CHANGED
@@ -1,5 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
</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.0
|
10 |
+
*/
|
11 |
|
12 |
+
// Prevent loading this file directly
|
13 |
+
defined( 'ABSPATH' ) || exit;
|
14 |
+
//echo'<pre>alo ';print_r(sprintf(__( '%s out of 5 stars', 'learnpress-course-review'), $rated));die;
|
15 |
+
|
16 |
+
$percent = ( ! $rated ) ? 0 : min( 100, ( round( $rated * 2 ) / 2 ) * 20 );
|
17 |
+
$title = sprintf( __( '%s out of 5 stars', 'learnpress-course-review' ), $rated );
|
18 |
+
?>
|
19 |
+
<div class="review-stars-rated" title="<?php echo esc_attr( $title ); ?>">
|
20 |
+
<div class="review-stars empty"></div>
|
21 |
+
<div class="review-stars filled" style="width:<?php echo $percent; ?>%;"></div>
|
22 |
</div>
|
templates/review-form.php
CHANGED
@@ -1,55 +1,60 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Template for displaying
|
4 |
*
|
5 |
-
*
|
6 |
-
*
|
7 |
-
* @
|
|
|
|
|
8 |
*/
|
9 |
|
10 |
-
|
11 |
-
|
12 |
?>
|
|
|
13 |
<button class="write-a-review"><?php _e( 'Write a review', 'learnpress-course-review' ); ?></button>
|
14 |
<div class="course-review-wrapper" id="course-review">
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
<?php _e( 'Write a review', 'learnpress-course-review' ); ?>
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
<?php do_action( 'learn_press_before_review_fields' ); ?>
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
<?php for ( $i = 1; $i <= 5; $i ++ ) { ?>
|
36 |
-
|
37 |
-
|
38 |
<?php } ?>
|
39 |
-
|
40 |
-
|
41 |
<?php do_action( 'learn_press_after_review_fields' ); ?>
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
47 |
<?php wp_nonce_field( 'learn_press_course_review_' . get_the_ID(), 'review-nonce' ); ?>
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
</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.0
|
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,34 +1,45 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
$course_rate_res = $args['course_rate'];
|
6 |
-
$course_rate
|
7 |
-
$total
|
8 |
?>
|
|
|
9 |
<div class="course-rate">
|
10 |
-
<?php
|
11 |
-
|
12 |
-
|
13 |
-
?>
|
14 |
<p class="review-number">
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
</p>
|
19 |
-
|
20 |
<?php
|
21 |
-
if( isset($course_rate_res['items']) && !empty($course_rate_res['items']) ):
|
22 |
-
foreach ($course_rate_res['items'] as $item ):
|
23 |
?>
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
<?php
|
30 |
endforeach;
|
31 |
endif;
|
32 |
?>
|
33 |
-
|
34 |
</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.0
|
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,7 +1,16 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
$course_id = $args['course_id'];
|
7 |
$course_review = learn_press_get_course_review( $course_id );
|
@@ -9,24 +18,24 @@ if ( $course_review['total'] ) {
|
|
9 |
$course_rate = learn_press_get_course_rate( $course_id, false );
|
10 |
$reviews = $course_review['reviews'];
|
11 |
?>
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
<?php foreach ( $reviews as $review ) { ?>
|
17 |
-
<?php
|
18 |
-
learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) );
|
19 |
-
?>
|
20 |
<?php } ?>
|
|
|
21 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
22 |
-
|
23 |
-
<?php }
|
24 |
-
|
25 |
-
<!-- <li><?php _e( 'No review to load', 'learnpress-course-review' ); ?></li> -->
|
26 |
-
</ul>
|
27 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
28 |
-
|
|
|
29 |
<?php } ?>
|
30 |
-
|
31 |
<?php
|
|
|
|
|
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.0
|
10 |
+
*/
|
11 |
+
|
12 |
+
// Prevent loading this file directly
|
13 |
+
defined( 'ABSPATH' ) || exit;
|
14 |
|
15 |
$course_id = $args['course_id'];
|
16 |
$course_review = learn_press_get_course_review( $course_id );
|
18 |
$course_rate = learn_press_get_course_rate( $course_id, false );
|
19 |
$reviews = $course_review['reviews'];
|
20 |
?>
|
21 |
+
<div id="course-reviews">
|
22 |
+
<h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
|
23 |
+
<p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress-course-review' ), $course_rate ); ?></p>
|
24 |
+
<ul class="course-reviews-list">
|
25 |
<?php foreach ( $reviews as $review ) { ?>
|
26 |
+
<?php learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) ); ?>
|
|
|
|
|
27 |
<?php } ?>
|
28 |
+
|
29 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
30 |
+
<li class="loading"><?php _e( 'Loading...', 'learnpress-course-review' ); ?></li>
|
31 |
+
<?php } ?>
|
32 |
+
</ul>
|
|
|
|
|
33 |
<?php if ( empty( $course_review['finish'] ) ) { ?>
|
34 |
+
<button class="button" 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
|
39 |
+
}else{
|
40 |
+
_e( 'No review to load', 'learnpress-course-review' );
|
41 |
}
|