/** * 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 }
/** * Sets the available orderby possible filters * * @package WP Idea Stream * @subpackage ideas/functions * * @since 2.0.0 * * @uses wp_idea_stream_is_rating_disabled() to check if ratings are enabled * @uses apply_filters() call 'wp_idea_stream_ideas_get_order_options' to add / remove orderby filters */ function wp_idea_stream_ideas_get_order_options() { $order_options = array('date' => __('Latest', 'wp-idea-stream'), 'comment_count' => __('Most commented', 'wp-idea-stream')); // Only if not disabled. if (!wp_idea_stream_is_rating_disabled()) { $order_options['rates_count'] = __('Best rated', 'wp-idea-stream'); } /** * @param array $order_options the list of available order options */ return apply_filters('wp_idea_stream_ideas_get_order_options', $order_options); }
/** * Check the main WordPress query to match WP Idea Stream conditions * Eventually Override query vars and set global template conditions / vars * * This the key function of the plugin, it is definining the templates * to load and is setting the displayed user. * * Inspired by bbPress 's bbp_parse_query() * * @package WP Idea Stream * @subpackage core/template-functions * * @since 2.0.0 * * @param WP_Query $posts_query The WP_Query instance * @uses WP_Query->is_main_query() to check it's the main query * @uses WP_Query->get() to get a query var * @uses wp_idea_stream_is_admin() to check if in IdeaStream's Admin territory * @uses wp_idea_stream_is_sticky_enabled() to check if sticky feature is available * @uses WP_Query->set() to set a query var * @uses wp_idea_stream_is_rating_disabled() to check if ratings feature are available * @uses wp_idea_stream_set_idea_var() to globalize a var * @uses is_admin() to check for WordPress administration * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier * @uses wp_idea_stream_user_rewrite_id() to get the user rewrite id * @uses wp_idea_stream_users_get_user_data() to get a specific user's data * @uses WP_Query->set_404() to set a 404 * @uses wp_idea_stream_user_rates_rewrite_id() to get the user rates rewrite id * @uses wp_idea_stream_user_comments_rewrite_id() to get the user comments rewrite id * @uses wp_idea_stream_action_rewrite_id() to get the action rewrite id * @uses wp_idea_stream_addnew_slug() to get the add new slug * @uses wp_idea_stream_edit_slug() to get the edit slug * @uses has_action() to check if the action 'wp_idea_stream_custom_action' is used by any plugins * @uses do_action() Calls 'wp_idea_stream_custom_action' to perform actions relative to ideas * @uses wp_idea_stream_get_category() to get the ideas category identifier * @uses wp_idea_stream_get_tag() to get the ideas tag identifier * @uses wp_idea_stream_search_rewrite_id() to get the search rewrite id */ function wp_idea_stream_parse_query($posts_query = null) { // Bail if $posts_query is not the main loop if (!$posts_query->is_main_query()) { return; } // Bail if filters are suppressed on this query if (true === $posts_query->get('suppress_filters')) { return; } // Handle the specific queries in IdeaStream Admin if (wp_idea_stream_is_admin()) { // Display sticky ideas if requested if (wp_idea_stream_is_sticky_enabled() && !empty($_GET['sticky_ideas'])) { $posts_query->set('post__in', wp_idea_stream_ideas_get_stickies()); } // Build meta_query if orderby rates is set if (!wp_idea_stream_is_rating_disabled() && !empty($_GET['orderby']) && 'rates_count' == $_GET['orderby']) { $posts_query->set('meta_query', array(array('key' => '_ideastream_average_rate', 'compare' => 'EXISTS'))); // Set the orderby idea var wp_idea_stream_set_idea_var('orderby', 'rates_count'); } do_action('wp_idea_stream_admin_request', $posts_query); return; } // Bail if else where in admin if (is_admin()) { return; } // Ideas post type for a later use $idea_post_type = wp_idea_stream_get_post_type(); /** User's profile ************************************************************/ // Are we requesting the user-profile template ? $user = $posts_query->get(wp_idea_stream_user_rewrite_id()); $embed_page = wp_idea_stream_is_embed_profile(); if (!empty($user)) { if (!is_numeric($user)) { // Get user by his username $user = wp_idea_stream_users_get_user_data('slug', $user); } else { // Get user by his id $user = wp_idea_stream_users_get_user_data('id', $user); } // No user id: no profile! if (empty($user->ID) || true === apply_filters('wp_idea_stream_users_is_spammy', is_multisite() && is_user_spammy($user), $user)) { $posts_query->set_404(); // Make sure the WordPress Embed Template will be used if ('true' === get_query_var('embed') || true === get_query_var('embed')) { $posts_query->is_embed = true; $posts_query->set('p', -1); } return; } // Set the displayed user id wp_idea_stream_set_idea_var('is_user', absint($user->ID)); // Make sure the post_type is set to ideas. $posts_query->set('post_type', $idea_post_type); // Are we requesting user rates $user_rates = $posts_query->get(wp_idea_stream_user_rates_rewrite_id()); // Or user comments ? $user_comments = $posts_query->get(wp_idea_stream_user_comments_rewrite_id()); if (!empty($user_rates) && !wp_idea_stream_is_rating_disabled()) { // We are viewing user's rates wp_idea_stream_set_idea_var('is_user_rates', true); // Define the Meta Query to get his rates $posts_query->set('meta_query', array(array('key' => '_ideastream_rates', 'value' => ';i:' . $user->ID . ';', 'compare' => 'LIKE'))); } else { if (!empty($user_comments)) { // We are viewing user's comments wp_idea_stream_set_idea_var('is_user_comments', true); /** * Make sure no result. * Query will be built later in user comments loop */ $posts_query->set('p', -1); } else { if ('true' === get_query_var('embed') || true === get_query_var('embed')) { $posts_query->is_embed = true; $posts_query->set('p', -1); if ($embed_page) { wp_idea_stream_set_idea_var('is_user_embed', true); } else { $posts_query->set_404(); return; } } // Default to the ideas the user submitted $posts_query->set('author', $user->ID); } } // No stickies on user's profile $posts_query->set('ignore_sticky_posts', true); // Make sure no 404 $posts_query->is_404 = false; // Set the displayed user. wp_idea_stream_set_idea_var('displayed_user', $user); } /** Actions (New Idea) ********************************************************/ $action = $posts_query->get(wp_idea_stream_action_rewrite_id()); if (!empty($action)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define a global to inform we're dealing with an action wp_idea_stream_set_idea_var('is_action', true); // Is the new idea form requested ? if (wp_idea_stream_addnew_slug() == $action) { // Yes so set the corresponding var wp_idea_stream_set_idea_var('is_new', true); /** * Make sure no result. * We are not querying any content, but creating one */ $posts_query->set('p', -1); // Edit action ? } else { if (wp_idea_stream_edit_slug() == $action) { // Yes so set the corresponding var wp_idea_stream_set_idea_var('is_edit', true); // Signup support } else { if (wp_idea_stream_signup_slug() == $action && wp_idea_stream_is_signup_allowed_for_current_blog()) { // Set the signup global var wp_idea_stream_set_idea_var('is_signup', true); /** * Make sure no result. * We are not querying any content, but creating one */ $posts_query->set('p', -1); } else { if (has_action('wp_idea_stream_custom_action')) { /** * Allow plugins to other custom idea actions * * @param string $action The requested action * @param WP_Query $posts_query The WP_Query instance */ do_action('wp_idea_stream_custom_action', $action, $posts_query); } else { $posts_query->set_404(); return; } } } } } /** Ideas by category *********************************************************/ $category = $posts_query->get(wp_idea_stream_get_category()); if (!empty($category)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define the current category wp_idea_stream_set_idea_var('is_category', $category); } /** Ideas by tag **************************************************************/ $tag = $posts_query->get(wp_idea_stream_get_tag()); if (!empty($tag)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define the current tag wp_idea_stream_set_idea_var('is_tag', $tag); } /** Searching ideas ***********************************************************/ $search = $posts_query->get(wp_idea_stream_search_rewrite_id()); if (!empty($search)) { // Make sure the post type is set to ideas $posts_query->set('post_type', $idea_post_type); // Define the query as a search one $posts_query->set('is_search', true); /** * Temporarly set the 's' parameter of WP Query * This will be reset while building ideas main_query args * @see wp_idea_stream_set_template() */ $posts_query->set('s', $search); // Set the search conditionnal var wp_idea_stream_set_idea_var('is_search', true); } /** Changing order ************************************************************/ // Here we're using built-in var $orderby = $posts_query->get('orderby'); // Make sure we are ordering ideas if (!empty($orderby) && $idea_post_type == $posts_query->get('post_type')) { if (!wp_idea_stream_is_rating_disabled() && 'rates_count' == $orderby) { /** * It's an order by rates request, set the meta query to achieve this. * Here we're not ordering yet, we simply make sure to get ideas that * have been rated. * Order will happen thanks to wp_idea_stream_set_rates_count_orderby() * filter. */ $posts_query->set('meta_query', array(array('key' => '_ideastream_average_rate', 'compare' => 'EXISTS'))); } // Set the order by var wp_idea_stream_set_idea_var('orderby', $orderby); } // Set the idea archive var if viewing ideas archive if ($posts_query->is_post_type_archive()) { wp_idea_stream_set_idea_var('is_idea_archive', true); } /** * Finally if post_type is ideas, then we're in IdeaStream's * territory so set this */ if ($idea_post_type === $posts_query->get('post_type')) { wp_idea_stream_set_idea_var('is_ideastream', true); // Reset the pagination if (-1 !== $posts_query->get('p')) { $posts_query->set('posts_per_page', wp_idea_stream_ideas_per_page()); } } }
/** * Remove some submenus and add some custom styles * * @package WP Idea Stream * @subpackage admin/admin * * @since 2.0.0 * * @uses remove_submenu_page() to remove a page to admin menu * @uses wp_idea_stream_is_admin() to check if on an IdeaStream Administration screen * @uses wp_idea_stream_is_rating_disabled() to check if ratings are enabled * @return string CSS output */ public function admin_head() { // Remove the fake Settings submenu remove_submenu_page('options-general.php', 'ideastream'); // Remove the About & credits pages from menu remove_submenu_page('index.php', 'about-ideastream'); remove_submenu_page('index.php', 'credits-ideastream'); //Generate help if one is available for the current screen if (wp_idea_stream_is_admin() || !empty($this->is_plugin_settings)) { $screen = get_current_screen(); if (!empty($screen->id) && !$screen->get_help_tabs()) { $help_tabs_list = $this->get_help_tabs($screen->id); if (!empty($help_tabs_list)) { // Loop through tabs foreach ($help_tabs_list as $key => $help_tabs) { // Make sure types are a screen method if (!in_array($key, array('add_help_tab', 'set_help_sidebar'))) { continue; } foreach ($help_tabs as $help_tab) { $content = ''; if (empty($help_tab['content']) || !is_array($help_tab['content'])) { continue; } if (!empty($help_tab['strong'])) { $content .= '<p><strong>' . $help_tab['strong'] . '</strong></p>'; } foreach ($help_tab['content'] as $tab_content) { if (is_array($tab_content)) { $content .= '<ul><li>' . join('</li><li>', $tab_content) . '</li></ul>'; } else { $content .= '<p>' . $tab_content . '</p>'; } } $help_tab['content'] = $content; if ('add_help_tab' == $key) { $screen->add_help_tab($help_tab); } else { $screen->set_help_sidebar($content); } } } } } } // Add some css ?> <style type="text/css" media="screen"> /*<![CDATA[*/ /* Bubble style for Main Post type menu */ #adminmenu .wp-menu-open.menu-icon-<?php echo $this->post_type; ?> .awaiting-mod { background-color: #2ea2cc; color: #fff; } .about-wrap .wp-idea-stream-badge { font: normal 150px/1 'dashicons' !important; /* Better Font Rendering =========== */ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; color: #000; display: inline-block; content:''; } .wp-idea-stream-badge:before{ content: "\f339"; } .about-wrap .wp-idea-stream-badge { position: absolute; top: 0; right: 0; } body.rtl .about-wrap .wp-idea-stream-badge { right: auto; left: 0; } .ideastream-credits { position:relative; float:left; margin-right:15px; } .ideastream-credits img.gravatar { width:150px; height:150px; } .dashboard_page_credits-ideastream .changelog { clear:both; overflow: hidden; } #wp-idea-stream-csv span.dashicons-media-spreadsheet { vertical-align: text-bottom; } <?php if (wp_idea_stream_is_admin() && !wp_idea_stream_is_rating_disabled()) { ?> /* Rating stars in screen options and in ideas WP List Table */ .metabox-prefs .idea-rating-bubble:before, th .idea-rating-bubble:before, .metabox-prefs .idea-group-bubble:before, th .idea-group-bubble:before { font: normal 20px/.5 'dashicons'; speak: none; display: inline-block; padding: 0; top: 4px; left: -4px; position: relative; vertical-align: top; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-decoration: none !important; color: #444; } th .idea-rating-bubble:before, .metabox-prefs .idea-rating-bubble:before { content: '\f155'; } .metabox-prefs .idea-group-bubble:before, th .idea-group-bubble:before { content: '\f307'; } .metabox-prefs .idea-rating-bubble:before, .metabox-prefs .idea-group-bubble:before { vertical-align: baseline; } /* Rates management */ #wp_idea_stream_ratings_box ul.admin-idea-rates { width: 100%; list-style: none; clear: both; margin: 0; padding: 0; } #wp_idea_stream_ratings_box ul.admin-idea-rates li { list-style: none; overflow: hidden; position: relative; padding:15px 0; border-bottom:dotted 1px #ccc; } #wp_idea_stream_ratings_box ul.admin-idea-rates li:last-child { border:none; } #wp_idea_stream_ratings_box ul.admin-idea-rates li div.admin-idea-rates-star { float:left; } #wp_idea_stream_ratings_box ul.admin-idea-rates li div.admin-idea-rates-star { width:20%; font-weight: bold; } #wp_idea_stream_ratings_box ul.admin-idea-rates li div.admin-idea-rates-users { margin-left: 20%; } #wp_idea_stream_ratings_box ul.admin-idea-rates li div.admin-idea-rates-users span.user-rated { display:inline-block; margin:5px; padding:5px; -webkit-box-shadow: 0 1px 1px 1px rgba(0,0,0,0.1); box-shadow: 0 1px 1px 1px rgba(0,0,0,0.1); } #wp_idea_stream_ratings_box ul.admin-idea-rates li div.admin-idea-rates-users a.del-rate { text-decoration: none; } #wp_idea_stream_ratings_box ul.admin-idea-rates li div.admin-idea-rates-users a.del-rate div { vertical-align: baseline; } <?php } ?> /*]]>*/ </style> <?php }
/** * Hooks to deleted_user to perform additional actions * * When a user is deleted, we need to be sure the ideas he shared are also * deleted to avoid troubles in edit screens as the post author field will found * no user. I also remove rates. * * The main problem here (excepting error notices) is ownership of the idea. To avoid any * troubles, deleting when user leaves seems to be the safest. If you have a different point * of view, you can remove_action( 'deleted_user', 'wp_idea_stream_users_delete_user_data', 10, 1 ) * and use a different way of managing this. I advise you to make sure ideas are reattributed to * an existing user ID. About rates, there's no problem if a non existing user ID is in the rating * list of an idea. * * @package WP Idea Stream * @subpackage users/functions * * @since 2.0.0 * * @uses add_filter() to temporarly include all post status * @uses wp_idea_stream_ideas_get_ideas() to get all user's ideas and rates * @uses remove_filter() to remove the filter * @uses apply_filters() Calls 'wp_idea_stream_users_delete_user_force_delete' to override * @uses do_action() Calls 'wp_idea_stream_users_before_trash_user_data' to perform actions before idea is trashed * Calls 'wp_idea_stream_users_before_delete_user_data' to perform actions before idea is deleted * @uses wp_delete_post() to peramanently delete (forces flag on) these ideas * @uses wp_idea_stream_is_rating_disabled() to check if rating functionality is available * @uses wp_idea_stream_delete_rate() to delete user's rates * @uses do_action() Calls 'wp_idea_stream_delete_user_rates' to perform actions once user is deleted */ function wp_idea_stream_users_delete_user_data($user_id = 0) { if (empty($user_id)) { return; } // Make sure we don't miss any ideas add_filter('wp_idea_stream_ideas_get_status', 'wp_idea_stream_ideas_get_all_status', 10, 1); // Get user's ideas, in case of multisite $user_ideas = wp_idea_stream_ideas_get_ideas(array('per_page' => -1, 'author' => $user_id)); // remove asap remove_filter('wp_idea_stream_ideas_get_status', 'wp_idea_stream_ideas_get_all_status', 10, 1); /** * We're forcing ideas to be deleted definitively * Using this filter you can set it to only be trashed * * Internally use in case user has been spammed (BuddyPress functionnality) * @see buddypress/functions * * @param bool $force_delete true to permanently delete, false to trash */ $force_delete = apply_filters('wp_idea_stream_users_delete_user_force_delete', true); // If any delete them if (!empty($user_ideas['ideas'])) { foreach ($user_ideas['ideas'] as $user_idea) { /** * WordPress is using a check on native post types * so we can't just pass $force_delete to wp_delete_post(). */ if (empty($force_delete)) { /** * @param int ID of the idea being trashed * @param int $user_id the user id */ do_action('wp_idea_stream_users_before_trash_user_data', $user_idea->ID, $user_id); wp_trash_post($user_idea->ID); } else { /** * @param int ID of the idea being trashed * @param int $user_id the user id */ do_action('wp_idea_stream_users_before_delete_user_data', $user_idea->ID, $user_id); wp_delete_post($user_idea->ID, true); } } } // Ratings are on, try to delete them. if (!wp_idea_stream_is_rating_disabled()) { // Make sure we don't miss any ideas add_filter('wp_idea_stream_ideas_get_status', 'wp_idea_stream_ideas_get_all_status', 10, 1); // Get user's rates $rated_ideas = wp_idea_stream_ideas_get_ideas(array('per_page' => -1, 'meta_query' => array(array('key' => '_ideastream_rates', 'value' => ';i:' . $user_id . ';', 'compare' => 'LIKE')))); // remove asap remove_filter('wp_idea_stream_ideas_get_status', 'wp_idea_stream_ideas_get_all_status', 10, 1); // If any delete them. if (!empty($rated_ideas['ideas'])) { foreach ($rated_ideas['ideas'] as $idea) { wp_idea_stream_delete_rate($idea->ID, $user_id); } /** * Internally used in BuddyPress part of the plugin to delete notifications * generated by the deleted user. * @see buddypress/notifications part * * @param int $user_id the user ID */ do_action('wp_idea_stream_delete_user_rates', $user_id); } } /** * @param int $user_id the user ID */ do_action('wp_idea_stream_users_deleted_user_data', $user_id); }
/** * Fire the 'wp_idea_stream_enqueue_embed_scripts' action. * But do it only if needed * * Used to register and enqueue custom scripts for the WordPress * & IdeaStream embed templates * * @since 2.3.0 */ function wp_idea_stream_enqueue_embed_scripts() { // Bail if not an idea or not an embed profile if (wp_idea_stream_get_post_type() === get_query_var('post_type') && !wp_idea_stream_is_rating_disabled() || wp_idea_stream_get_idea_var('is_user_embed') && wp_idea_stream_is_embed_profile()) { do_action('wp_idea_stream_enqueue_embed_scripts'); } }