kk Star Ratings - Version 3.1.0

Version Description

Added - Bottom margin added when bottom position in effect. - Ability to reset ratings for individual posts/pages. - Enable/disable star ratings for individual posts/pages. - Take manual control of the auto embedded markup to avoid duplication when using in a template.

Fixed - Markup is now hidden under AMP. - Assets are now enqueued when manually/forcefully loading the markup via template function.

Changed - Default colors have been updated. - Default size is now 22px instead of 24px. - Structured data now uses ratingCount instead of reviewCount.

Removed - Nothing

Deprecated - Nothing

Security - Nothing

Download this release

Release Info

Developer bhittani
Plugin Icon 128x128 kk Star Ratings
Version 3.1.0
Comparing to
See all releases

Code changes from version 3.0.5 to 3.1.0

index.php CHANGED
@@ -8,7 +8,7 @@
8
  * Author URI: http://bhittani.com
9
  * Text Domain: kk-star-ratings
10
  * Domain Path: /languages
11
- * Version: 3.0.5
12
  * License: GPLv2 or later
13
  *
14
  * @package Bhittani\StarRating
@@ -21,7 +21,7 @@ if (! defined('ABSPATH')) {
21
 
22
  define('KKSR_FILE', __FILE__);
23
  define('KKSR_PLUGIN', plugin_basename(KKSR_FILE));
24
- define('KKSR_VERSION', '3.0.5');
25
  define('KKSR_PREFIX', 'kksr_');
26
  define('KKSR_SLUG', 'kk-star-ratings');
27
  define('KKSR_LABEL', 'kk Star Ratings');
@@ -40,6 +40,7 @@ require_once KKSR_PATH_SRC . 'activate.php';
40
  require_once KKSR_PATH_SRC . 'enqueue.php';
41
  require_once KKSR_PATH_SRC . 'markup.php';
42
  require_once KKSR_PATH_SRC . 'admin.php';
 
43
  require_once KKSR_PATH_SRC . 'ajax.php';
44
  require_once KKSR_PATH_SRC . 'structure.php';
45
  require_once KKSR_PATH_SRC . 'shortcode.php';
8
  * Author URI: http://bhittani.com
9
  * Text Domain: kk-star-ratings
10
  * Domain Path: /languages
11
+ * Version: 3.1.0
12
  * License: GPLv2 or later
13
  *
14
  * @package Bhittani\StarRating
21
 
22
  define('KKSR_FILE', __FILE__);
23
  define('KKSR_PLUGIN', plugin_basename(KKSR_FILE));
24
+ define('KKSR_VERSION', '3.1.0');
25
  define('KKSR_PREFIX', 'kksr_');
26
  define('KKSR_SLUG', 'kk-star-ratings');
27
  define('KKSR_LABEL', 'kk Star Ratings');
40
  require_once KKSR_PATH_SRC . 'enqueue.php';
41
  require_once KKSR_PATH_SRC . 'markup.php';
42
  require_once KKSR_PATH_SRC . 'admin.php';
43
+ require_once KKSR_PATH_SRC . 'metabox.php';
44
  require_once KKSR_PATH_SRC . 'ajax.php';
45
  require_once KKSR_PATH_SRC . 'structure.php';
46
  require_once KKSR_PATH_SRC . 'shortcode.php';
languages/kk-star-ratings.pot CHANGED
@@ -4,7 +4,7 @@ msgid ""
4
  msgstr ""
5
  "Project-Id-Version: \n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/kk-star-ratings\n"
7
- "POT-Creation-Date: 2019-07-18 12:05:06+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -88,103 +88,114 @@ msgstr ""
88
  msgid "Stroke color of hover stars."
89
  msgstr ""
90
 
91
- #: src/admin/general.php:54 src/admin/rich-snippets.php:18
 
 
 
 
 
 
 
 
 
92
  msgid "Status"
93
  msgstr ""
94
 
95
- #: src/admin/general.php:55 src/admin/rich-snippets.php:19
96
  msgid "Active"
97
  msgstr ""
98
 
99
- #: src/admin/general.php:59
100
  msgid "Globally activate/deactivate the star ratings."
101
  msgstr ""
102
 
103
- #: src/admin/general.php:66
104
  msgid "Strategies"
105
  msgstr ""
106
 
107
- #: src/admin/general.php:68
108
  msgid "Select the voting strategies."
109
  msgstr ""
110
 
111
- #: src/admin/general.php:75
112
  msgid "Allow voting in archives"
113
  msgstr ""
114
 
115
- #: src/admin/general.php:82
116
  msgid "Allow guests to vote"
117
  msgstr ""
118
 
119
- #: src/admin/general.php:89
120
  msgid "Unique votes (based on IP Address)"
121
  msgstr ""
122
 
123
- #: src/admin/general.php:101
124
- msgid "Default Position"
125
  msgstr ""
126
 
127
- #: src/admin/general.php:103
128
- msgid "Choose a default position."
 
 
129
  msgstr ""
130
 
131
- #: src/admin/general.php:107
132
- msgid "Top Left"
133
  msgstr ""
134
 
135
- #: src/admin/general.php:114
136
- msgid "Top Center"
137
  msgstr ""
138
 
139
- #: src/admin/general.php:121
140
- msgid "Top Right"
141
  msgstr ""
142
 
143
- #: src/admin/general.php:128
144
- msgid "Bottom Left"
145
  msgstr ""
146
 
147
- #: src/admin/general.php:135
148
- msgid "Bottom Center"
149
  msgstr ""
150
 
151
- #: src/admin/general.php:142
152
- msgid "Bottom Right"
 
 
 
153
  msgstr ""
154
 
155
- #: src/admin/general.php:154
156
- msgid "Disable Locations"
157
  msgstr ""
158
 
159
- #: src/admin/general.php:156
160
- msgid "Select the locations where the star ratings should be excluded."
161
  msgstr ""
162
 
163
- #: src/admin/general.php:163
164
- msgid "Home page"
165
  msgstr ""
166
 
167
- #: src/admin/general.php:170
168
- msgid "Archives"
169
  msgstr ""
170
 
171
- #: src/admin/general.php:177
172
- msgid "Posts"
173
  msgstr ""
174
 
175
- #: src/admin/general.php:184
176
- msgid "Pages"
177
  msgstr ""
178
 
179
- #: src/admin/general.php:197
180
- msgid "Disable Categories"
181
  msgstr ""
182
 
183
- #: src/admin/general.php:204
184
- msgid ""
185
- "Exclude star ratings from posts belonging to the selected "
186
- "categories.<br>Use <strong>cmd/ctrl + click</strong> to select/deselect "
187
- "multiple categories."
188
  msgstr ""
189
 
190
  #: src/admin/rich-snippets.php:23
@@ -227,18 +238,34 @@ msgstr ""
227
  msgid "A rating is required to vote."
228
  msgstr ""
229
 
230
- #: src/functions.php:340
231
  msgid "You can only rate between 0 and %s."
232
  msgstr ""
233
 
234
- #: src/functions.php:441
235
  msgid "General"
236
  msgstr ""
237
 
238
- #: src/functions.php:442
239
  msgid "Rich Snippets"
240
  msgstr ""
241
 
242
- #: src/functions.php:443
243
  msgid "Appearance"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  msgstr ""
4
  msgstr ""
5
  "Project-Id-Version: \n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/kk-star-ratings\n"
7
+ "POT-Creation-Date: 2019-07-24 06:02:44+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
88
  msgid "Stroke color of hover stars."
89
  msgstr ""
90
 
91
+ #: src/admin/general.php:49
92
+ msgid "Posts"
93
+ msgstr ""
94
+
95
+ #: src/admin/general.php:50
96
+ msgid "Pages"
97
+ msgstr ""
98
+
99
+ #: src/admin/general.php:57 src/admin/rich-snippets.php:18
100
+ #: views/metabox/index.php:20
101
  msgid "Status"
102
  msgstr ""
103
 
104
+ #: src/admin/general.php:58 src/admin/rich-snippets.php:19
105
  msgid "Active"
106
  msgstr ""
107
 
108
+ #: src/admin/general.php:62
109
  msgid "Globally activate/deactivate the star ratings."
110
  msgstr ""
111
 
112
+ #: src/admin/general.php:69
113
  msgid "Strategies"
114
  msgstr ""
115
 
116
+ #: src/admin/general.php:71
117
  msgid "Select the voting strategies."
118
  msgstr ""
119
 
120
+ #: src/admin/general.php:78
121
  msgid "Allow voting in archives"
122
  msgstr ""
123
 
124
+ #: src/admin/general.php:85
125
  msgid "Allow guests to vote"
126
  msgstr ""
127
 
128
+ #: src/admin/general.php:92
129
  msgid "Unique votes (based on IP Address)"
130
  msgstr ""
131
 
132
+ #: src/admin/general.php:104
133
+ msgid "Manual Control"
134
  msgstr ""
135
 
136
+ #: src/admin/general.php:106
137
+ msgid ""
138
+ "Select the post types that should not auto embed the<br>markup and will be "
139
+ "manually controlled by the theme.<br>E.g. Using %s in your template."
140
  msgstr ""
141
 
142
+ #: src/admin/general.php:123
143
+ msgid "Disable Locations"
144
  msgstr ""
145
 
146
+ #: src/admin/general.php:125
147
+ msgid "Select the locations where the star ratings should be excluded."
148
  msgstr ""
149
 
150
+ #: src/admin/general.php:137
151
+ msgid "Home page"
152
  msgstr ""
153
 
154
+ #: src/admin/general.php:141
155
+ msgid "Archives"
156
  msgstr ""
157
 
158
+ #: src/admin/general.php:153
159
+ msgid "Disable Categories"
160
  msgstr ""
161
 
162
+ #: src/admin/general.php:160
163
+ msgid ""
164
+ "Exclude star ratings from posts belonging to the selected "
165
+ "categories.<br>Use <strong>cmd/ctrl + click</strong> to select/deselect "
166
+ "multiple categories."
167
  msgstr ""
168
 
169
+ #: src/admin/general.php:167
170
+ msgid "Default Position"
171
  msgstr ""
172
 
173
+ #: src/admin/general.php:169
174
+ msgid "Choose a default position."
175
  msgstr ""
176
 
177
+ #: src/admin/general.php:173
178
+ msgid "Top Left"
179
  msgstr ""
180
 
181
+ #: src/admin/general.php:180
182
+ msgid "Top Center"
183
  msgstr ""
184
 
185
+ #: src/admin/general.php:187
186
+ msgid "Top Right"
187
  msgstr ""
188
 
189
+ #: src/admin/general.php:194
190
+ msgid "Bottom Left"
191
  msgstr ""
192
 
193
+ #: src/admin/general.php:201
194
+ msgid "Bottom Center"
195
  msgstr ""
196
 
197
+ #: src/admin/general.php:208
198
+ msgid "Bottom Right"
 
 
 
199
  msgstr ""
200
 
201
  #: src/admin/rich-snippets.php:23
238
  msgid "A rating is required to vote."
239
  msgstr ""
240
 
241
+ #: src/functions.php:372
242
  msgid "You can only rate between 0 and %s."
243
  msgstr ""
244
 
245
+ #: src/functions.php:511
246
  msgid "General"
247
  msgstr ""
248
 
249
+ #: src/functions.php:512
250
  msgid "Rich Snippets"
251
  msgstr ""
252
 
253
+ #: src/functions.php:513
254
  msgid "Appearance"
255
+ msgstr ""
256
+
257
+ #: views/metabox/index.php:13
258
+ msgid "Reset Ratings"
259
+ msgstr ""
260
+
261
+ #: views/metabox/index.php:26
262
+ msgid "Auto"
263
+ msgstr ""
264
+
265
+ #: views/metabox/index.php:30
266
+ msgid "Enable"
267
+ msgstr ""
268
+
269
+ #: views/metabox/index.php:34
270
+ msgid "Disable"
271
  msgstr ""
public/css/kk-star-ratings.css CHANGED
@@ -1,8 +1,8 @@
1
  .kk-star-ratings {
2
- display: -webkit-box;
3
- display: -webkit-flex;
4
- display: -ms-flexbox;
5
- display: flex;
6
  -webkit-box-align: center;
7
  -webkit-align-items: center;
8
  -ms-flex-align: center;
@@ -14,7 +14,8 @@
14
  }
15
 
16
  .kk-star-ratings.kksr-bottom {
17
- margin-top: 2rem;
 
18
  }
19
 
20
  .kk-star-ratings.kksr-center {
1
  .kk-star-ratings {
2
+ display: -webkit-box !important;
3
+ display: -webkit-flex !important;
4
+ display: -ms-flexbox !important;
5
+ display: flex !important;
6
  -webkit-box-align: center;
7
  -webkit-align-items: center;
8
  -ms-flex-align: center;
14
  }
15
 
16
  .kk-star-ratings.kksr-bottom {
17
+ /* margin-top: 2rem; */
18
+ margin: 2rem 0;
19
  }
20
 
21
  .kk-star-ratings.kksr-center {
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: star ratings, votings, rate posts, ajax ratings, infinite stars, unlimited
5
  Requires at least: 4.5
6
  Requires PHP: 5.5.9
7
  Tested up to: 5.2.2
8
- Stable tag: 3.0.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -92,6 +92,32 @@ The source of this plugin is located at [Github](https://github.com/kamalkhan/kk
92
 
93
  == Changelog ==
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  = 3.0.0 =
96
 
97
  **Added**
5
  Requires at least: 4.5
6
  Requires PHP: 5.5.9
7
  Tested up to: 5.2.2
8
+ Stable tag: 3.1.0
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
92
 
93
  == Changelog ==
94
 
95
+ = 3.1.0 =
96
+
97
+ **Added**
98
+ - Bottom margin added when bottom position in effect.
99
+ - Ability to reset ratings for individual posts/pages.
100
+ - Enable/disable star ratings for individual posts/pages.
101
+ - Take manual control of the auto embedded markup to avoid duplication when using in a template.
102
+
103
+ **Fixed**
104
+ - Markup is now hidden under AMP.
105
+ - Assets are now enqueued when manually/forcefully loading the markup via template function.
106
+
107
+ **Changed**
108
+ - Default colors have been updated.
109
+ - Default size is now 22px instead of 24px.
110
+ - Structured data now uses ratingCount instead of reviewCount.
111
+
112
+ **Removed**
113
+ - Nothing
114
+
115
+ **Deprecated**
116
+ - Nothing
117
+
118
+ **Security**
119
+ - Nothing
120
+
121
  = 3.0.0 =
122
 
123
  **Added**
src/admin/general.php CHANGED
@@ -13,6 +13,7 @@ namespace Bhittani\StarRating;
13
 
14
  $enabled = (bool) getOption('enable');
15
  $position = getOption('position');
 
16
  $excludedLocations = getOption('exclude_locations');
17
  $strategies = getOption('strategies');
18
  $excludedCategories = getOption('exclude_categories', []);
@@ -33,20 +34,22 @@ foreach ($categories as $category) {
33
  ];
34
  }
35
 
36
- $excludedPostTypes = [];
37
 
38
- $postTypes = get_post_types(['publicly_queryable' => true, '_builtin' => false], 'objects');
39
 
40
- foreach ($postTypes as $postType) {
41
- $excludedPostTypes[] = [
42
- 'field' => 'checkbox',
43
- 'label' => $postType->labels->name,
44
- 'name' => prefix('exclude_locations[]'),
45
  'value' => $postType->name,
46
- 'checked' => in_array($postType->name, $excludedLocations),
47
  ];
48
  }
49
 
 
 
 
 
 
50
  return [
51
  [
52
  'field' => 'checkbox',
@@ -94,6 +97,69 @@ return [
94
  ],
95
  ],
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  // Position
98
 
99
  [
@@ -146,61 +212,4 @@ return [
146
  ],
147
  ],
148
  ],
149
-
150
- // Locations
151
-
152
- [
153
- 'id' => prefix('exclude_locations'),
154
- 'title' => __('Disable Locations', 'kk-star-ratings'),
155
- 'name' => prefix('exclude_locations'),
156
- 'help' => __('Select the locations where the star ratings should be excluded.', 'kk-star-ratings'),
157
- 'filter' => function ($values) {
158
- return (array) $values;
159
- },
160
- 'fields' => array_merge([
161
- [
162
- 'field' => 'checkbox',
163
- 'label' => __('Home page', 'kk-star-ratings'),
164
- 'name' => prefix('exclude_locations[]'),
165
- 'value' => 'home',
166
- 'checked' => in_array('home', $excludedLocations),
167
- ],
168
- [
169
- 'field' => 'checkbox',
170
- 'label' => __('Archives', 'kk-star-ratings'),
171
- 'name' => prefix('exclude_locations[]'),
172
- 'value' => 'archives',
173
- 'checked' => in_array('archives', $excludedLocations),
174
- ],
175
- [
176
- 'field' => 'checkbox',
177
- 'label' => __('Posts', 'kk-star-ratings'),
178
- 'name' => prefix('exclude_locations[]'),
179
- 'value' => 'post',
180
- 'checked' => in_array('post', $excludedLocations),
181
- ],
182
- [
183
- 'field' => 'checkbox',
184
- 'label' => __('Pages', 'kk-star-ratings'),
185
- 'name' => prefix('exclude_locations[]'),
186
- 'value' => 'page',
187
- 'checked' => in_array('page', $excludedLocations),
188
- ],
189
- ], $excludedPostTypes),
190
- ],
191
-
192
- // Categories
193
-
194
- [
195
- 'field' => 'select',
196
- 'id' => prefix('exclude_categories'),
197
- 'title' => __('Disable Categories', 'kk-star-ratings'),
198
- 'name' => prefix('exclude_categories'),
199
- 'multiple' => true,
200
- 'filter' => function ($values) {
201
- return (array) $values;
202
- },
203
- 'options' => $categoriesOptions,
204
- 'help' => __('Exclude star ratings from posts belonging to the selected categories.<br>Use <strong>cmd/ctrl + click</strong> to select/deselect multiple categories.', 'kk-star-ratings'),
205
- ],
206
  ];
13
 
14
  $enabled = (bool) getOption('enable');
15
  $position = getOption('position');
16
+ $manuallyControlled = getOption('manual_control');
17
  $excludedLocations = getOption('exclude_locations');
18
  $strategies = getOption('strategies');
19
  $excludedCategories = getOption('exclude_categories', []);
34
  ];
35
  }
