/**
         * Render the xprofile metabox for Community Profile screen.
         *
         * @since 2.0.0
         *
         * @param WP_User|null $user The WP_User object for the user being edited.
         * @param array        $args Aray of arguments for metaboxes.
         */
        public function user_admin_profile_metaboxes($user = null, $args = array())
        {
            // Bail if no user ID.
            if (empty($user->ID)) {
                return;
            }
            $r = bp_parse_args($args['args'], array('profile_group_id' => 0, 'user_id' => $user->ID), 'bp_xprofile_user_admin_profile_loop_args');
            // We really need these args.
            if (empty($r['profile_group_id']) || empty($r['user_id'])) {
                return;
            }
            // Bail if no profile fields are available.
            if (!bp_has_profile($r)) {
                return;
            }
            // Loop through profile groups & fields.
            while (bp_profile_groups()) {
                bp_the_profile_group();
                ?>

			<input type="hidden" name="field_ids[]" id="<?php 
                echo esc_attr('field_ids_' . bp_get_the_profile_group_slug());
                ?>
" value="<?php 
                echo esc_attr(bp_get_the_profile_group_field_ids());
                ?>
" />

			<?php 
                if (bp_get_the_profile_group_description()) {
                    ?>

				<p class="description"><?php 
                    bp_the_profile_group_description();
                    ?>
</p>

			<?php 
                }
                ?>

			<?php 
                while (bp_profile_fields()) {
                    bp_the_profile_field();
                    ?>

				<div<?php 
                    bp_field_css_class('bp-profile-field');
                    ?>
>

					<?php 
                    $field_type = bp_xprofile_create_field_type(bp_get_the_profile_field_type());
                    $field_type->edit_field_html(array('user_id' => $r['user_id']));
                    if (bp_get_the_profile_field_description()) {
                        ?>

						<p class="description"><?php 
                        bp_the_profile_field_description();
                        ?>
</p>

					<?php 
                    }
                    /**
                     * Fires before display of visibility form elements for profile metaboxes.
                     *
                     * @since 1.7.0
                     */
                    do_action('bp_custom_profile_edit_fields_pre_visibility');
                    $can_change_visibility = bp_current_user_can('bp_xprofile_change_field_visibility');
                    ?>

					<p class="field-visibility-settings-<?php 
                    echo $can_change_visibility ? 'toggle' : 'notoggle';
                    ?>
" id="field-visibility-settings-toggle-<?php 
                    bp_the_profile_field_id();
                    ?>
">

						<?php 
                    printf(__('This field can be seen by: %s', 'buddypress'), '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>');
                    ?>

						<?php 
                    if ($can_change_visibility) {
                        ?>

							<a href="#" class="button visibility-toggle-link"><?php 
                        esc_html_e('Change', 'buddypress');
                        ?>
</a>

						<?php 
                    }
                    ?>
					</p>

					<?php 
                    if ($can_change_visibility) {
                        ?>

						<div class="field-visibility-settings" id="field-visibility-settings-<?php 
                        bp_the_profile_field_id();
                        ?>
">
							<fieldset>
								<legend><?php 
                        _e('Who can see this field?', 'buddypress');
                        ?>
</legend>

								<?php 
                        bp_profile_visibility_radio_buttons();
                        ?>

							</fieldset>
							<a class="button field-visibility-settings-close" href="#"><?php 
                        esc_html_e('Close', 'buddypress');
                        ?>
</a>
						</div>

					<?php 
                    }
                    ?>

					<?php 
                    /**
                     * Fires at end of custom profile field items on your xprofile screen tab.
                     *
                     * @since 1.1.0
                     */
                    do_action('bp_custom_profile_edit_fields');
                    ?>

				</div>

			<?php 
                }
                // End bp_profile_fields().
                ?>

		<?php 
            }
            // End bp_profile_groups.
        }
/**
 * Returns the available members
 *
 * @package Rendez Vous
 * @subpackage Ajax
 *
 * @since Rendez Vous (1.0.0)
 */
function rendez_vous_ajax_get_users()
{
    check_ajax_referer('rendez-vous-editor');
    $query_args = isset($_REQUEST['query']) ? (array) $_REQUEST['query'] : array();
    $args = bp_parse_args($query_args, array('user_id' => false, 'type' => 'alphabetical', 'per_page' => 20, 'page' => 1, 'search_terms' => false, 'member_type' => false, 'exclude' => array(bp_loggedin_user_id())), 'rendez_vous_get_users');
    if (!empty($args['group_id'])) {
        // Get all type of group users
        $args['group_role'] = array('admin', 'mod', 'member');
        $query = new BP_Group_Member_Query($args);
    } else {
        $query = new BP_User_Query($args);
    }
    $response = new stdClass();
    $response->meta = array('total_page' => 0, 'current_page' => 0);
    if (empty($query->results)) {
        wp_send_json_error($response);
    }
    $users = array_map('rendez_vous_prepare_user_for_js', array_values($query->results));
    $users = array_filter($users);
    if (!empty($args['per_page'])) {
        $response->meta = array('total_page' => ceil((int) $query->total_users / (int) $args['per_page']), 'current_page' => (int) $args['page']);
    }
    $response->items = $users;
    wp_send_json_success($response);
}
/**
 * Retrieve a set of blogs
 *
 * @see BP_Blogs_Blog::get() for a description of arguments and return value.
 *
 * @param array $args {
 *     Arguments are listed here with their default values. For more
 *     information about the arguments, see {@link BP_Blogs_Blog::get()}.
 *     @type string $type Default: 'active'.
 *     @type int|bool $user_id Default: false.
 *     @type array $include_blog_ids Default: false.
 *     @type string|bool $search_terms Default: false.
 *     @type int $per_page Default: 20.
 *     @type int $page Default: 1.
 *     @type bool $update_meta_cache Whether to pre-fetch blogmeta. Default: true.
 * }
 * @return array See {@link BP_Blogs_Blog::get()}.
 */
function bp_blogs_get_blogs($args = '')
{
    // Parse query arguments
    $r = bp_parse_args($args, array('type' => 'active', 'include_blog_ids' => false, 'user_id' => false, 'search_terms' => false, 'per_page' => 20, 'page' => 1, 'update_meta_cache' => true), 'blogs_get_blogs');
    // Get the blogs
    $blogs = BP_Blogs_Blog::get($r['type'], $r['per_page'], $r['page'], $r['user_id'], $r['search_terms'], $r['update_meta_cache'], $r['include_blog_ids']);
    // Filter and return
    return apply_filters('bp_blogs_get_blogs', $blogs, $r);
}
/**
 * Insert a new profile field group
 *
 * @since BuddyPress (1.0.0)
 *
 * @param type $args
 * @return boolean
 */
