/** * Gets user's profile description * * @package WP Idea Stream * @subpackage users/tags * * @since 2.0.0 * * @uses wp_idea_stream_users_get_displayed_user_displayname() get displayed user display name * @uses wp_idea_stream_is_current_user_profile() to check current user is viewing his profile * @uses wp_idea_stream_users_get_displayed_user_description() to get user's descripton * @uses wp_kses_allowed_html() to get allowed tags for user's description * @uses wp_kses to sanitize user's descripton * @uses apply_filters() call 'wp_idea_stream_users_get_{$self}user_profile_description' to override output */ function wp_idea_stream_users_get_user_profile_description() { $display_name = wp_idea_stream_users_get_displayed_user_displayname(); $self = ''; $is_self_profile = wp_idea_stream_is_current_user_profile(); $user_description = sprintf(esc_html__('%s has not created his description yet', 'wp-idea-stream'), $display_name); if (!empty($is_self_profile)) { $user_description = esc_html__('Replace this text with your description, then hit the Edit button to save it.', 'wp-idea-stream'); } $description = wp_idea_stream_users_get_displayed_user_description(); if (!empty($description)) { $allowed_html = wp_kses_allowed_html('user_description'); $user_description = wp_kses($description, $allowed_html); } $output = '<div class="user-description">'; if (!empty($is_self_profile)) { $output .= '<form action="" method="post" id="wp_idea_stream_profile_form" class="user-profile-form">'; } $output .= '<blockquote>'; if (!empty($is_self_profile)) { $self = 'self_'; $output .= '<div id="wp_idea_stream_profile_description" contenteditable="true">'; } /** * Use 'wp_idea_stream_users_get_user_profile_description' to filter description when the current user * is viewing someone else profile * Use 'wp_idea_stream_users_get_self_user_profile_description' to filter description when the current user * is viewing his profile * * @param string $user_description User description */ $user_description = apply_filters("wp_idea_stream_users_get_{$self}user_profile_description", $user_description); // Add desciption to the output $output .= $user_description; if (!empty($is_self_profile)) { $output .= '</div>'; } $output .= '</blockquote>'; // Fall back is javscript's going wild if (!empty($is_self_profile)) { $output .= '<textarea name="wp_idea_stream_profile[description]">' . $user_description . '</textarea>'; $output .= wp_nonce_field('wp_idea_stream_update_description', '_wpis_nonce', true, false); $output .= '<input type="submit" name="wp_idea_stream_profile[save]" value="' . esc_attr_x('Edit', 'User profile description edit', 'wp-idea-stream') . '"/></form>'; } $output .= '</div>'; return $output; }
/** * Constructor * * @package WP Idea Stream * @subpackage comment/tags * * @since 2.0.0 * * @param array $args the loop args * @uses wp_idea_stream_ideas_per_page() to get the per page setting * @uses wp_idea_stream_is_current_user_profile() to check if on a user's profile * @uses wp_idea_stream_cpage_rewrite_id() to get the comment pagination rewrite id * @uses get_query_var() to get the value of a query var * @uses wp_parse_args() to merge custom args with default ones * @uses wp_idea_stream_get_post_type() to get the idea post type identifier * @uses wp_idea_stream_comments_count_comments() to count the comments for the user * @uses get_comments() to get the comments matching the arguments * @uses wp_list_pluck() to pluck a certain field out of each object in a list. * @uses get_posts() to get the posts corresponding to comments * @uses wp_idea_stream_set_idea_var() to globalize a value for a later use * @uses wp_idea_stream_is_pretty_links() to check if permalink structure is not default one * @uses add_query_arg() to build an url * @uses wp_idea_stream_users_get_user_comments_url() to get user's profile comment part url * @uses wp_idea_stream_users_displayed_user_id() to get the displayed user ID * @uses wp_idea_stream_users_get_displayed_user_username() to get the displayed user nicename * @uses wp_idea_stream_cpage_slug() to get the slug for the comments pagination * @uses WP_Idea_Stream_Loop::start() to build the user comments loop */ public function __construct($args = array()) { $default = array('post_status' => 'publish', 'status' => 'approve', 'user_id' => 0, 'number' => wp_idea_stream_ideas_per_page()); // All post status if user is viewing his profile if (wp_idea_stream_is_current_user_profile() || current_user_can('read_private_ideas')) { $default['post_status'] = ''; } //Merge default with requested $r = wp_parse_args($args, $default); // Set which pagination page if (get_query_var(wp_idea_stream_cpage_rewrite_id())) { $paged = get_query_var(wp_idea_stream_cpage_rewrite_id()); } else { if (!empty($_GET[wp_idea_stream_cpage_rewrite_id()])) { $paged = absint($_GET[wp_idea_stream_cpage_rewrite_id()]); } else { if (!empty($r['page'])) { $paged = absint($r['page']); // Set default page (first page) } else { $paged = 1; } } } $comments_args = array('post_type' => wp_idea_stream_get_post_type(), 'post_status' => $r['post_status'], 'status' => $r['status'], 'user_id' => (int) $r['user_id'], 'number' => (int) $r['number'], 'offset' => intval(($paged - 1) * $r['number']), 'page' => (int) $paged); if (!empty($comments_args)) { foreach ($comments_args as $key => $value) { $this->{$key} = $value; } } else { return false; } if (empty($this->user_id)) { $comment_count = 0; } else { $comment_count = wp_idea_stream_comments_count_comments($this->user_id); } // Get the comments $comments = get_comments($comments_args); if (!empty($comments)) { $post_ids = wp_list_pluck($comments, 'comment_post_ID'); // Get all posts in the object cache. $posts = get_posts(array('include' => $post_ids, 'post_type' => wp_idea_stream_get_post_type())); // Reset will need to be done at the end of the loop wp_idea_stream_set_idea_var('needs_reset', true); // Build a new post array indexed by post ID $p = array(); foreach ($posts as $post) { $p[$post->ID] = $post; } // Attach the corresponding post to each comment foreach ($comments as $key => $comment) { if (!empty($p[$comment->comment_post_ID])) { $comments[$key]->idea = $p[$comment->comment_post_ID]; } } } $params = array('plugin_prefix' => 'wp_idea_stream', 'item_name' => 'comment', 'item_name_plural' => 'comments', 'items' => $comments, 'total_item_count' => $comment_count, 'page' => $this->page, 'per_page' => $this->number); $paginate_args = array(); if (!wp_idea_stream_is_pretty_links()) { $paginate_args['base'] = add_query_arg(wp_idea_stream_cpage_rewrite_id(), '%#%'); } else { $paginate_args['base'] = trailingslashit(wp_idea_stream_users_get_displayed_profile_url('comments')) . '%_%'; $paginate_args['format'] = wp_idea_stream_cpage_slug() . '/%#%/'; } parent::start($params, apply_filters('wp_idea_stream_comments_pagination_args', $paginate_args)); }
/** * Enqueues Users description editing scripts * * @package WP Idea Stream * @subpackage users/functions * * @since 2.0.0 * * @uses wp_idea_stream_is_ideastream() to check it's plugin's territory * @uses wp_idea_stream_is_current_user_profile() to check the current user is on his profile * @uses wp_enqueue_script() to add the script to WordPress queue * @uses wp_idea_stream_get_js_script() to get a specific javascript * @uses wp_idea_stream_get_version() to get plugin's version * @uses wp_localize_script() to internatianlize data used in the script * @uses apply_filters() Calls 'wp_idea_stream_users_current_profile_script' to override/add new datas */ function wp_idea_stream_users_enqueue_scripts() { if (!wp_idea_stream_is_user_profile()) { return; } // Viewing another user's profile with no sharing dialog box doesn't need js. if (!wp_idea_stream_is_current_user_profile() && !wp_idea_stream_is_embed_profile()) { return; } $js_vars = array('is_profile' => 1); if (wp_idea_stream_is_current_user_profile()) { $js_vars['profile_editing'] = 1; } wp_enqueue_script('wp-idea-stream-script', wp_idea_stream_get_js_script('script'), array('jquery'), wp_idea_stream_get_version(), true); wp_localize_script('wp-idea-stream-script', 'wp_idea_stream_vars', apply_filters('wp_idea_stream_users_current_profile_script', $js_vars)); }