36
 
37
+ $postTypes = [];
38
 
39
+ $customPostTypes = get_post_types(['publicly_queryable' => true, '_builtin' => false], 'objects');
40
 
41
+ foreach ($customPostTypes as $postType) {
42
+ $postTypes[] = [
 
 
 
43
  'value' => $postType->name,
44
+ 'label' => $postType->labels->name,
45
  ];
46
  }
47
 
48
+ $postTypes = array_merge([
49
+ ['value' => 'post', 'label' => __('Posts', 'kk-star-ratings')],
50
+ ['value' => 'page', 'label' => __('Pages', 'kk-star-ratings')],
51
+ ], $customPostTypes);
52
+
53
  return [
54
  [
55
  'field' => 'checkbox',
97
  ],
98
  ],
99
 
100
+ // Manual Control
101
+
102
+ [
103
+ 'id' => prefix('manual_control'),
104
+ 'title' => __('Manual Control', 'kk-star-ratings'),
105
+ 'name' => prefix('manual_control'),
106
+ 'help' => sprintf(__('Select the post types that should not auto embed the<br>markup and will be manually controlled by the theme.<br>E.g. Using %s in your template.', 'kk-star-ratings'), '<code>echo kk_star_ratings();</code>'),
107
+ 'filter' => function ($values) {
108
+ return (array) $values;
109
+ },
110
+ 'fields' => array_map(function ($field) use ($manuallyControlled) {
111
+ $field['field'] = 'checkbox';
112
+ $field['name'] = prefix('manual_control[]');
113
+ $field['checked'] = in_array($field['value'], $manuallyControlled);
114
+
115
+ return $field;
116
+ }, $postTypes),
117
+ ],
118
+
119
+ // Locations
120
+
121
+ [
122
+ 'id' => prefix('exclude_locations'),
123
+ 'title' => __('Disable Locations', 'kk-star-ratings'),
124
+ 'name' => prefix('exclude_locations'),
125
+ 'help' => __('Select the locations where the star ratings should be excluded.', 'kk-star-ratings'),
126
+ 'filter' => function ($values) {
127
+ return (array) $values;
128
+ },
129
+ 'fields' => array_map(function ($field) use ($excludedLocations) {
130
+ $field['field'] = 'checkbox';
131
+ $field['name'] = prefix('exclude_locations[]');
132
+ $field['checked'] = in_array($field['value'], $excludedLocations);
133
+
134
+ return $field;
135
+ }, array_merge([
136
+ [
137
+ 'label' => __('Home page', 'kk-star-ratings'),
138
+ 'value' => 'home',
139
+ ],
140
+ [
141
+ 'label' => __('Archives', 'kk-star-ratings'),
142
+ 'value' => 'archives',
143
+ ],
144
+ ], $postTypes)
145
+ ),
146
+ ],
147
+
148
+ // Categories
149
+
150
+ [
151
+ 'field' => 'select',
152
+ 'id' => prefix('exclude_categories'),
153
+ 'title' => __('Disable Categories', 'kk-star-ratings'),
154
+ 'name' => prefix('exclude_categories'),
155
+ 'multiple' => true,
156
+ 'filter' => function ($values) {
157
+ return (array) $values;
158
+ },
159
+ 'options' => $categoriesOptions,
160
+ 'help' => __('Exclude star ratings from posts belonging to the selected categories.<br>Use <strong>cmd/ctrl + click</strong> to select/deselect multiple categories.', 'kk-star-ratings'),
161
+ ],
162
+
163
  // Position