function xprofile_insert_field_group($args = '')
{
    // Parse the arguments
    $r = bp_parse_args($args, array('field_group_id' => false, 'name' => false, 'description' => '', 'can_delete' => true), 'xprofile_insert_field_group');
    // Bail if no group name
    if (empty($r['name'])) {
        return false;
    }
    // Create new field group object, maybe using an existing ID
    $field_group = new BP_XProfile_Group($r['field_group_id']);
    $field_group->name = $r['name'];
    $field_group->description = $r['description'];
    $field_group->can_delete = $r['can_delete'];
    return $field_group->save();
}
Example #5
0
/**
 * Initialize the deposits loop.
 *
 * @param array $args
 *
 * @return bool Returns true when deposits are found, otherwise false.
 */
function humcore_has_deposits($args = '')
{
    global $deposits_results;
    // Note: any params used for filtering can be a single value, or multiple values comma separated.
    $defaults = array('page_arg' => 'dpage', 'sort' => 'date', 'page' => 1, 'per_page' => 25, 'max' => false, 'include' => false, 'search_tag' => false, 'search_terms' => false, 'search_facets' => false);
    $params = bp_parse_args($args, $defaults, 'has_deposits');
    if (empty($params['search_tag']) && !empty($params['tag'])) {
        $params['search_tag'] = $params['tag'];
    }
    if (empty($params['search_tag']) && !empty($_REQUEST['tag'])) {
        $params['search_tag'] = $_REQUEST['tag'];
    }
    if (empty($params['search_terms']) && !empty($params['s'])) {
        $params['search_terms'] = $params['s'];
    }
    if (empty($params['search_terms']) && !empty($_REQUEST['s'])) {
        $params['search_terms'] = $_REQUEST['s'];
    }
    // TODO figure out how to remove this hack (copy date_issued to text in solr?).
    $params['search_terms'] = preg_replace('/^(\\d{4})$/', 'date_issued:$1', $params['search_terms']);
    if (empty($params['search_facets']) && !empty($params['facets'])) {
        $params['search_facets'] = $params['facets'];
    }
    if (empty($params['search_facets']) && !empty($_REQUEST['facets'])) {
        $params['search_facets'] = $_REQUEST['facets'];
    }
    if (!empty($_REQUEST['sort'])) {
        $params['sort'] = esc_attr($_REQUEST['sort']);
    }
    // Do not exceed the maximum per page.
    if (!empty($params['max']) && (int) $params['per_page'] > (int) $params['max']) {
        $params['per_page'] = $params['max'];
    }
    $search_args = array('page' => $params['page'], 'per_page' => $params['per_page'], 'page_arg' => $params['page_arg'], 'max' => $params['max'], 'sort' => $params['sort'], 'include' => $params['include'], 'search_tag' => $params['search_tag'], 'search_terms' => $params['search_terms'], 'search_facets' => $params['search_facets']);
    $deposits_results = new Humcore_Deposit_Search_Results($search_args);
    return apply_filters('humcore_has_deposits', $deposits_results->has_deposits(), $deposits_results, $search_args);
}
/**
 * Add a notification for a specific user, from a specific component.
 *
 * @since 1.9.0
 *
 * @param array $args {
 *     Array of arguments describing the notification. All are optional.
 *     @type int    $user_id           ID of the user to associate the notification with.
 *     @type int    $item_id           ID of the item to associate the notification with.
 *     @type int    $secondary_item_id ID of the secondary item to associate the
 *                                     notification with.
 *     @type string $component_name    Name of the component to associate the
 *                                     notification with.
 *     @type string $component_action  Name of the action to associate the
 *                                     notification with.
 *     @type string $date_notified     Timestamp for the notification.
 * }
 * @return int|bool ID of the newly created notification on success, false
 *         on failure.
 */
