post->ID; $name = get_post_meta($postID, 'schema_item_name', true); $url = get_post_meta($postID, 'schema_item_url', true); $rating = (float) get_post_meta($postID, 'schema_rating', true); if($rating < $min_rate) return str_replace('{rating}', '', $content); if(!$show_rate){ $style = ' style="display: none;"'; } else { $style = ''; } $customPlacement = strpos($content, '{rating}') !== false; if($customPlacement){ $custom = '
' . $rating . ' / ' . $max_rate . ' stars '; $stars = $rating; for($i = 1; $i <= $max_rate; $i++){ $custom .= ''; if($stars > 1){ $custom .= ' '; } elseif($stars > 0) { $size = $stars * 16; if($fill_style == 'vertical'){ $css = 'height: ' . $size . 'px;width:16px;background-position:0 -' . (16 - $size) . 'px;vertical-align:-' . (16 - $size) . 'px;'; } else { $css = 'width: ' . $size . 'px;'; } $custom .= ' '; } else { $custom .= ' '; } $stars--; $custom .= ''; } $custom .= '
'; $content = str_replace('{rating}', $custom, $content); $style = ' style="display: none;"'; } $return = '
' . "\n" . $content . "\n
"; $return .= "\n\n\n"; $return .= ''; $return .= ''; $return .= '' . "\n"; if($name || $url){ $return .= '
' . "\n"; if($name) $return .= '' . "\n"; if($url) $return .= '' . "\n"; $return .= "
\n"; } $return .= '
'; $return .= ''; $return .= '' . $rating . ' / ' . $max_rate . ' stars'; $stars = $rating; for($i = 1; $i <= $max_rate; $i++){ $return .= ''; if($stars > 1){ $return .= ' '; } else { $size = $stars * 16; if($fill_style == 'vertical'){ $css = 'height: ' . $size . 'px;width:16px;background-position:0 -' . (16 - $size) . 'px;vertical-align:middle;'; } else { $css = 'width: ' . $size . 'px;'; } $return .= ' '; } $stars--; $return .= ''; } /*$return .= ''; $return .= ' '; $reutnr .= '';*/ $return .= '
'; $return .= '
'; return $return; } function add_review_box() { add_meta_box('review_schema', 'Review Info', 'review_box', 'post', 'side', 'high'); } function review_box($post) { // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'review_nonce' ); $max_rate = get_option('review-max-rating', 5); $min_rate = get_option('review-interval-rating', 0.5); $min_rate = ($min_rate > 0)?$min_rate:0.5; // The actual fields for data entry echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; } function review_save_postdata( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( !wp_verify_nonce( $_POST['review_nonce'], plugin_basename( __FILE__ ) ) ) return; // Check permissions if ( !current_user_can( 'edit_post', $post_id ) ) return; $itemName = filter_var($_POST['schema_item_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW); $itemURL = filter_var($_POST['schema_item_url'], FILTER_SANITIZE_URL); $rating = $_POST['schema_rating']; if(!update_post_meta($post_id, 'schema_item_name', $itemName)) add_post_meta($post_id, 'schema_item_name', $itemName); if(!update_post_meta($post_id, 'schema_item_url', $itemURL)) add_post_meta($post_id, 'schema_item_url', $itemURL); if(!update_post_meta($post_id, 'schema_rating', $rating)) add_post_meta($post_id, 'schema_rating', $rating); } function add_review_header(){ echo '' . "\n"; } add_filter('the_content', 'add_review_schema'); add_action('add_meta_boxes', 'add_review_box'); add_action('save_post', 'review_save_postdata'); add_action('wp_head', 'add_review_header'); if (is_admin()){ add_action('admin_menu', 'add_review_options_page'); add_action('admin_init', 'register_review_settings'); } ?>