164
 
165
  [
212
  ],
213
  ],
214
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
  ];
src/enqueue.php CHANGED
@@ -11,9 +11,9 @@
11
 
12
  namespace Bhittani\StarRating;
13
 
14
- add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'styles'); function styles()
15
  {
16
- if (isValidRequest()) {
17
  wp_enqueue_style(
18
  KKSR_SLUG,
19
  KKSR_URI.'css/kk-star-ratings.css',
@@ -23,9 +23,9 @@ add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'styles'); function styles()
23
  }
24
  }
25
 
26
- add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'scripts'); function scripts()
27
  {
28
- if (isValidRequest()) {
29
  wp_enqueue_script(
30
  KKSR_SLUG,
31
  KKSR_URI.'js/kk-star-ratings.js',
@@ -45,9 +45,9 @@ add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'scripts'); function scripts()
45
  }
46
  }
47
 
48
- add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'stylesheet'); function stylesheet()
49
  {
50
- if (! isValidRequest()) {
51
  return;
52
  }
53
 
11
 
12
  namespace Bhittani\StarRating;
13
 
14
+ add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'styles'); function styles($force = false)
15
  {
16
+ if ($force || isValidRequest()) {
17
  wp_enqueue_style(
18
  KKSR_SLUG,
19
  KKSR_URI.'css/kk-star-ratings.css',
23
  }
24
  }
25
 
26
+ add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'scripts'); function scripts($force = false)
27
  {
28
+ if ($force || isValidRequest()) {
29
  wp_enqueue_script(
30
  KKSR_SLUG,
31
  KKSR_URI.'js/kk-star-ratings.js',
45
  }
46
  }
47
 
48
+ add_action('wp_enqueue_scripts', KKSR_NAMESPACE.'stylesheet'); function stylesheet($force = false)
49
  {
50
+ if (! ($force || isValidRequest())) {
51
  return;
52
  }
53
 
src/functions.php CHANGED
@@ -18,6 +18,7 @@ function options()
18
  // General
19
  'enable' => true,
20
  'position' => 'top-left',
 
21
  'exclude_locations' => [],
22
  'exclude_categories' => [],
23
  'strategies' => ['guests', 'unique'],
@@ -27,13 +28,13 @@ function options()
27
  'sd_context' => 'https://schema.org/',
28
  // Appearance
29
  'stars' => 5,
30
- 'size' => 24,
31
  'fill_color_star' => '#ffffff',
32
- 'stroke_color_star' => '#333333',
33
- 'fill_color_active_star' => '#dddddd',
34
- 'stroke_color_active_star' => '#333333',
35
- 'fill_color_hover_star' => '#f2fa6f',
36
- 'stroke_color_hover_star' => '#333333',
37
  ];
38
  }
39
 
@@ -189,10 +190,29 @@ function canVote($p = null)
189
  return apply_filters($filterTag, true, $p);
190
  }
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  function isValidPost($p = null)
193
  {
 
 
194
  global $post;
195
  $p = $p ?: $post;
 
196
 
197
  $filterTag = prefix('is_valid_post');
198
 
@@ -201,16 +221,23 @@ function isValidPost($p = null)
201
  return apply_filters($filterTag, false, $p);
202
  }
203
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  if ($status = get_post_meta($p->ID, '_'.prefix('status'), true)) {
205
  // Exclusive status.
206
  return apply_filters($filterTag, $status == 'enable', $p);
207
  }
208
 
209
- if (has_shortcode($p->post_content, KKSR_SHORTCODE)) {
210
- // Has shortcode.
211
- return apply_filters($filterTag, true, $p);
212
- }
213
-
214
  $categories = array_map(function ($category) {
215
  return $category->term_id;
216
  }, get_the_category($p->ID));
@@ -229,7 +256,7 @@ function isValidPost($p = null)
229
  return apply_filters($filterTag, $bool, $p);
230
  }
231
 
232
- function isValidRequest()
233
  {
234
  $filterTag = prefix('is_valid_request');
235
 
@@ -238,13 +265,18 @@ function isValidRequest()
238
  return apply_filters($filterTag, false);
239
  }
