/** * Initialize the user's comments loop. * * @package WP Idea Stream * @subpackage comments/tags * * @since 2.0.0 * * @param array $args { * Arguments for customizing comments retrieved in the loop. * Arguments must be passed as an associative array * @type int 'user_id' to restrict the loop to one user (defaults to displayed user) * @type string 'status' to limit the query to comments having a certain status (defaults to approve) * @type int 'number' Number of results per page. * @type int 'page' the page of results to display. * } * @uses wp_parse_args() to merge args with defaults * @uses wp_idea_stream_users_displayed_user_id() to get the ID of the displayed user. * @uses wp_idea_stream_ideas_per_page() to get the pagination preferences * @uses WP_Idea_Stream_Loop_Comments to get the comments matching arguments * @uses wp_idea_stream() to get plugin's main instance * @uses apply_filters() call 'wp_idea_stream_comments_has_comments' to choose whether to init the loop or not * @return bool true if comments were found, false otherwise */ function wp_idea_stream_comments_has_comments($args = array()) { $r = wp_parse_args($args, array('user_id' => wp_idea_stream_users_displayed_user_id(), 'status' => 'approve', 'number' => wp_idea_stream_ideas_per_page(), 'page' => 1)); // Get the WP Idea Stream $comment_query_loop = new WP_Idea_Stream_Loop_Comments(array('user_id' => (int) $r['user_id'], 'status' => $r['status'], 'number' => (int) $r['number'], 'page' => (int) $r['page'])); // Setup the global query loop wp_idea_stream()->comment_query_loop = $comment_query_loop; return apply_filters('wp_idea_stream_comments_has_comments', $comment_query_loop->has_items(), $comment_query_loop); }
/** * Initialize the ideas loop. * * @package WP Idea Stream * @subpackage ideas/tags * * @since 2.0.0 * * @param array $args { * Arguments for customizing ideas retrieved in the loop. * Arguments must be passed as an associative array * @type int 'author' to restrict the loop to one author * @type int 'per_page' Number of results per page. * @type int 'page' the page of results to display. * @type string 'search' to limit the query to ideas containing the requested search terms * @type array|string 'exclude' Array or comma separated list of idea IDs to exclude * @type array|string 'include' Array or comma separated list of idea IDs to include * @type string 'orderby' to customize the sorting order type for the ideas (default is by date) * @type string 'order' the way results should be sorted : 'DESC' or 'ASC' (default is DESC) * @type array 'meta_query' Limit ideas regarding their post meta by passing an array of * meta_query conditions. See {@link WP_Meta_Query->queries} for a * description of the syntax. * @type array 'tax_query' Limit ideas regarding their terms by passing an array of * tax_query conditions. See {@link WP_Tax_Query->queries} for a * description of the syntax. * @type string 'idea_name' Limit results by a the post name of the idea. * @type bool 'is_widget' is the query performed inside a widget ? * } * @uses wp_parse_args() to merge args with defaults * @uses wp_idea_stream_search_rewrite_id() to get the search rewrite id * @uses wp_idea_stream_is_user_profile_ideas() to check if a user's profile is displayed * @uses wp_idea_stream_users_displayed_user_id() to get the ID of the displayed user. * @uses wp_idea_stream_ideas_per_page() to get the pagination preferences * @uses WP_Idea_Stream_Loop_Ideas to get the ideas matching arguments * @uses wp_idea_stream() to get plugin's main instance * @uses apply_filters() call 'wp_idea_stream_ideas_has_ideas' to choose whether to init the loop or not * @return bool true if ideas were found, false otherwise */ function wp_idea_stream_ideas_has_ideas($args = array()) { if (!is_array($args)) { $args = wp_parse_args($args, array()); } $template_args = array(); /** * We have arguments, so let's override the main query */ if (!empty($args)) { $search_terms = ''; if (isset($_GET[wp_idea_stream_search_rewrite_id()])) { $search_terms = stripslashes($_GET[wp_idea_stream_search_rewrite_id()]); } $r = wp_parse_args($args, array('author' => wp_idea_stream_is_user_profile_ideas() ? wp_idea_stream_users_displayed_user_id() : '', 'per_page' => wp_idea_stream_ideas_per_page(), 'page' => 1, 'search' => '', 'exclude' => '', 'include' => '', 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array(), 'tax_query' => array(), 'idea_name' => '', 'is_widget' => false)); $template_args = array('author' => (int) $r['author'], 'per_page' => (int) $r['per_page'], 'page' => (int) $r['page'], 'search' => $r['search'], 'exclude' => $r['exclude'], 'include' => $r['include'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'meta_query' => (array) $r['meta_query'], 'tax_query' => (array) $r['tax_query'], 'idea_name' => $r['idea_name'], 'is_widget' => (bool) $r['is_widget']); } // Get the ideas $query_loop = new WP_Idea_Stream_Loop_Ideas($template_args); // Setup the global query loop wp_idea_stream()->query_loop = $query_loop; /** * @param bool true if ideas were found, false otherwise * @param object $query_loop the ideas loop * @param array $template_args arguments used to build the loop * @param array $args requested arguments */ return apply_filters('wp_idea_stream_ideas_has_ideas', $query_loop->has_items(), $query_loop, $template_args, $args); }
/** * Adds oEmbed discovery links in the website <head> for the IdeaStream user's profile root page. * * @since 2.3.0 */ function wp_idea_stream_oembed_add_discovery_links() { if (!wp_idea_stream_is_user_profile_ideas() || !wp_idea_stream_is_embed_profile()) { return; } $user_link = wp_idea_stream_users_get_user_profile_url(wp_idea_stream_users_displayed_user_id(), '', true); $output = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(get_oembed_endpoint_url($user_link)) . '" />' . "\n"; if (class_exists('SimpleXMLElement')) { $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(get_oembed_endpoint_url($user_link, 'xml')) . '" />' . "\n"; } /** * Filter the oEmbed discovery links HTML. * * @since 2.3.0 * * @param string $output HTML of the discovery links. */ echo apply_filters('wp_idea_stream_users_oembed_add_discovery_links', $output); }
/** * Add the user's cover image to his embed profile * * @since 2.3.0 */ function wp_idea_stream_buddypress_embed_inline_style() { // Get displayed user id. $user_id = wp_idea_stream_users_displayed_user_id(); // If not set, we're not on a user's profile. if (empty($user_id) || bp_disable_cover_image_uploads()) { return; } $cover_image = bp_attachments_get_attachment('url', array('object_dir' => 'members', 'item_id' => $user_id)); if (!$cover_image) { return; } wp_add_inline_style('wp-idea-stream-embed-style', ' #buddypress-cover-image { display: block; background-image: url(' . $cover_image . '); background-position: center top; background-repeat: no-repeat; background-size: cover; height: 100px; position: absolute; top: 0; left: 0; width: 100%; z-index: 1; } #wp-idea-stream .profile-header { z-index: 1; position: relative; } #wp-idea-stream .wp-embed-excerpt { margin-top: 1em; } #wp-idea-stream .profile-header .wp-embed-heading a { color: #FFF; text-rendering: optimizelegibility; text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 ); height: 50px; line-height: 50px; } #wp-idea-stream .profile-header .user-avatar img.avatar { border: solid 2px #FFF; background: rgba( 255, 255, 255, 0.8 ); } '); }
/** * Displays the Sharing button inside a user's profile * * So that WordPress can build the sharing dialog and embed codes * we need to temporarly set the Utility page as the current post * for the displayed user's profile. * Then, we intercept the permalink and the title of the utility page * using filters and we override them with the ones of the displayed * user profile. Tada! * * @since 2.3.0 * * @global WP_Post $post * @return bool False in case the Embed profile is disabled */ function wp_idea_stream_users_embed_content_meta() { global $post; $reset_post = get_post(wp_idea_stream_is_embed_profile()); if (!empty($post->ID) && !empty($reset_post->ID) && (int) $post->ID === (int) $reset_post->ID || empty($reset_post->ID)) { return false; } if (!empty($reset_post->ID)) { // Globalize the post wp_idea_stream_set_idea_var('embed_reset_post', $post); // Reset it to our utility page $post = $reset_post; // Globalize the user wp_idea_stream_set_idea_var('embed_user_data', wp_idea_stream_users_get_user_data('id', wp_idea_stream_users_displayed_user_id())); // Make sure the post link will be the one of the user's displayed profile add_filter('post_type_link', 'wp_idea_stream_users_oembed_link', 10, 2); add_filter('the_title', 'wp_idea_stream_users_oembed_title', 10, 2); add_action('embed_footer', 'wp_idea_stream_users_embed_content_reset_post', 40); // Add WordPress Sharing Button print_embed_sharing_button(); } }
/** * Get the stat for the the requested type (number of ideas, comments or rates) * * @since 2.3.0 * * @param string $type the type of stat to get (eg: 'profile', 'comments', 'rates') * @param int $user_id the User ID to get the stat for */ function wp_idea_stream_users_get_stat_for($type = '', $user_id = 0) { $count = 0; if (empty($type)) { return $count; } if (empty($user_id)) { $user_id = wp_idea_stream_users_displayed_user_id(); } if (empty($user_id)) { return ${$count}; } if ('profile' === $type) { $count = count_user_posts($user_id, wp_idea_stream_get_post_type()); } elseif ('comments' === $type) { $count = wp_idea_stream_comments_count_comments($user_id); } elseif ('rates' === $type) { $count = wp_idea_stream_count_user_rates($user_id); } /** * Filter the user stats by type (number of ideas "profile", "comments" or "rates"). * * @since 2.3.0 * * @param int $count the stat for the requested type. * @param string $type "profile", "comments" or "rates". * @param int $user_id The user ID. */ return (int) apply_filters('wp_idea_stream_users_get_stat_for', $count, $type, $user_id); }