/** * Filters the_content() * * @param $content * @return filtered content */ function mr_filter_the_content($content) { // get the post id global $post; $post_id = null; if (!isset($post_id) && isset($post)) { $post_id = $post->ID; } else { if (!isset($post) && !isset($post_id)) { return $content; // No post id available to display rating form } } $can_apply_filter = !(!in_the_loop() || is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)); if (!apply_filters('mr_can_apply_filter', $can_apply_filter, 'the_content', $content, $post_id)) { return $content; } $position_settings = (array) get_option(Multi_Rating::POSITION_SETTINGS); $rating_form_html = null; $rating_results_html = null; $rating_form_position = get_post_meta($post->ID, Multi_Rating::RATING_FORM_POSITION_POST_META, true); $rating_results_position = get_post_meta($post->ID, Multi_Rating::RATING_RESULTS_POSITION_POST_META, true); if ($rating_form_position != Multi_Rating::DO_NOT_SHOW) { // use default rating form position if ($rating_form_position == '') { $rating_form_position = $position_settings[Multi_Rating::RATING_FORM_POSITION_OPTION]; } if ($rating_form_position == 'before_content' || $rating_form_position == 'after_content') { $rating_form_html = Multi_Rating_API::display_rating_form(array('post_id' => $post_id, 'echo' => false, 'class' => $rating_form_position . ' mr-filter')); } } if ($rating_results_position != Multi_Rating::DO_NOT_SHOW) { // use default rating results position if ($rating_results_position == '') { $rating_results_position = $position_settings[Multi_Rating::RATING_RESULTS_POSITION_OPTION]; } if ($rating_results_position == 'before_content' || $rating_results_position == 'after_content') { $rating_results_html = Multi_Rating_API::display_rating_result(array('post_id' => $post_id, 'echo' => false, 'show_date' => false, 'show_rich_snippets' => true, 'class' => $rating_results_position . ' mr-filter')); } } $filtered_content = ''; if ($rating_results_position == 'before_content' && $rating_results_html != null) { $filtered_content .= $rating_results_html; } if ($rating_form_position == 'before_content' && $rating_form_html != null) { $filtered_content .= $rating_form_html; } $filtered_content .= $content; if ($rating_results_position == 'after_content' && $rating_results_html != null) { $filtered_content .= $rating_results_html; } if ($rating_form_position == 'after_content' && $rating_form_html != null) { $filtered_content .= $rating_form_html; } do_action('mr_after_auto_placement', 'the_content', $post_id); return $filtered_content; }
/** * Shortcode to display the rating form */ function mr_rating_form($atts = array(), $content = null, $tag) { $can_do_shortcode = !(is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)); if (!apply_filters('mr_can_do_shortcode', $can_do_shortcode, 'mr_rating_form', $atts)) { return; } // get the post id global $post; $post_id = null; if (isset($post)) { $post_id = $post->ID; } $custom_text_settings = (array) get_option(Multi_Rating::CUSTOM_TEXT_SETTINGS); extract(shortcode_atts(array('post_id' => $post_id, 'title' => $custom_text_settings[Multi_Rating::RATING_FORM_TITLE_TEXT_OPTION], 'before_title' => '<h4>', 'after_title' => '</h4>', 'submit_button_text' => $custom_text_settings[Multi_Rating::SUBMIT_RATING_FORM_BUTTON_TEXT_OPTION], 'class' => ''), $atts)); if ($post_id == null) { return; // No post Id available } return Multi_Rating_API::display_rating_form(array('post_id' => $post_id, 'title' => $title, 'before_title' => $before_title, 'after_title' => $after_title, 'submit_button_text' => $submit_button_text, 'echo' => false, 'class' => $class . ' mr-shortcode')); }
/** * (non-PHPdoc) * @see WP_Widget::widget() */ function widget($args, $instance) { // https://codex.wordpress.org/Function_Reference/url_to_postid // FIXME may not work with attachments. See here: https://pippinsplugins.com/retrieve-attachment-id-from-image-url/ $post_id = url_to_postid(MR_Utils::get_current_url()); if ($post_id == 0 || $post_id == null) { return; // Nothing to do. } if (!apply_filters('mr_can_apply_widget', true, $post_id, $args, $instance)) { return; // do nothing } extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $header = empty($instance['header']) ? 'h3' : $instance['header']; $before_title = '<' . $header . ' class="widget-title">'; $after_title = '</' . $header . '>'; $title = apply_filters('widget_title', $title); echo $before_widget; Multi_Rating_API::display_rating_form(array('class' => 'mr-widget', 'before_title' => $before_title, 'after_title' => $after_title, 'title' => $title, 'post_id' => $post_id)); echo $after_widget; }