240
 
 
 
 
 
 
241
  $bool =
242
  // home or front page AND home is not an excluded location.
243
  (! in_array('home', getOption('exclude_locations')) && (is_front_page() || is_home()))
244
  // archives AND archives is not an excluded location.
245
  || (! in_array('archives', getOption('exclude_locations')) && is_archive())
246
  // singular AND (exclusively enabled OR (post does not belong to an excluded category AND post type is not an excluded location)).
247
- || (is_singular() && isValidPost());
248
 
249
  return apply_filters($filterTag, $bool);
250
  }
@@ -358,13 +390,51 @@ function vote($idOrPost, $rating)
358
  return [$ratings, $count];
359
  }
360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  function get($post = null, $force = null)
362
  {
363
  $force = is_null($force) ? ($post ? true : false) : $force;
364
 
 
 
 
 
365
  return markup(null, $force, $post);
366
  }
367
 
 
 
 
 
 
 
 
 
 
 
 
368
  function collect($limit = 5, $taxonomyId = null, $offset = 0)
369
  {
370
  global $wpdb;
18
  // General
19
  'enable' => true,
20
  'position' => 'top-left',
21
+ 'manual_control' => [],
22
  'exclude_locations' => [],
23
  'exclude_categories' => [],
24
  'strategies' => ['guests', 'unique'],
28
  'sd_context' => 'https://schema.org/',
29
  // Appearance
30
  'stars' => 5,
31
+ 'size' => 22,
32
  'fill_color_star' => '#ffffff',
33
+ 'stroke_color_star' => '#555555',
34
+ 'fill_color_active_star' => '#fb9005',
35
+ 'stroke_color_active_star' => '#2c1901',
36
+ 'fill_color_hover_star' => '#fffb00',
37
+ 'stroke_color_hover_star' => '#201f00',
38
  ];
39
  }
40
 
190
  return apply_filters($filterTag, true, $p);
191
  }
192
 
193
+ // function force($bool = true)
194
+ // {
195
+ // static $isForced;
196
+
197
+ // if (! is_null($bool)) {
198
+ // $isForced = (bool) $bool;
199
+ // }
200
+
201
+ // return (bool) $isForced;
202
+ // }
203
+
204
+ // function isForced()
205
+ // {
206
+ // return force(null);
207
+ // }
208
+
209
  function isValidPost($p = null)
