/** * Output the Idea Ratings if needed into the Embedded idea * * @since 2.3.0 * * @return string HTML output */ function wp_idea_stream_ideas_embed_meta() { $idea = get_post(); if (!isset($idea->post_type) || wp_idea_stream_get_post_type() !== $idea->post_type || wp_idea_stream_is_rating_disabled()) { return; } // Get the Average Rate $average_rate = wp_idea_stream_ideas_get_average_rating($idea->ID); if (!$average_rate) { return; } // Get rating link $rating_link = wp_idea_stream_ideas_get_idea_permalink($idea) . '#rate'; ?> <div class="wp-idea-stream-embed-ratings"> <a href="<?php echo esc_url($rating_link); ?> " target="_top"> <span class="dashicons ideastream-star-filled"></span> <?php printf(esc_html__('%1$sAverage Rating:%2$s%3$s', 'wp-idea-stream'), '<span class="screen-reader-text">', '</span>', $average_rate); ?> </a> </div> <?php }
/** * Fills the custom columns datarows * * @package WP Idea Stream * @subpackage admin/admin * * @since 2.0.0 * * @param string $column_name the column name * @param int $idea_id the ID of the idea (row) * @uses wp_idea_stream_ideas_get_average_rating() to get the idea average rate * @uses wp_idea_stream_get_category() to get the ideas category taxonomy identifier * @uses wp_idea_stream_get_tag() to get the ideas tag taxonomy identifier * @uses get_taxonomy() to get the taxonomy object * @uses wp_get_object_terms() to get the terms the idea is associated with * @uses esc_html() to sanitize output * @uses esc_url() to sanitize url * @uses sanitize_term_field() to cleanse the field value in the term based on the context * @uses do_action() call 'wp_idea_stream_admin_column_data' to perform custom actions in case of custom columns * @return string HTML output */ public function column_data($column_name = '', $idea_id = 0) { switch ($column_name) { case 'rates': $rate = wp_idea_stream_ideas_get_average_rating($idea_id); if (!empty($rate)) { echo $rate; } else { echo '—'; } break; case 'cat_ideas': case 'tag_ideas': if ('cat_ideas' == $column_name) { $taxonomy = wp_idea_stream_get_category(); } elseif ('tag_ideas' == $column_name) { $taxonomy = wp_idea_stream_get_tag(); } else { $taxonomy = false; } if (empty($taxonomy)) { return; } $taxonomy_object = get_taxonomy($taxonomy); $terms = wp_get_object_terms($idea_id, $taxonomy, array('fields' => 'all')); if (empty($terms)) { echo '—'; return; } $output = array(); foreach ($terms as $term) { $query_vars = array('post_type' => $this->post_type, $taxonomy_object->query_var => $term->slug); $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg($query_vars, 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, $taxonomy, 'display'))); } echo join(__(', '), $out); break; default: /** * @param string $column_name the column name * @param int $idea_id the ID of the idea (row) */ do_action('wp_idea_stream_admin_column_data', $column_name, $idea_id); break; } }