'.$excerpt.'
*/ class WP_Post_Comment_Rating_Public { /** * The ID of this plugin. * * @since 2.4 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 2.4 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 2.4 * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. * * @since 2.4 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-post-comment-rating-public.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 2.4 */ public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wp-post-comment-rating-public.js', array( 'jquery' ), $this->version, false ); } //--------------------------------------------------- // SHORTCODES //--------------------------------------------------- // register shortcodes public function wpcr_register_shortcodes($atts) { // average rating add_shortcode( 'wppr_avg_rating', array( $this, 'wpcr_avg_rating' ) ); // average rating by post ID add_shortcode( 'wppr_avg_rating_post_id', array( $this, 'wpcr_avg_rating_post_id' ) ); } /* AVERAGE RATING SHORTCODE */ public function wpcr_avg_rating($atts ) { $a = shortcode_atts( array( 'title' => 'Rating', ), $atts ); global $post; $args = array('post_id' => $post->ID); $comments = get_comments($args); //var_dump($comments); $sum = 0; $count=0; foreach($comments as $comment) : $approvedComment = $comment->comment_approved; if($approvedComment > 0){ $rates = get_comment_meta( $comment->comment_ID, 'rating', true ); } if($rates){ $sum = $sum + (int)$rates; $count++; } endforeach; if($count != 0){ $result= $sum/$count; }else { $result= 0; } $chkresults = get_option('wpcr_settings'); $check_val = isset($chkresults['checkbox2']) ? $chkresults['checkbox2'] : false; $tooltip_inline = isset($chkresults['tooltip_inline']) ? $chkresults['tooltip_inline'] : false; $avgrating_text = isset($chkresults['wpcravg_text']) ? $chkresults['wpcravg_text'] : false; if($avgrating_text == ''){ $avg_text = __( 'Average', 'wp-post-comment-rating' ); }else{ $avg_text = $avgrating_text; } $avgText = __('average', 'wp-post-comment-rating'); $outOf = __('out of 5. Total', 'wp-post-comment-rating'); if($count > 0){ if($tooltip_inline == 1){ $output = '
'; } if($tooltip_inline == 0){ $output = '