210
  {
211
+ $bail = $p === false;
212
+
213
  global $post;
214
  $p = $p ?: $post;
215
+ $p = is_object($p) ? $p : get_post($p);
216
 
217
  $filterTag = prefix('is_valid_post');
218
 
221
  return apply_filters($filterTag, false, $p);
222
  }
223
 
224
+ // if (isForced()) {
225
+ // // Manually forced.
226
+ // return apply_filters($filterTag, true, $p);
227
+ // }
228
+
229
+ if ($bail && (
230
+ has_shortcode($p->post_content, KKSR_SHORTCODE)
231
+ || has_shortcode($p->post_content, 'kkratings')
232
+ )) {
233
+ return apply_filters($filterTag, false, $p);
234
+ }
235
+
236
  if ($status = get_post_meta($p->ID, '_'.prefix('status'), true)) {
237
  // Exclusive status.
238
  return apply_filters($filterTag, $status == 'enable', $p);
239
  }
240
 
 
 
 
 
 
241
  $categories = array_map(function ($category) {
242
  return $category->term_id;
243
  }, get_the_category($p->ID));
256
  return apply_filters($filterTag, $bool, $p);
257
  }
258
 
259
+ function isValidRequest($p = null)
260
  {
261
  $filterTag = prefix('is_valid_request');
262
 
265
  return apply_filters($filterTag, false);
266
  }
267
 
268
+ // if (isForced()) {
269
+ // // Manually forced.
270
+ // return apply_filters($filterTag, true);
271
+ // }
272
+
273
  $bool =
274
  // home or front page AND home is not an excluded location.
275
  (! in_array('home', getOption('exclude_locations')) && (is_front_page() || is_home()))
276
  // archives AND archives is not an excluded location.
277
  || (! in_array('archives', getOption('exclude_locations')) && is_archive())
278
  // singular AND (exclusively enabled OR (post does not belong to an excluded category AND post type is not an excluded location)).
279
+ || (is_singular() && isValidPost($p));
280
 
281
  return apply_filters($filterTag, $bool);
282
  }
390
  return [$ratings, $count];
391
  }
392
 
393
+ function queue($post = null)
394
+ {
395
+ // static $queued;
396
+
397
+ // if ($queued) {
398
+ // return;
399
+ // }
400
+
401
+ styles(true);
402
+ scripts(true);
403
+ stylesheet(true);
404
+
405
+ $sd = function () use ($post) {
406
+ echo structuredData(true, $post);
407
+ };
408
+
409
+ if (! has_action('wp_footer', $sd)) {
410
+ add_action('wp_footer', $sd);
411
+ }
412
+
413
+ // $queued = true;
414
+ }
415
+
416
  function get($post = null, $force = null)
417
  {
418
  $force = is_null($force) ? ($post ? true : false) : $force;
419
 
420
+ if ($force) {
421
+ queue($post);
422
+ }
423
+
424
  return markup(null, $force, $post);
425
  }
426
 
427
+ function quick($atts, $shortcode = '')
428
+ {
429
+ extract(shortcode_atts(['id' => null, 'force' => null], $atts, $shortcode));
430
+
431
+ $force = is_null($force)
432
+ ? (in_array('force', (array) $atts) ? true : null)
433
+ : (in_array($force, ['null', 'false']) ? false : (bool) $force);
434
+
435
+ return get($id ?: false, $force);
436
+ }
437
+
438
  function collect($limit = 5, $taxonomyId = null, $offset = 0)
439
  {
440
  global $wpdb;
src/legacy.php CHANGED
@@ -10,9 +10,11 @@
10
  */
11
 
12
  if (! function_exists('kk_star_ratings')) {
13
- function kk_star_ratings($post = null, $force = null)
14
  {
15
- return \Bhittani\StarRating\get($post, $force);
 
 
16
  }
17
  }
18
 
@@ -22,3 +24,8 @@ if (! function_exists('kk_star_ratings_get')) {
22
  return \Bhittani\StarRating\collect($limit, $taxonomyId, $offset);
23
  }
24
  }
 
 
 
 
 
10
  */
11
 
12
  if (! function_exists('kk_star_ratings')) {
13
+ function kk_star_ratings($postOrForce = null, $force = null)
14
  {
15
+ $force = is_null($force) ? (is_bool($postOrForce) ? $postOrForce : null) : $force;
16
+
17
+ return \Bhittani\StarRating\get(is_bool($postOrForce) ? null : $postOrForce, $force);
18
  }
19
  }
20
 
24
  return \Bhittani\StarRating\collect($limit, $taxonomyId, $offset);
25
  }
26
  }
27
+
28
+ add_shortcode('kkratings', KKSR_NAMESPACE.'legacyShortcode'); function legacyShortcode($atts)
29
+ {
30
+ return quick($atts, 'kkratings');
31
+ }
src/markup.php CHANGED
@@ -13,17 +13,24 @@ namespace Bhittani\StarRating;
13
 
14
  add_filter('the_content', KKSR_NAMESPACE.'markup'); function markup($content, $force = false, $p = null)
