public function show_settings_page() { ?> <div class="wrap"> <?php if (isset($_GET['recount_host_ratings']) && $_GET['recount_host_ratings'] == 'true') { $host_args = array('orderby' => 'post_title', 'order' => 'DESC', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => 'hosts', 'post_mime_type' => '', 'post_status' => 'publish', 'posts_per_page' => -1, 'suppress_filters' => true); $hosts = get_posts($host_args); foreach ($hosts as $host) { rah_run_recalculation($host->ID); } ?> <div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Host Reviews Refreshed</strong></p></div><?php } ?> <h2>Host Reviews Board - Settings & Utilities</h2> <a class="button-secondary" href="<?php echo admin_url('options-general.php?page=rate-a-host'); ?> &recount_host_ratings=true">Re-calculate Host Ratings</a> </div> <?php }
function rah_recalculate_host_ratings($new_status, $old_status, $post) { if ($post->post_type !== 'reviews') { return; } if ($new_status == 'publish' && $old_status != 'publish' || $old_status == 'publish' && $new_status != 'publish') { rah_run_recalculation($post->post_parent); } }