Changeset 2951952
- Timestamp:
- 08/11/2023 05:53:56 AM (3 years ago)
- Location:
- yet-another-stars-rating/trunk
- Files:
-
- 8 edited
-
admin/editor/YasrOnSavePost.php (modified) (1 diff)
-
docs/yasr_hooks.md (modified) (20 diffs)
-
includes/classes/YasrDB.php (modified) (1 diff)
-
includes/shortcodes/classes/YasrShortcodesAjax.php (modified) (4 diffs)
-
includes/shortcodes/classes/YasrVisitorVotes.php (modified) (1 diff)
-
includes/yasr-includes-functions.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
yet-another-stars-rating.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
yet-another-stars-rating/trunk/admin/editor/YasrOnSavePost.php
r2907917 r2951952 90 90 $rating = (float)$rating; 91 91 92 if ($rating > 5) { 93 $rating = 5; 94 } 95 96 if($rating <= 0) { 97 return; 98 } 92 $rating = yasr_validate_rating($rating, 0); 99 93 100 94 /** -
yet-another-stars-rating/trunk/docs/yasr_hooks.md
r2944495 r2951952 6 6 _Add custom script in one of the page used by YASR, at the beginning_ 7 7 8 | Argument | Type | Description |9 | --- | --- | --- | 10 | $hook | string | |8 |Argument | Type | Description | 9 | --- | --- | --- | 10 |$hook | string | | 11 11 ___ 12 12 ### `do_action('yasr_add_admin_scripts_end')` … … 16 16 _Add custom script in one of the page used by YASR, at the end_ 17 17 18 | Argument | Type | Description |19 | --- | --- | --- | 20 | $hook | string | |18 |Argument | Type | Description | 19 | --- | --- | --- | 20 |$hook | string | | 21 21 ___ 22 22 … … 34 34 _Use this action to add content inside shortcode creator_ 35 35 36 | Argument | Type | Description |37 | --- | --- | --- | 38 | $n_multi_set | int | |39 | $multi_set | string | the multiset name |36 |Argument | Type | Description | 37 | --- | --- | --- | 38 |$n_multi_set | int | | 39 |$multi_set | string | the multiset name | 40 40 ___ 41 41 … … 57 57 _Hook here to add new content at the beginning of the div_ 58 58 59 | Argument | Type | Description |60 | --- | --- | --- | 61 | $post_id | int | |62 | $set_id | int | |59 |Argument | Type | Description | 60 | --- | --- | --- | 61 |$post_id | int | | 62 |$set_id | int | | 63 63 ___ 64 64 ### `do_action('yasr_add_content_multiset_tab_pro')` … … 68 68 _Hook here to add new content_ 69 69 70 | Argument | Type | Description |71 | --- | --- | --- | 72 | $post_id | int | |73 | $set_id | int | |70 |Argument | Type | Description | 71 | --- | --- | --- | 72 |$post_id | int | | 73 |$set_id | int | | 74 74 ___ 75 75 … … 80 80 _Hook here to add actions when YASR save data on save_post_ 81 81 82 | Argument | Type | Description |83 | --- | --- | --- | 84 | $post_id | int | |82 |Argument | Type | Description | 83 | --- | --- | --- | 84 |$post_id | int | | 85 85 ___ 86 86 ### `do_action('yasr_action_on_overall_rating')` … … 90 90 _Do action before overall rating is saved, works only in classic editor_ 91 91 92 | Argument | Type | Description |93 | --- | --- | --- | 94 | $post_id | int | |95 | $rating | float | |92 |Argument | Type | Description | 93 | --- | --- | --- | 94 |$post_id | int | | 95 |$rating | float | | 96 96 ___ 97 97 … … 102 102 _Hook here to add content at the bottom of the metabox_ 103 103 104 | Argument | Type | Description |105 | --- | --- | --- | 106 | $post_id | int | |104 |Argument | Type | Description | 105 | --- | --- | --- | 106 |$post_id | int | | 107 107 ___ 108 108 … … 130 130 _Since this could contain js, this will only allow FALSE as value_ 131 131 132 | Argument | Type | Description |133 | --- | --- | --- | 134 | $style_page_upgrade_pro_js | string | |132 |Argument | Type | Description | 133 | --- | --- | --- | 134 |$style_page_upgrade_pro_js | string | | 135 135 ___ 136 136 … … 248 248 _Use this hook to add (or eventually remove) supported itemTypes_ 249 249 250 | Argument | Type | Description |251 | --- | --- | --- | 252 | $itemTypes | array | an array containing all the default supported itemTypes |250 |Argument | Type | Description | 251 | --- | --- | --- | 252 |$itemTypes | array | an array containing all the default supported itemTypes | 253 253 ___ 254 254 ### `apply_filters('yasr_filter_itemtypes_fields')` … … 264 264 _yasr_softwareapplication_price_ 265 265 266 | Argument | Type | Description |267 | --- | --- | --- | 268 | $additionalFields | array | an array containing all the default supported additional fields |266 |Argument | Type | Description | 267 | --- | --- | --- | 268 |$additionalFields | array | an array containing all the default supported additional fields | 269 269 ___ 270 270 … … 333 333 _If not used, will work with no support for atts_ 334 334 335 | Argument | Type | Description |336 | --- | --- | --- | 337 | $this->shortcode_name | string | Name of shortcode caller |338 | $atts | string|array | Shortcode atts |335 |Argument | Type | Description | 336 | --- | --- | --- | 337 |$this->shortcode_name | string | Name of shortcode caller | 338 |$atts | string|array | Shortcode atts | 339 339 ___ 340 340 ### `apply_filters('yasr_multi_set_ranking_atts')` … … 350 350 _If not used, shortcode will works only with setId param_ 351 351 352 | Argument | Type | Description |353 | --- | --- | --- | 354 | $this->shortcode_name | string | Name of shortcode caller |355 | $atts | string|array | Shortcode atts |352 |Argument | Type | Description | 353 | --- | --- | --- | 354 |$this->shortcode_name | string | Name of shortcode caller | 355 |$atts | string|array | Shortcode atts | 356 356 ___ 357 357 … … 367 367 ### `do_action('yasr_action_on_visitor_vote')` 368 368 369 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 89](.././includes/shortcodes/classes/YasrShortcodesAjax.php:89) 369 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 93](.././includes/shortcodes/classes/YasrShortcodesAjax.php:93) 370 371 _Hook here to add an action on visitor votes (e.g. empty cache)_ 372 373 |Argument | Type | Description | 374 | --- | --- | --- | 375 |$array_action_visitor_vote | array | An array containing post_id and is_singular | 370 376 ___ 371 377 ### `apply_filters('yasr_vv_cookie')` 372 378 373 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 197](.././includes/shortcodes/classes/YasrShortcodesAjax.php:197)379 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 201](.././includes/shortcodes/classes/YasrShortcodesAjax.php:201) 374 380 ___ 375 381 ### `apply_filters('yasr_vv_updated_text')` 376 382 377 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 21 0](.././includes/shortcodes/classes/YasrShortcodesAjax.php:210)383 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 214](.././includes/shortcodes/classes/YasrShortcodesAjax.php:214) 378 384 ___ 379 385 ### `apply_filters('yasr_vv_saved_text')` 380 386 381 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 21 3](.././includes/shortcodes/classes/YasrShortcodesAjax.php:213)387 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 217](.././includes/shortcodes/classes/YasrShortcodesAjax.php:217) 382 388 ___ 383 389 ### `do_action('yasr_action_on_visitor_multiset_vote')` 384 390 385 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 32 4](.././includes/shortcodes/classes/YasrShortcodesAjax.php:324)391 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 328](.././includes/shortcodes/classes/YasrShortcodesAjax.php:328) 386 392 ___ 387 393 ### `apply_filters('yasr_mv_cookie')` 388 394 389 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 4 29](.././includes/shortcodes/classes/YasrShortcodesAjax.php:429)395 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 433](.././includes/shortcodes/classes/YasrShortcodesAjax.php:433) 390 396 ___ 391 397 ### `apply_filters('yasr_mv_saved_text')` 392 398 393 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 4 38](.././includes/shortcodes/classes/YasrShortcodesAjax.php:438)399 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 442](.././includes/shortcodes/classes/YasrShortcodesAjax.php:442) 394 400 ___ 395 401 ### `apply_filters('yasr_filter_ranking_request')` 396 402 397 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 62 1](.././includes/shortcodes/classes/YasrShortcodesAjax.php:621)403 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 625](.././includes/shortcodes/classes/YasrShortcodesAjax.php:625) 398 404 ___ 399 405 ### `apply_filters('yasr_add_sources_ranking_request')` 400 406 401 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 67 2](.././includes/shortcodes/classes/YasrShortcodesAjax.php:672)407 Source: [../includes/shortcodes/classes/YasrShortcodesAjax.php, line 676](.././includes/shortcodes/classes/YasrShortcodesAjax.php:676) 402 408 ___ 403 409 … … 417 423 _Use this filter to customize yasr visitor votes readonly._ 418 424 419 | Argument | Type | Description |420 | --- | --- | --- | 421 | $shortcode_html | string | html for the shortcode |422 | $stored_votes | array | array with average rating data for the post id. |423 | $this->post_id | int | the post id |424 | $stored_votes | YasrDB::visitorVotes() | array |425 |Argument | Type | Description | 426 | --- | --- | --- | 427 |$shortcode_html | string | html for the shortcode | 428 |$stored_votes | array | array with average rating data for the post id. | 429 |$this->post_id | int | the post id | 430 |$stored_votes | YasrDB::visitorVotes() | array | 425 431 ___ 426 432 ### `apply_filters('yasr_vv_cookie')` … … 430 436 _Use this filter to customize the visitor votes cookie name_ 431 437 432 | Argument | Type | Description |433 | --- | --- | --- | 434 | | string | yasr_visitor_votes_cookie is the default name |438 |Argument | Type | Description | 439 | --- | --- | --- | 440 | | string | yasr_visitor_votes_cookie is the default name | 435 441 ___ 436 442 ### `apply_filters('yasr_cstm_text_already_voted')` … … 466 472 _"General Settings" -> "Custom text to display BEFORE Visitor Rating"_ 467 473 468 | Argument | Type | Description |469 | --- | --- | --- | 470 | $number_of_votes | int | the total number of votes |471 | $average_rating | float | the average rating |472 | $this->unique_id | string | the dom ID |474 |Argument | Type | Description | 475 | --- | --- | --- | 476 |$number_of_votes | int | the total number of votes | 477 |$average_rating | float | the average rating | 478 |$this->unique_id | string | the dom ID | 473 479 ___ 474 480 ### `apply_filters('yasr_cstm_text_after_vv')` … … 482 488 _"General Settings" -> "Custom text to display AFTER Visitor Rating"_ 483 489 484 | Argument | Type | Description |485 | --- | --- | --- | 486 | $number_of_votes | int | the total number of votes |487 | $average_rating | float | the average rating |488 | $this->unique_id | string | the dom ID |490 |Argument | Type | Description | 491 | --- | --- | --- | 492 |$number_of_votes | int | the total number of votes | 493 |$average_rating | float | the average rating | 494 |$this->unique_id | string | the dom ID | 489 495 ___ 490 496 ### `apply_filters('yasr_vv_shortcode')` … … 494 500 _Use this filter to customize the yasr_visitor_votes shortcode_ 495 501 496 | Argument | Type | Description |497 | --- | --- | --- | 498 | $shortcode_html | string | html for the shortcode |499 | $this->post_id | int | the post id |500 | $this->starSize | string | () the star size |501 | $this->readonly | string | is the stars are readonly or not |502 | $this->ajax_nonce_visitor | string | the WordPress nonce |503 | $this->is_singular | string | if the current page is_singular or not |502 |Argument | Type | Description | 503 | --- | --- | --- | 504 |$shortcode_html | string | html for the shortcode | 505 |$this->post_id | int | the post id | 506 |$this->starSize | string | () the star size | 507 |$this->readonly | string | is the stars are readonly or not | 508 |$this->ajax_nonce_visitor | string | the WordPress nonce | 509 |$this->is_singular | string | if the current page is_singular or not | 504 510 ___ 505 511 … … 537 543 _Use this hook to write your custom microdata from scratch_ 538 544 539 | Argument | Type | Description |540 | --- | --- | --- | 541 | $item_type_for_post | string | the itemType selected for the post |545 |Argument | Type | Description | 546 | --- | --- | --- | 547 |$item_type_for_post | string | the itemType selected for the post | 542 548 ___ 543 549 ### `apply_filters('yasr_filter_existing_schema')` -
yet-another-stars-rating/trunk/includes/classes/YasrDB.php
r2944495 r2951952 91 91 $overall_rating = get_post_meta($post_id, 'yasr_overall_rating', true); 92 92 93 if (!$overall_rating || $overall_rating < 0) { 94 $overall_rating = 0; 95 } 96 if($overall_rating > 5) { 97 $overall_rating = 5; 98 } 93 $overall_rating = yasr_validate_rating($overall_rating, 0); 94 99 95 return $overall_rating; 100 96 } -
yet-another-stars-rating/trunk/includes/shortcodes/classes/YasrShortcodesAjax.php
r2944495 r2951952 44 44 add_action('wp_ajax_nopriv_yasr_send_visitor_rating', array($this, 'saveVV')); 45 45 46 //die if post status is non publish 47 add_action('yasr_action_on_visitor_vote', array($this, 'dieIfPrivatePost')); 48 add_action('yasr_action_on_visitor_multiset_vote', array($this, 'dieIfPrivatePost')); 49 46 50 //MV save rating 47 51 add_action('wp_ajax_yasr_visitor_multiset_field_vote', array($this, 'saveMV')); … … 69 73 $this->dieIfNotAjax(); 70 74 71 if (isset($_POST['rating'], $_POST['post_id'])) { 72 $rating = (int) $_POST['rating']; 73 $post_id = (int) $_POST['post_id']; 74 $is_singular = $_POST['is_singular']; 75 } 76 else { 77 echo ($this->returnErrorResponse(__('Error in Ajax Call, missing required param.', 'yet-another-stars-rating'))); 78 die(); 79 } 80 81 if(isset($_POST['nonce_visitor'])) { 82 $nonce_visitor = $_POST['nonce_visitor']; 83 } else { 84 $nonce_visitor = false; 85 } 86 87 $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular); 88 89 do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote); 90 91 $nonce_response = self::validNonce($nonce_visitor, 'yasr_nonce_vv'); 92 if($nonce_response !== true) { 93 die($nonce_response); 94 } 95 96 if(YASR_ALLOWED_USER === 'logged_only' && !is_user_logged_in()) { 97 echo ($this->returnErrorResponse(__('Only logged in user can rate.', 'yet-another-stars-rating'))); 98 die(); 99 } 100 101 if ($rating < 1) { 102 $rating = 1; 103 } 104 elseif ($rating > 5) { 105 $rating = 5; 106 } 107 108 $current_user_id = get_current_user_id(); 75 $this->vvDieIfNotValidData(); 76 77 $post_id = (int) $_POST['post_id']; 78 $is_singular = $_POST['is_singular']; 79 80 $this->vvDieIfNonceInvalid(); 81 82 $this->actionOnVV($post_id, $is_singular); 83 84 $this->vvDieIfNotAllowed(); 85 86 $rating = yasr_validate_rating((int) $_POST['rating']); 109 87 110 88 if (is_user_logged_in()) { 111 $result_insert_log = $this->saveVVLoggedIn($post_id, $current_user_id, $rating);89 $result_insert_log = $this->saveVVLoggedIn($post_id, get_current_user_id(), $rating); 112 90 113 91 } //if user is not logged in insert … … 125 103 die(); // this is required to return a proper result 126 104 } 105 106 /** 107 * Echo an error and die if rating or post id are missing in $_POST 108 * 109 * @author Dario Curvino <@dudo> 110 * 111 * @since 3.4.4 112 * @return void 113 */ 114 private function vvDieIfNotValidData() { 115 if (!isset($_POST['rating']) || !isset($_POST['post_id'])) { 116 echo $this->returnErrorResponse(__('Error in Ajax Call, missing required param.', 'yet-another-stars-rating')); 117 die(); 118 } 119 } 120 121 /** 122 * Validate the nonce 123 * 124 * @author Dario Curvino <@dudo> 125 * 126 * @since 3.4.4 127 * @return void 128 */ 129 private function vvDieIfNonceInvalid () { 130 if(isset($_POST['nonce_visitor'])) { 131 $nonce_visitor = $_POST['nonce_visitor']; 132 } else { 133 $nonce_visitor = false; 134 } 135 136 $nonce_response = self::validNonce($nonce_visitor, 'yasr_nonce_vv'); 137 if($nonce_response !== true) { 138 die($nonce_response); 139 } 140 } 141 142 143 /** 144 * Create an array and add an action to perform on vv 145 * 146 * @author Dario Curvino <@dudo> 147 * 148 * @since 3.4.4 149 * 150 * @param $post_id 151 * @param $is_singular 152 * 153 * @return void 154 */ 155 private function actionOnVV($post_id, $is_singular) { 156 $array_action_visitor_vote = array('post_id' => $post_id, 'is_singular' => $is_singular); 157 158 /** 159 * Hook here to add an action on visitor votes (e.g. empty cache) 160 * @param array $array_action_visitor_vote An array containing post_id and is_singular 161 */ 162 do_action('yasr_action_on_visitor_vote', $array_action_visitor_vote); 163 } 164 165 /** 166 * @author Dario Curvino <@dudo> 167 * 168 * Die if user not allowed to rate 169 * 170 * @since 3.4.4 171 * @return void 172 */ 173 private function vvDieIfNotAllowed() { 174 if(YASR_ALLOWED_USER === 'logged_only' && !is_user_logged_in()) { 175 echo ($this->returnErrorResponse(__('Only logged in user can rate.', 'yet-another-stars-rating'))); 176 die(); 177 } 178 } 179 127 180 128 181 /** … … 285 338 //return rest response 286 339 return $array_to_return; 340 } 341 342 /** 343 * @author Dario Curvino <@dudo> 344 * 345 * @since 3.4.4 346 * 347 * @param $array_action_visitor_vote 348 * 349 * @return void 350 */ 351 public function dieIfPrivatePost($array_action_visitor_vote) { 352 $post_id = $array_action_visitor_vote['post_id']; 353 if(!is_user_logged_in() || !current_user_can(YASR_USER_CAPABILITY_EDIT_POST)) { 354 $status = get_post_status($post_id); 355 356 if ($status !== 'publish') { 357 echo $this->returnErrorResponse(__("This post doesn't exists or is private", 'yet-another-stars-rating')); 358 die(); 359 } 360 } 287 361 } 288 362 -
yet-another-stars-rating/trunk/includes/shortcodes/classes/YasrVisitorVotes.php
r2929048 r2951952 153 153 } 154 154 155 //I've to check $cookie_value !== false before because 156 //if $cookie_value is false, $cookie_value < 1 return true (...wtf...) 155 //I've to check $cookie_value !== false before 157 156 if($cookie_value !== false) { 158 if ($cookie_value > 5) { 159 $cookie_value = 5; 160 } elseif ($cookie_value < 1) { 161 $cookie_value = 1; 162 } 157 $cookie_value = yasr_validate_rating($cookie_value); 163 158 } 164 159 //return int -
yet-another-stars-rating/trunk/includes/yasr-includes-functions.php
r2907917 r2951952 384 384 return esc_html($prefix) . str_shuffle(uniqid()); 385 385 } 386 387 /** 388 * Sanitize rating 389 * 390 * @author Dario Curvino <@dudo> 391 * 392 * @since 3.4.4 393 * 394 * @param $rating 395 * @param $min_value 396 * @param $only_min 397 * @param $only_max 398 * 399 * @return int|mixed 400 */ 401 function yasr_validate_rating($rating, $min_value=1, $only_min=false, $only_max=false) { 402 if(!$rating) { 403 $rating = 0; 404 } 405 406 if ($rating < $min_value) { 407 $rating = $min_value; 408 } 409 elseif ($rating > 5) { 410 $rating = 5; 411 } 412 413 return $rating; 414 } -
yet-another-stars-rating/trunk/readme.txt
r2944495 r2951952 5 5 Contributors: Dudo 6 6 Tested up to: 6.3 7 Stable tag: 3.4. 37 Stable tag: 3.4.4 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 … … 207 207 The full changelog can be found in the plugin's directory. Recent entries: 208 208 209 = 3.4.4 = 210 * TWEAKED: since this version, for non-logged-in users, or users that can't edit posts, it is no longer possible to vote for a post that do not exist or is marked as private. 211 If, for some reason, you need to do this, just add [this code](https://gist.github.com/Dudo1985/9105ee335f6104cc4ce4ea392416678c) into your functions.php file 212 209 213 = 3.4.3 = 210 214 * TWEAKED: The same mechanisms to prevent spam ratings for yasr_visitor_votes now also work for yasr_visitor_multiset. -
yet-another-stars-rating/trunk/yet-another-stars-rating.php
r2944495 r2951952 5 5 * Plugin URI: http://wordpress.org/plugins/yet-another-stars-rating/ 6 6 * Description: Boost the way people interact with your site with an easy WordPress stars rating system! With schema.org rich snippets YASR will improve your SEO 7 * Version: 3.4. 37 * Version: 3.4.4 8 8 * Requires at least: 4.7 9 9 * Requires PHP: 5.4 … … 79 79 // Signal that SDK was initiated. 80 80 do_action( 'yasr_fs_loaded' ); 81 define( 'YASR_VERSION_NUM', '3.4. 3' );81 define( 'YASR_VERSION_NUM', '3.4.4' ); 82 82 //Plugin absolute path 83 83 //e.g. /var/www/html/plugin_development/wp-content/plugins/yet-another-stars-rating
Note: See TracChangeset
for help on using the changeset viewer.