function bp_notifications_add_notification($args = array())
{
    $r = bp_parse_args($args, array('user_id' => 0, 'item_id' => 0, 'secondary_item_id' => 0, 'component_name' => '', 'component_action' => '', 'date_notified' => bp_core_current_time(), 'is_new' => 1, 'allow_duplicate' => false), 'notifications_add_notification');
    // Check for existing duplicate notifications
    if (!$r['allow_duplicate']) {
        // date_notified, allow_duplicate don't count toward
        // duplicate status
        $existing = BP_Notifications_Notification::get(array('user_id' => $r['user_id'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'component_name' => $r['component_name'], 'component_action' => $r['component_action'], 'is_new' => $r['is_new']));
        if (!empty($existing)) {
            return false;
        }
    }
    // Setup the new notification
    $notification = new BP_Notifications_Notification();
    $notification->user_id = $r['user_id'];
    $notification->item_id = $r['item_id'];
    $notification->secondary_item_id = $r['secondary_item_id'];
    $notification->component_name = $r['component_name'];
    $notification->component_action = $r['component_action'];
    $notification->date_notified = $r['date_notified'];
    $notification->is_new = $r['is_new'];
    // Save the new notification
    return $notification->save();
}
/**
 * Ajax Upload and set a cover image
 *
 * @since  2.4.0
 *
 * @return  string|null A json object containing success data if the upload succeeded
 *                      error message otherwise.
 */
function bp_attachments_cover_image_ajax_upload()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        wp_die();
    }
    /**
     * Sending the json response will be different if
     * the current Plupload runtime is html4
     */
    $is_html4 = false;
    if (!empty($_POST['html4'])) {
        $is_html4 = true;
    }
    // Check the nonce
    check_admin_referer('bp-uploader');
    // Init the BuddyPress parameters
    $bp_params = array();
    // We need it to carry on
    if (!empty($_POST['bp_params'])) {
        $bp_params = bp_parse_args($_POST['bp_params'], array('object' => 'user', 'item_id' => bp_loggedin_user_id()), 'attachments_cover_image_ajax_upload');
    } else {
        bp_attachments_json_response(false, $is_html4);
    }
    // We need the object to set the uploads dir filter
    if (empty($bp_params['object'])) {
        bp_attachments_json_response(false, $is_html4);
    }
    // Capability check
    if (!bp_attachments_current_user_can('edit_cover_image', $bp_params)) {
        bp_attachments_json_response(false, $is_html4);
    }
    $bp = buddypress();
    $needs_reset = array();
    // Member's cover image
    if ('user' === $bp_params['object']) {
        $object_data = array('dir' => 'members', 'component' => 'xprofile');
        if (!bp_displayed_user_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('key' => 'displayed_user', 'value' => $bp->displayed_user);
            $bp->displayed_user->id = $bp_params['item_id'];
        }
        // Group's cover image
    } elseif ('group' === $bp_params['object']) {
        $object_data = array('dir' => 'groups', 'component' => 'groups');
        if (!bp_get_current_group_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group);
            $bp->groups->current_group = groups_get_group(array('group_id' => $bp_params['item_id'], 'populate_extras' => false));
        }
        // Other object's cover image
    } else {
        $object_data = apply_filters('bp_attachments_cover_image_object_dir', array(), $bp_params['object']);
    }
    // Stop here in case of a missing parameter for the object
    if (empty($object_data['dir']) || empty($object_data['component'])) {
        bp_attachments_json_response(false, $is_html4);
    }
    $cover_image_attachment = new BP_Attachment_Cover_Image();
    $uploaded = $cover_image_attachment->upload($_FILES);
    // Reset objects
    if (!empty($needs_reset)) {
        if (!empty($needs_reset['component'])) {
            $bp->{$needs_reset['component']}->{$needs_reset['key']} = $needs_reset['value'];
        } else {
            $bp->{$needs_reset['key']} = $needs_reset['value'];
        }
    }
    if (!empty($uploaded['error'])) {
        // Upload error response
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $uploaded['error'])));
    }
    // Default error message
    $error_message = __('There was a problem uploading the cover image.', 'buddypress');
    // Get BuddyPress Attachments Uploads Dir datas
    $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
    // The BP Attachments Uploads Dir is not set, stop.
    if (!$bp_attachments_uploads_dir) {
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $error_message));
    }
    $cover_subdir = $object_data['dir'] . '/' . $bp_params['item_id'] . '/cover-image';
    $cover_dir = trailingslashit($bp_attachments_uploads_dir['basedir']) . $cover_subdir;
    if (!is_dir($cover_dir)) {
        // Upload error response
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $error_message));
    }
    /**
     * Generate the cover image so that it fit to feature's dimensions
     *
     * Unlike the Avatar, Uploading and generating the cover image is happening during
     * the same Ajax request, as we already instantiated the BP_Attachment_Cover_Image
     * class, let's use it.
     */
    $cover = bp_attachments_cover_image_generate_file(array('file' => $uploaded['file'], 'component' => $object_data['component'], 'cover_image_dir' => $cover_dir), $cover_image_attachment);
    if (!$cover) {
        // Upload error response
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $error_message));
    }
    // Build the url to the file
    $cover_url = trailingslashit($bp_attachments_uploads_dir['baseurl']) . $cover_subdir . '/' . $cover['cover_basename'];
    // Init Feedback code, 1 is success
    $feedback_code = 1;
    // 0 is the size warning
    if ($cover['is_too_small']) {
        $feedback_code = 0;
    }
    // Set the name of the file
    $name = $_FILES['file']['name'];
    $name_parts = pathinfo($name);
    $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
    /**
     * Fires if the new cover image was successfully uploaded.
     *
     * The dynamic portion of the hook will be xprofile in case of a user's
     * cover image, groups in case of a group's cover image. For instance:
     * Use add_action( 'xprofile_cover_image_uploaded' ) to run your specific
     * code once the user has set his cover image.
     *
     * @since 2.4.0
     *
     * @param int $item_id Inform about the item id the cover image was set for.
     */
    do_action($object_data['component'] . '_cover_image_uploaded', (int) $bp_params['item_id']);
    // Finally return the cover image url to the UI
    bp_attachments_json_response(true, $is_html4, array('name' => $name, 'url' => $cover_url, 'feedback_code' => $feedback_code));
}
/**
 * Register a member type.
 *
 * @since 2.2.0
 *
 * @param string $member_type Unique string identifier for the member type.
 * @param array  $args {
 *     Array of arguments describing the member type.
 *
 *     @type array       $labels {
 *         Array of labels to use in various parts of the interface.
 *
 *         @type string $name          Default name. Should typically be plural.
 *         @type string $singular_name Singular name.
 *     }
 *     @type bool|string $has_directory Whether the member type should have its own type-specific directory.
 *                                      Pass `true` to use the `$member_type` string as the type's slug.
 *                                      Pass a string to customize the slug. Pass `false` to disable.
 *                                      Default: true.
 * }
 * @return object|WP_Error Member type object on success, WP_Error object on failure.
 */
function bp_register_member_type($member_type, $args = array())
{
    $bp = buddypress();
    if (isset($bp->members->types[$member_type])) {
        return new WP_Error('bp_member_type_exists', __('Member type already exists.', 'buddypress'), $member_type);
    }
    $r = bp_parse_args($args, array('labels' => array(), 'has_directory' => true), 'register_member_type');
    $member_type = sanitize_key($member_type);
    /**
     * Filters the list of illegal member type names.
     *
     * - 'any' is a special pseudo-type, representing items unassociated with any member type.
     * - 'null' is a special pseudo-type, representing users without any type.
     * - '_none' is used internally to denote an item that should not apply to any member types.
     *
     * @since 2.4.0
     *
     * @param array $illegal_names Array of illegal names.
     */
    $illegal_names = apply_filters('bp_member_type_illegal_names', array('any', 'null', '_none'));
    if (in_array($member_type, $illegal_names, true)) {
        return new WP_Error('bp_member_type_illegal_name', __('You may not register a member type with this name.', 'buddypress'), $member_type);
    }
    // Store the post type name as data in the object (not just as the array key).
    $r['name'] = $member_type;
    // Make sure the relevant labels have been filled in.
    $default_name = isset($r['labels']['name']) ? $r['labels']['name'] : ucfirst($r['name']);
    $r['labels'] = array_merge(array('name' => $default_name, 'singular_name' => $default_name), $r['labels']);
    // Directory slug.
    if ($r['has_directory']) {
        // A string value is intepreted as the directory slug. Otherwise fall back on member type.
        if (is_string($r['has_directory'])) {
            $directory_slug = $r['has_directory'];
        } else {
            $directory_slug = $member_type;
        }
        // Sanitize for use in URLs.
        $r['directory_slug'] = sanitize_title($directory_slug);
        $r['has_directory'] = true;
    } else {
        $r['directory_slug'] = '';
        $r['has_directory'] = false;
    }
    $bp->members->types[$member_type] = $type = (object) $r;
    /**
     * Fires after a member type is registered.
     *
     * @since 2.2.0
     *
     * @param string $member_type Member type identifier.
     * @param object $type        Member type object.
     */
    do_action('bp_registered_member_type', $member_type, $type);
    return $type;
}
    /**
     * Output HTML for this field type on the wp-admin Profile Fields screen.
     *
     * Must be used inside the {@link bp_profile_fields()} template loop.
     *
     * @since 2.0.0
     *
     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
     */
    public function admin_field_html(array $raw_properties = array())
    {
        $day_r = bp_parse_args($raw_properties, array('id' => bp_get_the_profile_field_input_name() . '_day', 'name' => bp_get_the_profile_field_input_name() . '_day'));
        $month_r = bp_parse_args($raw_properties, array('id' => bp_get_the_profile_field_input_name() . '_month', 'name' => bp_get_the_profile_field_input_name() . '_month'));
        $year_r = bp_parse_args($raw_properties, array('id' => bp_get_the_profile_field_input_name() . '_year', 'name' => bp_get_the_profile_field_input_name() . '_year'));
        ?>

		<label for="<?php 
        bp_the_profile_field_input_name();
        ?>
_day" class="screen-reader-text"><?php 
        esc_html_e('Select day', 'buddypress');
        ?>
</label>
		<select <?php 
        echo $this->get_edit_field_html_elements($day_r);
        ?>
>
			<?php 
        bp_the_profile_field_options(array('type' => 'day'));
        ?>
		</select>

		<label for="<?php 
        bp_the_profile_field_input_name();
        ?>
_month" class="screen-reader-text"><?php 
        esc_html_e('Select month', 'buddypress');
        ?>
</label>
		<select <?php 
        echo $this->get_edit_field_html_elements($month_r);
        ?>
>
			<?php 
        bp_the_profile_field_options(array('type' => 'month'));
        ?>
		</select>

		<label for="<?php 
        bp_the_profile_field_input_name();
        ?>
_year" class="screen-reader-text"><?php 
        esc_html_e('Select year', 'buddypress');
        ?>
</label>
		<select <?php 
        echo $this->get_edit_field_html_elements($year_r);
        ?>
>
			<?php 
        bp_the_profile_field_options(array('type' => 'year'));
        ?>
		</select>

	<?php 
    }
/**
 * Return the number of friends in user's profile.
 *
 * @since 2.0.0
 *
 * @param array|string $args before|after|user_id.
 * @return string HTML for stats output.
 */
function bp_friends_get_profile_stats($args = '')
{
    // Parse the args.
    $r = bp_parse_args($args, array('before' => '<li class="bp-friends-profile-stats">', 'after' => '</li>', 'user_id' => bp_displayed_user_id(), 'friends' => 0, 'output' => ''), 'friends_get_profile_stats');
    // Allow completely overloaded output.
    if (empty($r['output'])) {
        // Only proceed if a user ID was passed.
        if (!empty($r['user_id'])) {
            // Get the user's friends.
            if (empty($r['friends'])) {
                $r['friends'] = absint(friends_get_total_friend_count($r['user_id']));
            }
            // If friends exist, show some formatted output.
            $r['output'] = $r['before'] . sprintf(_n('%s friend', '%s friends', $r['friends'], 'buddypress'), '<strong>' . $r['friends'] . '</strong>') . $r['after'];
        }
    }
    /**
     * Filters the number of friends in user's profile.
     *
     * @since 2.0.0
     *
     * @param string $value Formatted string displaying total friends count.
     * @param array  $r     Array of arguments for string formatting and output.
     */
    return apply_filters('bp_friends_get_profile_stats', $r['output'], $r);
}
/**
 * Initiate the loop for a single topic's posts.
 *
 * @param array $args {
 *     Arguments for limiting the contents of the topic posts loop.
 *     @type int $topic_id ID of the topic to which the posts belong.
 *     @type int $per_page Number of items to return per page. Default: 15.
 *     @type int $max Max items to return. Default: false.
 *     @type string $order 'ASC' or 'DESC'.
 * }
 * @return bool True when posts are found corresponding to the args,
 *         otherwise false.
 */
function bp_has_forum_topic_posts($args = '')
{
    global $topic_template;
    $defaults = array('topic_id' => false, 'per_page' => 15, 'max' => false, 'order' => 'ASC');
    $r = bp_parse_args($args, $defaults, 'has_forum_topic_posts');
    extract($r, EXTR_SKIP);
    if (empty($topic_id) && bp_is_groups_component() && bp_is_current_action('forum') && bp_is_action_variable('topic', 0) && bp_action_variable(1)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(1));
    } elseif (empty($topic_id) && bp_is_forums_component() && bp_is_current_action('topic') && bp_action_variable(0)) {
        $topic_id = bp_forums_get_topic_id_from_slug(bp_action_variable(0));
    }
    if (empty($topic_id)) {
        return false;
    } else {
        $topic_template = new BP_Forums_Template_Topic((int) $topic_id, $per_page, $max, $order);
        // Current topic forum_id needs to match current_group forum_id
        if (bp_is_groups_component() && $topic_template->forum_id != groups_get_groupmeta(bp_get_current_group_id(), 'forum_id')) {
            return false;
        }
    }
    return apply_filters('bp_has_topic_posts', $topic_template->has_posts(), $topic_template);
}
 /**
  * Get a sanitised and escaped string of the edit field's HTML elements and attributes.
  *
  * Must be used inside the {@link bp_profile_fields()} template loop.
  * This method was intended to be static but couldn't be because php.net/lsb/ requires PHP >= 5.3.
  *
  * @since 2.0.0
  *
  * @param array $properties Optional key/value array of attributes for this edit field.
  *
  * @return string
  */
 protected function get_edit_field_html_elements(array $properties = array())
 {
     $r = bp_parse_args($properties, array('id' => bp_get_the_profile_field_input_name(), 'name' => bp_get_the_profile_field_input_name()));
     if (bp_get_the_profile_field_is_required()) {
         $r['aria-required'] = 'true';
     }
     /**
      * Filters the edit html elements and attributes.
      *
      * @since 2.0.0
      *
      * @param array  $r     Array of parsed arguments.
      * @param string $value Class name for the current class instance.
      */
     $r = (array) apply_filters('bp_xprofile_field_edit_html_elements', $r, get_class($this));
     return bp_get_form_field_attributes(sanitize_key(bp_get_the_profile_field_name()), $r);
 }
/**
 * BuddyPress Suggestions API for types of at-mentions.
 *
 * This is used to power BuddyPress' at-mentions suggestions, but it is flexible enough to be used
 * for similar kinds of future requirements, or those implemented by third-party developers.
 *
 * @param array $args
 * @return array|WP_Error Array of results. If there were any problems, returns a WP_Error object.
 * @since BuddyPress (2.1.0)
 */
function bp_core_get_suggestions($args)
{
    $args = bp_parse_args($args, array(), 'get_suggestions');
    if (!$args['type']) {
        return new WP_Error('missing_parameter');
    }
    // Members @name suggestions.
    if ($args['type'] === 'members') {
        $class = 'BP_Members_Suggestions';
        // Members @name suggestions for users in a specific Group.
        if (isset($args['group_id'])) {
            $class = 'BP_Groups_Member_Suggestions';
        }
    } else {
        // If you've built a custom suggestions service, use this to tell BP the name of your class.
        $class = apply_filters('bp_suggestions_services', '', $args);
    }
    if (!$class || !class_exists($class)) {
        return new WP_Error('missing_parameter');
    }
    $suggestions = new $class($args);
    $validation = $suggestions->validate();
    if (is_wp_error($validation)) {
        $retval = $validation;
    } else {
        $retval = $suggestions->get_suggestions();
    }
    return apply_filters('bp_core_get_suggestions', $retval, $args);
}
Example #14
0
/**
 * Delete an activity item by activity id.
 *
 * You should use bp_activity_delete() instead.
 *
 * @since BuddyPress (1.1.0)
 * @deprecated BuddyPress (1.2)
 *
 * @uses wp_parse_args()
 * @uses bp_activity_delete()
 *
 * @param array $args See BP_Activity_Activity::get for a description
 *                    of accepted arguments.
 *
 * @return bool True on success, false on failure.
 */
function bp_activity_delete_by_item_id($args = '')
{
    $r = bp_parse_args($args, array('item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false));
    return bp_activity_delete($r);
}
/**
 * Return the current member's last active time.
 *
 * @param array $args {
 *     Array of optional arguments.
 *     @type mixed $active_format If true, formatted "active 5 minutes
 *                                ago". If false, formatted "5 minutes ago".
 *                                If string, should be sprintf'able like
 *                                'last seen %s ago'.
 * }
 * @return string
 */
function bp_get_member_last_active($args = array())
{
    global $members_template;
    // Parse the activity format.
    $r = bp_parse_args($args, array('active_format' => true));
    // Backwards compatibility for anyone forcing a 'true' active_format.
    if (true === $r['active_format']) {
        $r['active_format'] = __('active %s', 'buddypress');
    }
    // Member has logged in at least one time.
    if (isset($members_template->member->last_activity)) {
        // Backwards compatibility for pre 1.5 'ago' strings.
        $last_activity = !empty($r['active_format']) ? bp_core_get_last_activity($members_template->member->last_activity, $r['active_format']) : bp_core_time_since($members_template->member->last_activity);
        // Member has never logged in or been active.
    } else {
        $last_activity = __('Never active', 'buddypress');
    }
    /**
     * Filters the current members last active time.
     *
     * @since 1.2.0
     *
     * @param string $last_activity Formatted time since last activity.
     * @param array  $r             Array of parsed arguments for query.
     */
    return apply_filters('bp_member_last_active', $last_activity, $r);
}
 /**
  * Merge the widget settings into defaults array.
  *
  * @since 2.3.0
  *
  * @uses bp_parse_args() To merge widget settings into defaults.
  *
  * @param array $instance Widget instance settings.
  * @return array
  */
 public function parse_settings($instance = array())
 {
     return bp_parse_args($instance, array('title' => __('Recently Active Members', 'buddypress'), 'max_members' => 15), 'recently_active_members_widget_settings');
 }
/**
 * BuddyDrive Loop : do we have items for the query asked
 *
 * @param  array $args the arguments of the query
 * @global object $buddydrive_template
 * @uses buddydrive_get_folder_post_type() to get BuddyFolder post type
 * @uses buddydrive_get_file_post_type() to get BuddyFile post type
 * @uses bp_displayed_user_id() to default to current displayed user
 * @uses bp_current_action() to get the current action ( files / friends / admin)
 * @uses bp_is_active() to check if groups component is active
 * @uses buddydrive_is_group() are we on a group's BuddyDrive ?
 * @uses wp_parse_args() to merge defaults and args
 * @uses BuddyDrive_Item::get() to request the DB
 * @uses BuddyDrive_Item::have_posts to know if BuddyItems matched the query
 * @return the result of the query
 */
function buddydrive_has_items($args = '')
{
    global $buddydrive_template;
    // This keeps us from firing the query more than once
    if (empty($buddydrive_template)) {
        $defaulttype = array(buddydrive_get_folder_post_type(), buddydrive_get_file_post_type());
        $user = $group_id = $buddyscope = false;
        if (bp_displayed_user_id()) {
            $user = bp_displayed_user_id();
        }
        $buddyscope = bp_current_action();
        if ($buddyscope == buddydrive_get_friends_subnav_slug()) {
            $buddyscope = 'friends';
        }
        if (is_admin()) {
            $buddyscope = 'admin';
        }
        if (bp_is_active('groups') && buddydrive_is_group()) {
            $group = groups_get_current_group();
            $group_id = $group->id;
            $buddyscope = 'groups';
        }
        /***
         * Set the defaults for the parameters you are accepting via the "buddydrive_has_items()"
         * function call
         */
        $defaults = array('id' => false, 'name' => false, 'group_id' => $group_id, 'user_id' => $user, 'per_page' => 10, 'paged' => 1, 'type' => $defaulttype, 'buddydrive_scope' => $buddyscope, 'search' => false, 'buddydrive_parent' => 0, 'exclude' => 0, 'orderby' => 'title', 'order' => 'ASC');
        $r = bp_parse_args($args, $defaults, 'buddydrive_has_items');
        if ('admin' === $r['buddydrive_scope'] && !bp_current_user_can('bp_moderate')) {
            $r['buddydrive_scope'] = 'files';
        }
        $buddydrive_template = new BuddyDrive_Item();
        if (!empty($search)) {
            $buddydrive_template->get(array('per_page' => $r['per_page'], 'paged' => $r['paged'], 'type' => $r['type'], 'buddydrive_scope' => $r['buddydrive_scope'], 'search' => $r['search'], 'orderby' => $r['orderby'], 'order' => $r['order']));
        } else {
            $buddydrive_template->get(array('id' => $r['id'], 'name' => $r['name'], 'group_id' => $r['group_id'], 'user_id' => $r['user_id'], 'per_page' => $r['per_page'], 'paged' => $r['paged'], 'type' => $r['type'], 'buddydrive_scope' => $r['buddydrive_scope'], 'buddydrive_parent' => $r['buddydrive_parent'], 'exclude' => $r['exclude'], 'orderby' => $r['orderby'], 'order' => $r['order']));
        }
        do_action('buddydrive_has_items_catch_total_count', $buddydrive_template->query->found_posts);
    }
    return apply_filters('buddydrive_has_items', $buddydrive_template->have_posts());
}
/**
 * Retrieve a client friendly version of the root blog name.
 *
 * The blogname option is escaped with esc_html on the way into the database in
 * sanitize_option, we want to reverse this for the plain text arena of emails.
 *
 * @since 1.7.0
 * @since 2.5.0 No longer used by BuddyPress, but not deprecated in case any existing plugins use it.
 *
 * @see https://buddypress.trac.wordpress.org/ticket/4401
 *
 * @param array $args {
 *     Array of optional parameters.
 *     @type string $before  String to appear before the site name in the
 *                           email subject. Default: '['.
 *     @type string $after   String to appear after the site name in the
 *                           email subject. Default: ']'.
 *     @type string $default The default site name, to be used when none is
 *                           found in the database. Default: 'Community'.
 *     @type string $text    Text to append to the site name (ie, the main text of
 *                           the email subject).
 * }
 * @return string Sanitized email subject.
 */
function bp_get_email_subject($args = array())
{
    $r = bp_parse_args($args, array('before' => '[', 'after' => ']', 'default' => __('Community', 'buddypress'), 'text' => ''), 'get_email_subject');
    $subject = $r['before'] . wp_specialchars_decode(bp_get_option('blogname', $r['default']), ENT_QUOTES) . $r['after'] . ' ' . $r['text'];
    /**
     * Filters a client friendly version of the root blog name.
     *
     * @since 1.7.0
     *
     * @param string $subject Client friendy version of the root blog name.
     * @param array  $r       Array of arguments for the email subject.
     */
    return apply_filters('bp_get_email_subject', $subject, $r);
}
/**
 * Deletes activity for a user within the profile component so that it will be
 * removed from the users activity stream and sitewide stream (if installed).
 *
 * @since 1.0.0
 *
 * @uses bp_activity_delete() Deletes an entry to the activity component tables
 *                            for a specific activity.
 *
 * @param array|string $args Containing all variables used after bp_parse_args() call.
 *
 * @return bool
 */
function xprofile_delete_activity($args = '')
{
    // Bail if activity component is not active.
    if (!bp_is_active('activity')) {
        return false;
    }
    // Parse the arguments.
    $r = bp_parse_args($args, array('component' => buddypress()->profile->id), 'xprofile_delete_activity');
    // Delete the activity item.
    bp_activity_delete_by_item_id($r);
}
 /**
  * Get a sanitised and escaped string of the edit field's HTML elements and attributes.
  *
  * Must be used inside the {@link bp_profile_fields()} template loop.
  * This method was intended to be static but couldn't be because php.net/lsb/ requires PHP >= 5.3.
  *
  * @param array $properties Optional key/value array of attributes for this edit field.
  * @return string
  * @since BuddyPress (2.0.0)
  */
 protected function get_edit_field_html_elements(array $properties = array())
 {
     $r = bp_parse_args($properties, array('id' => bp_get_the_profile_field_input_name(), 'name' => bp_get_the_profile_field_input_name()));
     if (bp_get_the_profile_field_is_required()) {
         $r['aria-required'] = 'true';
     }
     $html = '';
     $r = (array) apply_filters('bp_xprofile_field_edit_html_elements', $r, get_class($this));
     foreach ($r as $name => $value) {
         $html .= sprintf('%s="%s" ', sanitize_key($name), esc_attr($value));
     }
     return $html;
 }
 /**
  * Get current message threads for a user.
  *
  * @since 1.0.0
  *
  * @param array $args {
  *     Array of arguments.
  *     @type int    $user_id      The user ID.
  *     @type string $box          The type of mailbox to get. Either 'inbox' or 'sentbox'.
  *                                Defaults to 'inbox'.
  *     @type string $type         The type of messages to get. Either 'all' or 'unread'
  *                                or 'read'. Defaults to 'all'.
  *     @type int    $limit        The number of messages to get. Defaults to null.
  *     @type int    $page         The page number to get. Defaults to null.
  *     @type string $search_terms The search term to use. Defaults to ''.
  *     @type array  $meta_query   Meta query arguments. See WP_Meta_Query for more details.
  * }
  * @return array|bool Array on success. Boolean false on failure.
  */
 public static function get_current_threads_for_user($args = array())
 {
     global $wpdb;
     // Backward compatibility with old method of passing arguments
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '2.2.0', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
         $old_args_keys = array(0 => 'user_id', 1 => 'box', 2 => 'type', 3 => 'limit', 4 => 'page', 5 => 'search_terms');
         $func_args = func_get_args();
         $args = bp_core_parse_args_array($old_args_keys, $func_args);
     }
     $r = bp_parse_args($args, array('user_id' => false, 'box' => 'inbox', 'type' => 'all', 'limit' => null, 'page' => null, 'search_terms' => '', 'meta_query' => array()));
     $pag_sql = $type_sql = $search_sql = $user_id_sql = $sender_sql = '';
     $meta_query_sql = array('join' => '', 'where' => '');
     if ($r['limit'] && $r['page']) {
         $pag_sql = $wpdb->prepare(" LIMIT %d, %d", intval(($r['page'] - 1) * $r['limit']), intval($r['limit']));
     }
     if ($r['type'] == 'unread') {
         $type_sql = " AND r.unread_count != 0 ";
     } elseif ($r['type'] == 'read') {
         $type_sql = " AND r.unread_count = 0 ";
     }
     if (!empty($r['search_terms'])) {
         $search_terms_like = '%' . bp_esc_like($r['search_terms']) . '%';
         $search_sql = $wpdb->prepare("AND ( subject LIKE %s OR message LIKE %s )", $search_terms_like, $search_terms_like);
     }
     $r['user_id'] = (int) $r['user_id'];
     // Default deleted SQL
     $deleted_sql = 'r.is_deleted = 0';
     switch ($r['box']) {
         case 'sentbox':
             $user_id_sql = 'AND ' . $wpdb->prepare('m.sender_id = %d', $r['user_id']);
             $sender_sql = 'AND m.sender_id = r.user_id';
             break;
         case 'inbox':
             $user_id_sql = 'AND ' . $wpdb->prepare('r.user_id = %d', $r['user_id']);
             $sender_sql = 'AND r.sender_only = 0';
             break;
         default:
             // Omit user-deleted threads from all other custom message boxes
             $deleted_sql = $wpdb->prepare('( r.user_id = %d AND r.is_deleted = 0 )', $r['user_id']);
             break;
     }
     // Process meta query into SQL
     $meta_query = self::get_meta_query_sql($r['meta_query']);
     if (!empty($meta_query['join'])) {
         $meta_query_sql['join'] = $meta_query['join'];
     }
     if (!empty($meta_query['where'])) {
         $meta_query_sql['where'] = $meta_query['where'];
     }
     $bp = buddypress();
     // set up SQL array
     $sql = array();
     $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent';
     $sql['from'] = "FROM {$bp->messages->table_name_recipients} r INNER JOIN {$bp->messages->table_name_messages} m ON m.thread_id = r.thread_id {$meta_query_sql['join']}";
     $sql['where'] = "WHERE {$deleted_sql} {$user_id_sql} {$sender_sql} {$type_sql} {$search_sql} {$meta_query_sql['where']}";
     $sql['misc'] = "GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}";
     // get thread IDs
     $thread_ids = $wpdb->get_results(implode(' ', $sql));
     if (empty($thread_ids)) {
         return false;
     }
     // adjust $sql to work for thread total
     $sql['select'] = 'SELECT COUNT( DISTINCT m.thread_id )';
     unset($sql['misc']);
     $total_threads = $wpdb->get_var(implode(' ', $sql));
     // Sort threads by date_sent
     foreach ((array) $thread_ids as $thread) {
         $sorted_threads[$thread->thread_id] = strtotime($thread->date_sent);
     }
     arsort($sorted_threads);
     $threads = array();
     foreach ((array) $sorted_threads as $thread_id => $date_sent) {
         $threads[] = new BP_Messages_Thread($thread_id, 'ASC', array('update_meta_cache' => false));
     }
     /**
      * Filters the results of the query for a user's message threads.
      *
      * @since 2.2.0
      *
      * @param array $value {
      *     @type array $threads       Array of threads. Passed by reference.
      *     @type int   $total_threads Number of threads found by the query.
      * }
      */
     return apply_filters('bp_messages_thread_current_threads', array('threads' => &$threads, 'total' => (int) $total_threads));
 }
/**
 * Get the avatar for the current message sender.
 *
 * @param array|string $args {
 *     Array of arguments. See {@link bp_core_fetch_avatar()} for more
 *     complete details. All arguments are optional.
 *     @type string $type   Avatar type. Default: 'thumb'.
 *     @type int    $width  Avatar width. Default: default for your $type.
 *     @type int    $height Avatar height. Default: default for your $type.
 * }
 * @return string <img> tag containing the avatar.
 */
function bp_get_the_thread_message_sender_avatar_thumb($args = '')
{
    global $thread_template;
    $r = bp_parse_args($args, array('type' => 'thumb', 'width' => false, 'height' => false));
    /**
     * Filters the avatar for the current message sender.
     *
     * @since 1.1.0
     *
     * @param string $value <img> tag containing the avatar value.
     */
    return apply_filters('bp_get_the_thread_message_sender_avatar_thumb', bp_core_fetch_avatar(array('item_id' => $thread_template->message->sender_id, 'type' => $r['type'], 'width' => $r['width'], 'height' => $r['height'], 'alt' => bp_core_get_user_displayname($thread_template->message->sender_id))));
}
 /**
  * Edit an image file to resize it or rotate it
  *
  * @since 2.4.0
  *
  * @param string $attachment_type The attachment type (eg: avatar or cover_image). Required.
  * @param array  $args {
  *     @type string $file     Absolute path to the image file (required).
  *     @type int    $max_w    Max width attribute for the editor's resize method (optional).
  *     @type int    $max_h    Max height attribute for the editor's resize method (optional).
  *     @type bool   $crop     Crop attribute for the editor's resize method (optional).
  *     @type float  $rotate   Angle for the editor's rotate method (optional).
  *     @type int    $quality  Compression quality on a 1-100% scale (optional).
  *     @type bool   $save     Whether to use the editor's save method or not (optional).
  * }
  * @return string|WP_Image_Editor|WP_Error The edited image path or the WP_Image_Editor object in case of success,
  *                                         an WP_Error object otherwise.
  */
 public static function edit_image($attachment_type, $args = array())
 {
     if (empty($attachment_type)) {
         return new WP_Error('missing_parameter');
     }
     $r = bp_parse_args($args, array('file' => '', 'max_w' => 0, 'max_h' => 0, 'crop' => false, 'rotate' => 0, 'quality' => 90, 'save' => true), 'attachment_' . $attachment_type . '_edit_image');
     // Make sure we have to edit the image.
     if (empty($r['max_w']) && empty($r['max_h']) && empty($r['rotate']) && empty($r['file'])) {
         return new WP_Error('missing_parameter');
     }
     // Get the image editor.
     $editor = wp_get_image_editor($r['file']);
     if (is_wp_error($editor)) {
         return $editor;
     }
     $editor->set_quality($r['quality']);
     if (!empty($r['rotate'])) {
         $rotated = $editor->rotate($r['rotate']);
         // Stop in case of error.
         if (is_wp_error($rotated)) {
             return $rotated;
         }
     }
     if (!empty($r['max_w']) || !empty($r['max_h'])) {
         $resized = $editor->resize($r['max_w'], $r['max_h'], $r['crop']);
         // Stop in case of error.
         if (is_wp_error($resized)) {
             return $resized;
         }
     }
     // Use the editor save method to get a path to the edited image.
     if (true === $r['save']) {
         return $editor->save($editor->generate_filename());
         // Need to do some other edit actions or use a specific method to save file.
     } else {
         return $editor;
     }
 }
    /**
     * Output HTML for this field type on the wp-admin Profile Fields screen.
     *
     * Must be used inside the {@link bp_profile_fields()} template loop.
     *
     * @param array $raw_properties Optional key/value array of permitted
     *        attributes that you want to add.
     * @since 2.1.0
     */
    public function admin_field_html(array $raw_properties = array())
    {
        $r = bp_parse_args($raw_properties, array('type' => 'url'));
        ?>

		<input <?php 
        echo $this->get_edit_field_html_elements($r);
        ?>
>

		<?php 
    }
/**
 * Initialize the notifications loop.
 *
 * Based on the $args passed, bp_has_notifications() populates
 * buddypress()->notifications->query_loop global, enabling the use of BP
 * templates and template functions to display a list of notifications.
 *
 * @since BuddyPress (1.9.0)
 *
 * @param array|string $args {
 *     Arguments for limiting the contents of the notifications loop. Can be
 *     passed as an associative array, or as a URL query string.
 *
 *     See {@link BP_Notifications_Notification::get()} for detailed
 *     information on the arguments.  In addition, also supports:
 *
 *     @type int    $max      Optional. Max items to display. Default: false.
 *     @type string $page_arg URL argument to use for pagination.
 *                            Default: 'npage'.
 * }
 *
 * @return bool
 */
function bp_has_notifications($args = '')
{
    // Get the default is_new argument
    if (bp_is_current_action('unread')) {
        $is_new = 1;
    } elseif (bp_is_current_action('read')) {
        $is_new = 0;
        // not on a notifications page? default to fetch new notifications
    } else {
        $is_new = 1;
    }
    // Get the user ID
    if (bp_displayed_user_id()) {
        $user_id = bp_displayed_user_id();
    } else {
        $user_id = bp_loggedin_user_id();
    }
    // Parse the args
    $r = bp_parse_args($args, array('id' => false, 'user_id' => $user_id, 'secondary_item_id' => false, 'component_name' => bp_notifications_get_registered_components(), 'component_action' => false, 'is_new' => $is_new, 'search_terms' => isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '', 'order_by' => 'date_notified', 'sort_order' => 'DESC', 'meta_query' => false, 'date_query' => false, 'page' => 1, 'per_page' => 25, 'max' => false, 'page_arg' => 'npage'), 'has_notifications');
    // Get the notifications
    $query_loop = new BP_Notifications_Template($r);
    // Setup the global query loop
    buddypress()->notifications->query_loop = $query_loop;
    /**
     * Filters whether or not the user has notifications to display.
     *
     * @since BuddyPress (1.9.0)
     *
     * @param bool                      $value      Whether or not there are notifications to display.
     * @param BP_Notifications_Template $query_loop BP_Notifications_Template object instance.
     */
    return apply_filters('bp_has_notifications', $query_loop->has_notifications(), $query_loop);
}
Example #26
0
/**
 * Return the number of blogs in user's profile.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param array|string $args before|after|user_id
 *
 * @return string HTML for stats output.
 */
function bp_blogs_get_profile_stats($args = '')
{
    // Parse the args
    $r = bp_parse_args($args, array('before' => '<li class="bp-blogs-profile-stats">', 'after' => '</li>', 'user_id' => bp_displayed_user_id(), 'blogs' => 0, 'output' => ''), 'blogs_get_profile_stats');
    // Allow completely overloaded output
    if (is_multisite() && empty($r['output'])) {
        // Only proceed if a user ID was passed
        if (!empty($r['user_id'])) {
            // Get the user's blogs
            if (empty($r['blogs'])) {
                $r['blogs'] = absint(bp_blogs_total_blogs_for_user($r['user_id']));
            }
            // If blogs exist, show some formatted output
            $r['output'] = $r['before'] . sprintf(_n('%s site', '%s sites', $r['blogs'], 'buddypress'), '<strong>' . $r['blogs'] . '</strong>') . $r['after'];
        }
    }
    /**
     * Filters the number of blogs in user's profile.
     *
     * @since BuddyPress (2.0.0)
     *
     * @param string $value Output determined for the profile stats.
     * @param array  $r     Array of arguments used for default output if none provided.
     */
    return apply_filters('bp_blogs_get_profile_stats', $r['output'], $r);
}
/**
 * Return the number of groups in user's profile.
 *
 * @since BuddyPress (2.0.0)
 *
 * @param array $args before|after|user_id
 * @return string HTML for stats output.
 */
function bp_groups_get_profile_stats($args = '')
{
    // Parse the args
    $r = bp_parse_args($args, array('before' => '<li class="bp-groups-profile-stats">', 'after' => '</li>', 'user_id' => bp_displayed_user_id(), 'groups' => 0, 'output' => ''), 'groups_get_profile_stats');
    // Allow completely overloaded output
    if (empty($r['output'])) {
        // Only proceed if a user ID was passed
        if (!empty($r['user_id'])) {
            // Get the user groups
            if (empty($r['groups'])) {
                $r['groups'] = absint(bp_get_total_group_count_for_user($r['user_id']));
            }
            // If groups exist, show some formatted output
            $r['output'] = $r['before'] . sprintf(_n('%s group', '%s groups', $r['groups'], 'buddypress'), '<strong>' . $r['groups'] . '</strong>') . $r['after'];
        }
    }
    // Filter and return
    return apply_filters('bp_groups_get_profile_stats', $r['output'], $r);
}
/**
 * Delete a blog-related activity stream item.
 *
 * @since BuddyPress (1.0.0)
 *
 * @see bp_activity_delete() for description of parameters.
 *
 * @param array $args {
 *     See {@link bp_activity_delete()} for complete description of arguments.
 *     The arguments listed here have different default values from
 *     bp_activity_add().
 *     @type string $component Default: 'blogs'.
 * }
 * @return bool True on success, false on failure.
 */
function bp_blogs_delete_activity( $args = '' ) {

	// Bail if activity is not active
	if ( ! bp_is_active( 'activity' ) ) {
		return false;
	}

	$r = bp_parse_args( $args, array(
		'item_id'           => false,
		'component'         => buddypress()->blogs->id,
		'type'              => false,
		'user_id'           => false,
		'secondary_item_id' => false
	) );

	bp_activity_delete_by_item_id( $r );
}
    /**
     * Output HTML for this field type on the wp-admin Profile Fields screen.
     *
     * Must be used inside the {@link bp_profile_fields()} template loop.
     *
     * @since 2.0.0
     *
     * @param array $raw_properties Optional key/value array of permitted attributes that you want to add.
     */
    public function admin_field_html(array $raw_properties = array())
    {
        $r = bp_parse_args($raw_properties, array('multiple' => 'multiple'));
        ?>

		<label for="<?php 
        bp_the_profile_field_input_name();
        ?>
" class="screen-reader-text"><?php 
        esc_html_e('Select', 'buddypress');
        ?>
</label>
		<select <?php 
        echo $this->get_edit_field_html_elements($r);
        ?>
>
			<?php 
        bp_the_profile_field_options();
        ?>
		</select>

		<?php 
    }
 /**
  * Update the meta for a signup.
  *
  * This is the way we use to "trace" the last date an activation
  * email was sent and how many times activation was sent.
  *
  * @since 2.0.0
  *
  * @param array $args Array of arguments for the signup update.
  * @return int The signup id.
  */
 public static function update($args = array())
 {
     global $wpdb;
     $r = bp_parse_args($args, array('signup_id' => 0, 'meta' => array()), 'bp_core_signups_update_args');
     if (empty($r['signup_id']) || empty($r['meta'])) {
         return false;
     }
     $wpdb->update(buddypress()->members->table_name_signups, array('meta' => serialize($r['meta'])), array('signup_id' => $r['signup_id']), array('%s'), array('%d'));
     /**
      * Filters the signup ID which received a meta update.
      *
      * @since 2.0.0
      *
      * @param int $value The signup ID.
      */
     return apply_filters('bp_core_signups_update', $r['signup_id']);
 }