rating, author name, date and price of the product. It'll help you to get more click through rate and better visibility in Google search engine. * Author: Rajesh Namase * Version: 1.1 * Author URI: http://www.techlila.com/ * License: GPLv2 or later */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ define('AUTHOR_PRODUCT_REVIEW_VERSION', '1.1'); include plugin_dir_path(__FILE__).'options.php'; function add_author_product_review($content) { global $wp_query; if( get_post_type() != 'post' || !is_single()) return $content; $max_rate = get_option('review-max-rating', 5); $min_rate = get_option('review-interval-rating', 0.5); $show_rate = get_option('review-show-rating', 1); $fill_style = get_option('review-fill-style', 'horizontal'); $postID = $wp_query->post->ID; $name = get_post_meta($postID, 'schema_product_name', true); $price = get_post_meta($postID, 'schema_product_price', true); $price_currency = get_post_meta($postID, 'schema_price_currency', 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) { $return .= '
' . "\n"; $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 .= '
'; if($name){ $return .= '
' . "\n"; $return .= '' . "\n"; if($price){ if($price_currency) $return .= '
'; else $return .= '
'; } $return .= "
\n"; } return $return; } function add_author_product_review_box() { add_meta_box('author_product_review', 'Product Review Info', 'author_product_review_box', 'post', 'side', 'high'); } function author_product_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; $currencies = array("EUR","USD","GBP","INR","AUD","CAD","AED","CHF","CNY","MYR","THB","NZD","JPY","SGD","PHP","SAR","HKD","MXN","SEK","HUF"); // The actual fields for data entry echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo ''; echo '

'; echo ''; } function author_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; $productName = filter_var($_POST['schema_product_name'], FILTER_SANITIZE_STRING, FILTER_FLAG_ENCODE_LOW); $productPrice = filter_var($_POST['schema_product_price'], FILTER_SANITIZE_STRING); $priceCurrency = filter_var($_POST['schema_price_currency'], FILTER_SANITIZE_STRING); $rating = $_POST['schema_rating']; if(!update_post_meta($post_id, 'schema_product_name', $productName)) add_post_meta($post_id, 'schema_product_name', $productName); if(!update_post_meta($post_id, 'schema_product_price', $productPrice)) add_post_meta($post_id, 'schema_product_price', $productPrice); if(!update_post_meta($post_id, 'schema_price_currency', $priceCurrency)) add_post_meta($post_id, 'schema_price_currency', $priceCurrency); if(!update_post_meta($post_id, 'schema_rating', $rating)) add_post_meta($post_id, 'schema_rating', $rating); } function add_author_review_header(){ echo '' . "\n"; } add_filter('the_content', 'add_author_product_review'); add_action('add_meta_boxes', 'add_author_product_review_box'); add_action('save_post', 'author_review_save_postdata'); add_action('wp_head', 'add_author_review_header'); if (is_admin()){ add_action('admin_menu', 'add_author_product_review_options_page'); add_action('admin_init', 'register_author_product_review_settings'); } // Add settings link on plugin page function author_product_review_settings_link($links) { $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } $plugin = plugin_basename(__FILE__); add_filter("plugin_action_links_$plugin", 'author_product_review_settings_link' ); ?>