15
  {
16
- if (! $force && ! (isValidRequest() && isValidPost())) {
 
 
 
 
17
  return $content;
18
  }
19
 
20
- if (! $force && has_shortcode($content, KKSR_SHORTCODE)) {
 
 
 
21
  return $content;
22
  }
23
 
24
- global $post;
25
- $p = $p ?: $post;
26
- $p = is_object($p) ? $p : get_post($p);
27
 
28
  $id = $p->ID;
29
  $isRtl = is_rtl();
13
 
14
  add_filter('the_content', KKSR_NAMESPACE.'markup'); function markup($content, $force = false, $p = null)
15
  {
16
+ global $post;
17
+ $p = $p ?: $post;
18
+ $p = is_object($p) ? $p : get_post($p);
19
+
20
+ if (! $force && ! (isValidRequest($p) && isValidPost($p))) {
21
  return $content;
22
  }
23
 
24
+ if (! $force && (
25
+ has_shortcode($content, KKSR_SHORTCODE)
26
+ || has_shortcode($content, 'kkratings')
27
+ )) {
28
  return $content;
29
  }
30
 
31
+ if (! is_null($content) && in_array(get_post_type($p), getOption('manual_control'))) {
32
+ return $content;
33
+ }
34
 
35
  $id = $p->ID;
36
  $isRtl = is_rtl();
src/metabox.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of bhittani/kk-star-ratings.
5
+ *
6
+ * (c) Kamal Khan <shout@bhittani.com>
7
+ *
8
+ * This source file is subject to the GPL v2 license that
9
+ * is bundled with this source code in the file LICENSE.
10
+ */
11
+
12
+ namespace Bhittani\StarRating;
13
+
14
+ add_action('add_meta_boxes', KKSR_NAMESPACE.'metabox', 10, 2); function metabox($type, $post)
15
+ {
16
+ $customPostTypes = get_post_types(['publicly_queryable' => true, '_builtin' => false], 'names');
17
+ $postTypes = array_merge(['post', 'page'], $customPostTypes);
18
+
19
+ $count = get_post_meta($post->ID, '_'.prefix('casts'), true);
20
+ $ratings = get_post_meta($post->ID, '_'.prefix('ratings'), true);
21
+ $score = calculateScore($ratings, $count, getOption('stars'));
22
+
23
+ $icon = '<span class="dashicons dashicons-star-empty" style="margin-right: .25rem; font-size: 18px;"></span>';
24
+
25
+ $legend = '';
26
+
27
+ if ($score) {
28
+ $legend = "
29
+ <span style=\"float:right;color:#666;\">
30
+ {$score}
31
+ <span style=\"font-weight:normal;color:#ddd;\">/</span>
32
+ <span style=\"font-weight:normal;color:#aaa;\">{$count}</span>
33
+ </span>
34
+ ";
35
+ }
36
+
37
+ add_meta_box(KKSR_SLUG, $icon.KKSR_LABEL.$legend, KKSR_NAMESPACE.'echoMetabox', $postTypes, 'side');
38
+ }
39
+
40
+ function echoMetabox($post)
41
+ {
42
+ wp_nonce_field(basename(__FILE__), KKSR_SLUG.'-metabox-nonce');
43
+
44
+ $resetFieldName = '__'.prefix('reset');
45
+ $statusFieldName = '_'.prefix('status');
46
+ $status = get_post_meta($post->ID, $statusFieldName, true);
47
+
48
+ ob_start();
49
+ include KKSR_PATH_VIEWS.'metabox/index.php';
50
+ echo ob_get_clean();
51
+ }
52
+
53
+ add_action('save_post', KKSR_NAMESPACE.'saveMetabox'); function saveMetabox($id)
54
+ {
55
+ if ((! isset($_POST[KKSR_SLUG.'-metabox-nonce']))
56
+ || (! wp_verify_nonce($_POST[KKSR_SLUG.'-metabox-nonce'], basename(__FILE__)))
57
+ || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
58
+ || (! current_user_can('edit_post', $id))
59
+ // || (is_multisite() && ms_is_switched())
60
+ // || (! (isset( $_POST['post_type'] ) && 'page' === $_POST['post_type']))
61
+ ) {
62
+ return;
63
+ }
64
+
65
+ update_post_meta($id, '_'.prefix('status'), $_POST['_'.prefix('status')]);
66
+
67
+ if (checked($_POST['__'.prefix('reset')], '1')) {
68
+ delete_post_meta($id, '_kksr_avg');
69
+ delete_post_meta($id, '_'.prefix('casts'));
70
+ delete_post_meta($id, '_'.prefix('ratings'));
71
+ }
72
+
73
+ do_action('kksr_save_metabox');
74
+ }
src/shortcode.php CHANGED
@@ -13,16 +13,17 @@ namespace Bhittani\StarRating;
13
 
14
  add_shortcode(KKSR_SHORTCODE, KKSR_NAMESPACE.'shortcode'); function shortcode($atts)
15
  {
16
- extract(shortcode_atts(['id' => null], $atts, KKSR_SHORTCODE));
17
-
18
- return markup(null, true, $id);
19
  }
20
 
21
- // Legacy
22
-
23
- add_shortcode('kkratings', KKSR_NAMESPACE.'shortcodeLegacy'); function shortcodeLegacy($atts)
24
- {
25
- extract(shortcode_atts(['id' => null], $atts, 'kkratings'));
 
 
 
26
 
27
- return markup(null, true, $id);
28
- }
13
 
14
  add_shortcode(KKSR_SHORTCODE, KKSR_NAMESPACE.'shortcode'); function shortcode($atts)
15
  {
16
+ return quick($atts, KKSR_SHORTCODE);
 
 
17
  }
18
 
19
+ // add_filter('shortcode_atts_kkratings', KKSR_NAMESPACE.'filterShortcode');
20
+ // add_filter('shortcode_atts_'.KKSR_SHORTCODE, KKSR_NAMESPACE.'filterShortcode');
21
+ // function filterShortcode($atts)
22
+ // {
23
+ // // if ($atts['id']) {
24
+ // // queue();
25
+ // // }
26
+ // die(var_dump($atts));
27
 
28
+ // return $atts;
29
+ // }
src/structure.php CHANGED
@@ -11,19 +11,21 @@
11
 
12
  namespace Bhittani\StarRating;
13
 
14
- add_action('wp_head', KKSR_NAMESPACE.'structuredData'); function structuredData()
15
  {
16
  if (! getOption('grs')) {
17
  return;
18
  }
19
 
20
- if (! (isValidRequest() && is_singular())) {
 
 
 
 
21
  return;
22
  }
23
 
24
- global $post;
25
-
26
- $id = $post->ID;
27
  $count = (int) get_post_meta($id, '_kksr_casts', true);
28
 
29
  if (! $count) {
@@ -41,5 +43,5 @@ add_action('wp_head', KKSR_NAMESPACE.'structuredData'); function structuredData(
41
  include KKSR_PATH_VIEWS.'structured-data.php';
42
  $html = ob_get_clean();
43
 
44
- echo apply_filters(prefix('structured_data'), $html, $post);
45
  }
11
 
12
  namespace Bhittani\StarRating;
13
 
14
+ add_action('wp_head', KKSR_NAMESPACE.'structuredData'); function structuredData($force = false, $p = null)
15
  {
16
  if (! getOption('grs')) {
17
  return;
18
  }
19
 
20
+ global $post;
21
+ $p = $p ?: $post;
22
+ $p = is_object($p) ? $p : get_post($p);
23
+
24
+ if (! (($force || isValidRequest($p)) && is_singular())) {
25
  return;
26
  }
27
 
28
+ $id = $p->ID;
 
 
29
  $count = (int) get_post_meta($id, '_kksr_casts', true);
30
 
31
  if (! $count) {
43
  include KKSR_PATH_VIEWS.'structured-data.php';
44
  $html = ob_get_clean();
45
 
46
+ echo apply_filters(prefix('structured_data'), $html, $p);
47
  }
views/markup.php CHANGED
@@ -1,4 +1,5 @@
1
  <div data-id="<?php echo $id; ?>" data-score="<?php echo $score; ?>" data-count="<?php echo $count; ?>"
 
2
  class="kk-star-ratings <?php echo (isset($disabled) && $disabled) ? 'kksr-disable' : ''; ?> kksr-<?php echo isset($placement) ? $placement : 'top'; ?> kksr-<?php echo isset($alignment) ? $alignment : 'left'; ?><?php echo (isset($isRtl) && $isRtl) ? ' kksr-rtl' : ''; ?>">
3
  <?php
4
  ob_start();
1
  <div data-id="<?php echo $id; ?>" data-score="<?php echo $score; ?>" data-count="<?php echo $count; ?>"
2
+ style="display:none;"
3
  class="kk-star-ratings <?php echo (isset($disabled) && $disabled) ? 'kksr-disable' : ''; ?> kksr-<?php echo isset($placement) ? $placement : 'top'; ?> kksr-<?php echo isset($alignment) ? $alignment : 'left'; ?><?php echo (isset($isRtl) && $isRtl) ? ' kksr-rtl' : ''; ?>">
4
  <?php
5
  ob_start();
views/metabox/index.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (! defined('ABSPATH')) {
3
+ http_response_code(404);
4
+ die();
5
+ }
6
+ ?>
7
+
8
+ <div class="components-base-control">
9
+ <div class='components-base-control__field'>
10
+ <div style="margin-top: 1rem;">
11
+ <label class="components-base-control__label" style="margin-top: .75rem; margin-bottom: .25rem;">
12
+ <input type="checkbox" name="<?php echo $resetFieldName; ?>" value="1">
13
+ <?php _e('Reset Ratings', 'kk-star-ratings'); ?>
14
+ </label>
15
+ </div>
16
+ </div>
17
+
18
+ <div class='components-base-control__field'>
19
+ <label class="components-base-control__label" style="margin-top: .75rem; margin-bottom: .25rem;">
20
+ <strong><?php _e('Status', 'kk-star-ratings'); ?></strong>
21
+ </label>
22
+
23
+ <div style="margin-top: 1rem;">
24
+ <label class="components-base-control__label" style="margin-top: .5rem; margin-bottom: .25rem;">
25
+ <input type="radio" name="<?php echo $statusFieldName; ?>" value="" <?php checked($status, ''); ?>>
26
+ <?php _e('Auto', 'kk-star-ratings'); ?>
27
+ </label>
28
+ <label class="components-base-control__label" style="margin-top: .5rem; margin-bottom: .25rem;">
29
+ <input type="radio" name="<?php echo $statusFieldName; ?>" value="enable" <?php checked($status, 'enable'); ?>>
30
+ <?php _e('Enable', 'kk-star-ratings'); ?>
31
+ </label>
32
+ <label class="components-base-control__label" style="margin-top: .5rem; margin-bottom: .25rem;">
33
+ <input type="radio" name="<?php echo $statusFieldName; ?>" value="disable" <?php checked($status, 'disable'); ?>>
34
+ <?php _e('Disable', 'kk-star-ratings'); ?>
35
+ </label>
36
+ </div>
37
+
38
+ <?php do_action('kksr_metabox'); ?>
39
+ </div>
40
+ </div>
views/structured-data.php CHANGED
@@ -6,7 +6,7 @@
6
  "aggregateRating": {
7
  "@type": "AggregateRating",
8
  "ratingValue": "<?php echo $score; ?>",
9
- "reviewCount": "<?php echo $count; ?>",
10
  "bestRating": "<?php echo $stars; ?>",
11
  "worstRating": "1"
12
  }
6
  "aggregateRating": {
7
  "@type": "AggregateRating",
8
  "ratingValue": "<?php echo $score; ?>",
9
+ "ratingCount": "<?php echo $count; ?>",
10
  "bestRating": "<?php echo $stars; ?>",
11
  "worstRating": "1"
12
  }