function extra_add_post_rating($post_id, $rating) { if (extra_get_user_post_rating($post_id)) { return array(); } $commentdata = array('comment_type' => EXTRA_RATING_COMMENT_TYPE, 'comment_author' => '', 'comment_author_url' => '', 'comment_author_email' => '', 'comment_post_ID' => absint($post_id), 'comment_content' => abs(floatval($rating))); $user = wp_get_current_user(); if ($user->exists()) { $commentdata['comment_author'] = wp_slash($user->display_name); $commentdata['user_ID'] = $user->ID; } // prevent notifications add_filter('extra_rating_notify_intercept', '__return_zero'); wp_new_comment($commentdata); return array('rating' => $rating, 'average' => extra_set_post_rating_average($post_id)); }
function extra_rating_stars_display($post_id = 0) { $post_id = empty($post_id) ? get_the_ID() : $post_id; if ($rating = extra_get_user_post_rating($post_id)) { $output = '<p id="rate-title" class="rate-title">' . esc_html__('Your Rating:', 'extra') . '</p>'; $output .= '<div id="rated-stars">' . extra_make_fixed_stars($rating) . '</div>'; } else { $title = __('Rate:', 'extra'); $output = '<p id="rate-title" class="rate-title">' . esc_html__('Rate:', 'extra') . '</p>'; $output .= '<div id="rating-stars"></div>'; $output .= '<input type="hidden" id="post_id" value="' . $post_id . '" />'; } echo $output; }