Last active
December 18, 2016 02:14
-
-
Save danielpowney/92d551efd46a59c9753a to your computer and use it in GitHub Desktop.
Recalculate rating item results for a post and rating form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Recalculate rating item results for a post and rating form | |
* | |
* @param unknown $post_id | |
* @param unknown $rating_form_id | |
*/ | |
function mrp_recalculate_rating_item_results( $post_id, $rating_form_id ) { | |
$rating_form = MRP_Multi_Rating_API::get_rating_form( $rating_form_id ); | |
$rating_items = MRP_Multi_Rating_API::get_rating_items( array( 'rating_form_id' => $rating_form_id ) ); | |
// Lets recalculate rating item results for this specific post and rating form | |
foreach ( $rating_items as $rating_item ) { | |
$rating_item_result = MRP_Multi_Rating_API::get_rating_item_result( array( | |
'post_id' => $post_id, | |
'rating_form_id' => $rating_form_id, | |
'rating_item' => $rating_item | |
) ); | |
} | |
} | |
function my_mrp_after_delete_rating_entry_success( $params ) { | |
// params = array( 'rating_entry_id' => $rating_entry_id, 'post_id' => $post_id, 'rating_form_id' => $rating_form_id ) | |
mrp_recalculate_rating_item_results( $params['post_id'], $params['rating_form_id'] ); | |
} | |
function my_mrp_after_save_rating_entry_success( $rating_entry, $is_new, $entry_status_changed ) { | |
mrp_recalculate_rating_item_results( $rating_entry['post_id'], $rating_entry['rating_form_id'] ); | |
} | |
add_action( 'mrp_after_delete_rating_entry_success', 'my_mrp_after_delete_rating_entry_success', 10, 1 ); | |
add_action( 'mrp_after_save_rating_entry_success', 'my_mrp_after_save_rating_entry_success', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment