/**
* 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();
}
/**
* 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();
}
/**
* 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;
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
请发表评论