*/
'post_content' => __( "An administrator accepted an invitation to join "{{group.name}}" on your behalf.\n\nIf you disagree with this, you can leave the group at anytime visiting your groups memberships page.", 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_excerpt' => __( "An administrator accepted an invitation to join \"{{group.name}}\" on your behalf.\n\nIf you disagree with this, you can leave the group at anytime visiting your groups memberships page: {{{leave-group.url}}}", 'buddypress' ),
),
'groups-membership-request-rejected-by-admin' => array(
/* translators: do not remove {} brackets or translate its contents. */
'post_title' => __( '[{{{site.name}}}] Membership request for group "{{group.name}}" rejected', 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_content' => __( "An administrator rejected an invitation to join "{{group.name}}" on your behalf.\n\nIf you disagree with this, please contact the site administrator.", 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_excerpt' => __( "An administrator rejected an invitation to join \"{{group.name}}\" on your behalf.\n\nIf you disagree with this, please contact the site administrator.", 'buddypress' ),
),
'bp-members-invitation' => array(
/* translators: do not remove {} brackets or translate its contents. */
'post_title' => __( '{{inviter.name}} has invited you to join {{site.name}}', 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_content' => __( "{{inviter.name}} has invited you to join the site: "{{site.name}}".\n\n{{usermessage}}\n\nAccept your invitation or visit the site to learn more.", 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_excerpt' => __( "{{inviter.name}} has invited you to join the site \"{{site.name}}\".\n\n{{usermessage}}\n\nTo accept your invitation, visit: {{{invite.accept_url}}}\n\nTo learn more about the site, visit: {{{site.url}}}.\nTo view {{inviter.name}}'s profile, visit: {{{inviter.url}}}", 'buddypress' ),
),
'members-membership-request' => array(
/* translators: do not remove {} brackets or translate its contents. */
'post_title' => __( '{{requesting-user.user_login}} would like to join {{site.name}}', 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_content' => __( "{{requesting-user.user_login}} would like to join the site: "{{site.name}}".\n\nManage the request.", 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_excerpt' => __( "{{requesting-user.user_login}} would like to join the site \"{{site.name}}\".\n\nTo manage the request, visit: {{{manage.url}}}.", 'buddypress' ),
),
'members-membership-request-rejected' => array(
/* translators: do not remove {} brackets or translate its contents. */
'post_title' => __( 'Your request to join {{site.name}} has been declined', 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_content' => __( "Sorry, your request to join the site "{{site.name}}" has been declined.", 'buddypress' ),
/* translators: do not remove {} brackets or translate its contents. */
'post_excerpt' => __( "Sorry, your request to join the site \"{{site.name}}\" has been declined.", 'buddypress' ),
),
) );
}
/**
* Get a list of emails for populating email type taxonomy terms.
*
* @since 2.5.1
* @since 2.7.0 $field argument added.
*
* @param string $field Optional; defaults to "description" for backwards compatibility. Other values: "all".
* @return array {
* The array of email types and their schema.
*
* @type string $description The description of the action which causes this to trigger.
* @type array $unsubscribe {
* Replacing this with false indicates that a user cannot unsubscribe from this type.
*
* @type string $meta_key The meta_key used to toggle the email setting for this notification.
* @type string $message The message shown when the user has successfully unsubscribed.
* }
*/
function bp_email_get_type_schema( $field = 'description' ) {
$activity_comment = array(
'description' => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_activity_new_reply',
'message' => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
),
);
$activity_comment_author = array(
'description' => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_activity_new_reply',
'message' => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
),
);
$activity_at_message = array(
'description' => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_activity_new_mention',
'message' => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
),
);
$groups_at_message = array(
'description' => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_activity_new_mention',
'message' => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
),
);
$core_user_registration = array(
'description' => __( 'Recipient has registered for an account.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => false,
);
$core_user_registration_with_blog = array(
'description' => __( 'Recipient has registered for an account and site.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => false,
);
$friends_request = array(
'description' => __( 'A member has sent a friend request to the recipient.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_friends_friendship_request',
'message' => __( 'You will no longer receive emails when someone sends you a friend request.', 'buddypress' ),
),
);
$friends_request_accepted = array(
'description' => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_friends_friendship_accepted',
'message' => __( 'You will no longer receive emails when someone accepts your friendship request.', 'buddypress' ),
),
);
$groups_details_updated = array(
'description' => __( "A group's details were updated.", 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_groups_group_updated',
'message' => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ),
),
);
$groups_invitation = array(
'description' => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_groups_invite',
'message' => __( 'You will no longer receive emails when you are invited to join a group.', 'buddypress' ),
),
);
$groups_member_promoted = array(
'description' => __( "Recipient's status within a group has changed.", 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_groups_admin_promotion',
'message' => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ),
),
);
$groups_membership_request = array(
'description' => __( 'A member has requested permission to join a group.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_groups_membership_request',
'message' => __( 'You will no longer receive emails when someone requests to be a member of your group.', 'buddypress' ),
),
);
$messages_unread = array(
'description' => __( 'Recipient has received a private message.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_messages_new_message',
'message' => __( 'You will no longer receive emails when someone sends you a message.', 'buddypress' ),
),
);
$settings_verify_email_change = array(
'description' => __( 'Recipient has changed their email address.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => false,
);
$groups_membership_request_accepted = array(
'description' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_membership_request_completed',
'message' => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
),
);
$groups_membership_request_rejected = array(
'description' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_membership_request_completed',
'message' => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
),
);
$groups_membership_request_accepted_by_admin = array(
'description' => __( 'Recipient had requested to join a group, which was accepted by admin.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => false,
);
$groups_membership_request_rejected_by_admin = array(
'description' => __( 'Recipient had requested to join a group, which was rejected by admin.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => false,
);
$core_user_activation = array(
'description' => __( 'Recipient has successfully activated an account.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => false,
);
$members_invitation = array(
'description' => __( 'A site member has sent a site invitation to the recipient.', 'buddypress' ),
'named_salutation' => false,
'unsubscribe' => array(
'meta_key' => 'notification_bp_members_invite',
'message' => __( 'You will no longer receive emails when you are invited to join this site.', 'buddypress' ),
),
);
$members_membership_request = array(
'description' => __( 'Someone has requested membership on this site.', 'buddypress' ),
'named_salutation' => true,
'unsubscribe' => array(
'meta_key' => 'notification_members_membership_request',
'message' => __( 'You will no longer receive emails when people submit requests to join this site.', 'buddypress' ),
),
);
$members_membership_request_rejected = array(
'description' => __( 'A site membership request has been rejected.', 'buddypress' ),
'named_salutation' => false,
'unsubscribe' => false,
);
$types = array(
'activity-comment' => $activity_comment,
'activity-comment-author' => $activity_comment_author,
'activity-at-message' => $activity_at_message,
'groups-at-message' => $groups_at_message,
'core-user-registration' => $core_user_registration,
'core-user-registration-with-blog' => $core_user_registration_with_blog,
'friends-request' => $friends_request,
'friends-request-accepted' => $friends_request_accepted,
'groups-details-updated' => $groups_details_updated,
'groups-invitation' => $groups_invitation,
'groups-member-promoted' => $groups_member_promoted,
'groups-membership-request' => $groups_membership_request,
'messages-unread' => $messages_unread,
'settings-verify-email-change' => $settings_verify_email_change,
'groups-membership-request-accepted' => $groups_membership_request_accepted,
'groups-membership-request-rejected' => $groups_membership_request_rejected,
'core-user-activation' => $core_user_activation,
'bp-members-invitation' => $members_invitation,
'members-membership-request' => $members_membership_request,
'members-membership-request-rejected' => $members_membership_request_rejected,
'groups-membership-request-accepted-by-admin' => $groups_membership_request_accepted_by_admin,
'groups-membership-request-rejected-by-admin' => $groups_membership_request_rejected_by_admin,
);
if ( $field !== 'all' ) {
return wp_list_pluck( $types, $field );
} else {
return $types;
}
}
/**
* Handles unsubscribing user from notification emails.
*
* @since 2.7.0
*/
function bp_email_unsubscribe_handler() {
$emails = bp_email_get_unsubscribe_type_schema();
$raw_email_type = ! empty( $_GET['nt'] ) ? $_GET['nt'] : '';
$raw_hash = ! empty( $_GET['nh'] ) ? $_GET['nh'] : '';
$raw_user_id = ! empty( $_GET['uid'] ) ? absint( $_GET['uid'] ) : 0;
$raw_user_email = ! empty( $_GET['uem'] ) ? $_GET['uem'] : '';
$raw_member_id = ! empty( $_GET['mid'] ) ? absint( $_GET['mid'] ) : 0;
$redirect_to = '';
$new_hash = '';
if ( ! empty( $raw_user_id ) ) {
$new_hash = hash_hmac( 'sha1', "{$raw_email_type}:{$raw_user_id}", bp_email_get_salt() );
} else if ( ! empty( $raw_user_email ) ) {
$new_hash = hash_hmac( 'sha1', "{$raw_email_type}:{$raw_user_email}", bp_email_get_salt() );
}
// Check required values.
if ( ( ! $raw_user_id && ! $raw_user_email ) || ! $raw_email_type || ! $raw_hash || ! array_key_exists( $raw_email_type, $emails ) ) {
$redirect_to = wp_login_url();
$result_msg = __( 'Something has gone wrong.', 'buddypress' );
$unsub_msg = __( 'Please log in and go to your settings to unsubscribe from notification emails.', 'buddypress' );
// Check valid hash.
} elseif ( ! hash_equals( $new_hash, $raw_hash ) ) {
$redirect_to = wp_login_url();
$result_msg = __( 'Something has gone wrong.', 'buddypress' );
$unsub_msg = __( 'Please log in and go to your settings to unsubscribe from notification emails.', 'buddypress' );
// Don't let authenticated users unsubscribe other users' email notifications.
} elseif ( is_user_logged_in() && get_current_user_id() !== $raw_user_id ) {
$result_msg = __( 'Something has gone wrong.', 'buddypress' );
$unsub_msg = __( 'Please go to your notifications settings to unsubscribe from emails.', 'buddypress' );
if ( bp_is_active( 'settings' ) ) {
$redirect_to = bp_members_get_user_url(
get_current_user_id(),
bp_members_get_path_chunks( array( bp_get_settings_slug(), 'notifications' ) )
);
} else {
$redirect_to = bp_members_get_user_url( get_current_user_id() );
}
// This is an unsubscribe request from a nonmember.
} else if ( $raw_user_email ) {
// Unsubscribe.
if ( bp_user_has_opted_out() ) {
$result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
$unsub_msg = __( 'You have already unsubscribed from all communication from this site.', 'buddypress' );
} else {
$optout_args = array(
'email_address' => $raw_user_email,
'user_id' => $raw_member_id,
'email_type' => $raw_email_type,
'date_modified' => bp_core_current_time(),
);
bp_add_optout( $optout_args );
$result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
$unsub_msg = __( 'You have been unsubscribed.', 'buddypress' );
}
// This is an unsubscribe request from a current member.
} else {
if ( bp_is_active( 'settings' ) ) {
$redirect_to = bp_members_get_user_url(
$raw_user_id,
bp_members_get_path_chunks( array( bp_get_settings_slug(), 'notifications' ) )
);
} else {
$redirect_to = bp_members_get_user_url( $raw_user_id );
}
// Unsubscribe.
$meta_key = $emails[ $raw_email_type ]['unsubscribe']['meta_key'];
bp_update_user_meta( $raw_user_id, $meta_key, 'no' );
$result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
$unsub_msg = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
}
if ( $raw_user_id && $redirect_to ) {
$message = sprintf(
'%1$s %3$s',
$result_msg,
esc_url( $redirect_to ),
esc_html( $unsub_msg )
);
// Template notices are only displayed on BP pages.
bp_core_add_message( $message );
bp_core_redirect( bp_members_get_user_url( $raw_user_id ) );
exit;
} else {
wp_die(
sprintf( '%1$s %2$s', esc_html( $unsub_msg ), esc_html( $result_msg ) ),
esc_html( $unsub_msg ),
array(
'link_url' => esc_url( home_url() ),
'link_text' => esc_html__( 'Go to website\'s home page.', 'buddypress' ),
)
);
}
}
/**
* Creates unsubscribe link for notification emails.
*
* @since 2.7.0
*
* @param string $redirect_to The URL to which the unsubscribe query string is appended.
* @param array $args {
* Used to build unsubscribe query string.
*
* @type string $notification_type Which notification type is being sent.
* @type string $user_id The ID of the user to whom the notification is sent.
* @type string $redirect_to Optional. The url to which the user will be redirected. Default is the activity directory.
* @type string $email Optional. The email address of the user to whom the notification is sent.
* }
* @return string The unsubscribe link.
*/
function bp_email_get_unsubscribe_link( $args ) {
$emails = bp_email_get_unsubscribe_type_schema();
if ( empty( $args['notification_type'] ) || ! array_key_exists( $args['notification_type'], $emails ) ) {
return wp_login_url();
}
$email_type = $args['notification_type'];
$redirect_to = ! empty( $args['redirect_to'] ) ? $args['redirect_to'] : site_url();
$user_id = (int) $args['user_id'];
// Bail out if the activity type is not un-unsubscribable.
if ( empty( $emails[ $email_type ]['unsubscribe'] ) ) {
return '';
}
$link = '';
// Case where the recipient is a member of the site.
if ( ! empty( $user_id ) ) {
$link = add_query_arg(
array(
'action' => 'unsubscribe',
'nh' => hash_hmac( 'sha1', "{$email_type}:{$user_id}", bp_email_get_salt() ),
'nt' => $args['notification_type'],
'uid' => $user_id,
),
$redirect_to
);
// Case where the recipient is not a member of the site.
} else if ( ! empty( $args['email_address'] ) ) {
$email_address = $args['email_address'];
$member_id = (int) $args['member_id'];
$link = add_query_arg(
array(
'action' => 'unsubscribe',
'nh' => hash_hmac( 'sha1', "{$email_type}:{$email_address}", bp_email_get_salt() ),
'nt' => $args['notification_type'],
'mid' => $member_id,
'uem' => $email_address,
),
$redirect_to
);
}
/**
* Filters the unsubscribe link.
*
* @since 2.7.0
*/
return apply_filters( 'bp_email_get_link', $link, $redirect_to, $args );
}
/**
* Get a persistent salt for email unsubscribe links.
*
* @since 2.7.0
*
* @return string|null Returns null if value isn't set, otherwise string.
*/
function bp_email_get_salt() {
return bp_get_option( 'bp-emails-unsubscribe-salt', null );
}
/**
* Get a list of emails for use in our unsubscribe functions.
*
* @since 2.8.0
*
* @see https://buddypress.trac.wordpress.org/ticket/7431
*
* @return array The array of email types and their schema.
*/
function bp_email_get_unsubscribe_type_schema() {
$emails = bp_email_get_type_schema( 'all' );
/**
* Filters the return of `bp_email_get_type_schema( 'all' )` for use with
* our unsubscribe functionality.
*
* @since 2.8.0
*
* @param array $emails The array of email types and their schema.
*/
return (array) apply_filters( 'bp_email_get_unsubscribe_type_schema', $emails );
}
/**
* Gets the BP Email type of a BP Email ID or object.
*
* @since 8.0.0
*
* @param int|WP_Post $email Optional. BP Email ID or BP Email object. Defaults to global $post.
* @return string The type of the BP Email object.
*/
function bp_email_get_type( $email = null ) {
$email = get_post( $email );
if ( ! $email ) {
return '';
}
$types = bp_get_object_terms( $email->ID, bp_get_email_tax_type(), array( 'fields' => 'slugs' ) );
$type = reset( $types );
return $type;
}
/**
* Get BuddyPress content allowed tags.
*
* @since 3.0.0
*
* @global array $allowedtags KSES allowed HTML elements.
* @return array BuddyPress content allowed tags.
*/
function bp_get_allowedtags() {
global $allowedtags;
return array_merge_recursive( $allowedtags, array(
'a' => array(
'aria-label' => array(),
'class' => array(),
'data-bp-tooltip' => array(),
'id' => array(),
'rel' => array(),
),
'img' => array(
'src' => array(),
'alt' => array(),
'width' => array(),
'height' => array(),
'class' => array(),
'id' => array(),
),
'span'=> array(
'class' => array(),
'data-livestamp' => array(),
),
'ul' => array(),
'ol' => array(),
'li' => array(),
) );
}
/**
* Remove script and style tags from a string.
*
* @since 3.0.1
*
* @param string $string The string to strip tags from.
* @return string The stripped tags string.
*/
function bp_strip_script_and_style_tags( $string ) {
return preg_replace( '@<(script|style)[^>]*?>.*?\\1>@si', '', $string );
}
/**
* Checks whether the current installation is "large".
*
* By default, an installation counts as "large" if there are 10000 users or more.
* Filter 'bp_is_large_install' to adjust.
*
* @since 4.1.0
*
* @return bool
*/
function bp_is_large_install() {
// Use the Multisite function if available.
if ( function_exists( 'wp_is_large_network' ) ) {
$is_large = wp_is_large_network( 'users' );
} else {
$is_large = bp_core_get_total_member_count() > 10000;
}
/**
* Filters whether the current installation is "large".
*
* @since 4.1.0
*
* @param bool $is_large True if the network is "large".
*/
return (bool) apply_filters( 'bp_is_large_install', $is_large );
}
/**
* Add a new BP_Optout.
*
* @since 8.0.0
*
* @param array $args {
* An array of arguments describing the new opt-out.
* @type string $email_address Email address of user who has opted out.
* @type int $user_id Optional. ID of user whose communication
* prompted the user to opt-out.
* @type string $email_type Optional. Name of the email type that
* prompted the user to opt-out.
* @type string $date_modified Optional. Specify a time, else now will be used.
* }
* @return false|int False on failure, ID of new (or existing) opt-out if successful.
*/
function bp_add_optout( $args = array() ) {
$optout = new BP_Optout();
$r = bp_parse_args(
$args, array(
'email_address' => '',
'user_id' => 0,
'email_type' => '',
'date_modified' => bp_core_current_time(),
),
'add_optout'
);
// Opt-outs must have an email address.
if ( empty( $r['email_address'] ) ) {
return false;
}
// Avoid creating duplicate opt-outs.
$optout_id = $optout->optout_exists(
array(
'email_address' => $r['email_address'],
'user_id' => $r['user_id'],
'email_type' => $r['email_type'],
)
);
if ( ! $optout_id ) {
// Set up the new opt-out.
$optout->email_address = $r['email_address'];
$optout->user_id = $r['user_id'];
$optout->email_type = $r['email_type'];
$optout->date_modified = $r['date_modified'];
$optout_id = $optout->save();
}
return $optout_id;
}
/**
* Find matching BP_Optouts.
*
* @since 8.0.0
*
* @see BP_Optout::get() for a description of parameters and return values.
*
* @param array $args See {@link BP_Optout::get()}.
* @return array See {@link BP_Optout::get()}.
*/
function bp_get_optouts( $args = array() ) {
$optout_class = new BP_Optout();
return $optout_class::get( $args );
}
/**
* Check an email address to see if that individual has opted out.
*
* @since 8.0.0
*
* @param string $email_address Email address to check.
* @return bool True if the user has opted out, false otherwise.
*/
function bp_user_has_opted_out( $email_address = '' ) {
$optout_class = new BP_Optout();
$optout_id = $optout_class->optout_exists(
array(
'email_address' => $email_address,
)
);
return (bool) $optout_id;
}
/**
* Delete a BP_Optout by ID.
*
* @since 8.0.0
*
* @param int $id ID of the optout to delete.
* @return bool True on success, false on failure.
*/
function bp_delete_optout_by_id( $id = 0 ) {
$optout_class = new BP_Optout();
return $optout_class::delete_by_id( $id );
}
/**
* Get the list of versions needing their deprecated functions to be loaded.
*
* @since 11.0.0
*
* @return array The list of versions needing their deprecated functions to be loaded.
*/
function bp_get_deprecated_functions_versions() {
$ignore_deprecated = null;
// Do ignore deprecated => ignore all deprecated code.
if ( defined( 'BP_IGNORE_DEPRECATED' ) && BP_IGNORE_DEPRECATED ) {
$ignore_deprecated = (bool) BP_IGNORE_DEPRECATED;
}
// Do not ignore deprecated => load all deprecated code.
if ( defined( 'BP_LOAD_DEPRECATED' ) && BP_LOAD_DEPRECATED ) {
$ignore_deprecated = ! (bool) BP_LOAD_DEPRECATED;
}
/*
* Respect the site owner's choice to ignore deprecated functions.
* Return an empty array to inform no deprecated version files should be loaded.
*/
if ( true === $ignore_deprecated ) {
return array();
}
// List of versions containing deprecated functions.
$deprecated_functions_versions = array(
1.2,
1.5,
1.6,
1.7,
1.9,
2.0,
2.1,
2.2,
2.3,
2.4,
2.5,
2.6,
2.7,
2.8,
2.9,
3.0,
4.0,
6.0,
7.0,
8.0,
9.0,
10.0,
11.0,
12.0,
);
/*
* Respect the site owner's choice to load all deprecated functions.
* Return an empty array to inform no deprecated version files should be loaded.
*/
if ( false === $ignore_deprecated ) {
return $deprecated_functions_versions;
}
/*
* Unless the `BP_IGNORE_DEPRECATED` constant is used & set to false, the development
* version of BuddyPress do not load deprecated functions.
*/
if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) {
return array();
}
/*
* If the constant is not defined, put our logic in place so that only the
* 2 last versions deprecated functions will be loaded for upgraded installs.
*/
$initial_version = (float) bp_get_initial_version();
$current_major_version = (float) bp_get_major_version( bp_get_version() );
$load_latest_deprecated = $initial_version < $current_major_version;
// New installs.
if ( ! $load_latest_deprecated ) {
// Run some additional checks if PHPUnit is running.
if ( defined( 'BP_TESTS_DIR' ) ) {
$deprecated_files = array_filter(
array_map(
function( $file ) {
if ( false !== strpos( $file, '.php' ) ) {
return (float) str_replace( '.php', '', $file );
};
},
scandir( buddypress()->plugin_dir . 'bp-core/deprecated' )
)
);
if ( array_diff( $deprecated_files, $deprecated_functions_versions ) ) {
return false;
}
}
// Only load 12.0 deprecated functions.
return array( 12.0 );
}
$index_first_major = array_search( $initial_version, $deprecated_functions_versions, true );
if ( false === $index_first_major ) {
return array_splice( $deprecated_functions_versions, -2 );
}
$latest_deprecated_functions_versions = array_splice( $deprecated_functions_versions, $index_first_major );
if ( 2 <= count( $latest_deprecated_functions_versions ) ) {
$latest_deprecated_functions_versions = array_splice( $latest_deprecated_functions_versions, -2 );
}
$index_initial_version = array_search( $initial_version, $latest_deprecated_functions_versions, true );
if ( false !== $index_initial_version ) {
unset( $latest_deprecated_functions_versions[ $index_initial_version ] );
}
return $latest_deprecated_functions_versions;
}
/**
* Get the BuddyPress Post Type site ID.
*
* @since 12.0.0
*
* @return int The site ID the BuddyPress Post Type should be registered on.
*/
function bp_get_post_type_site_id() {
$site_id = bp_get_root_blog_id();
/**
* Filter here to edit the site ID.
*
* @todo This will need to be improved to take in account
* specific configurations like multiblog.
*
* @since 12.0.0
*
* @param integer $site_id The site ID to register the post type on.
*/
return (int) apply_filters( 'bp_get_post_type_site_id', $site_id );
}
/**
* Returns registered navigation items for all or a specific component.
*
* @since 12.0.0
*
* @param string $component The component ID.
* @return array The list of registered navigation items.
*/
function bp_get_component_navigations( $component = '' ) {
$args = array();
if ( $component ) {
$args['id'] = $component;
}
$components = bp_core_get_active_components( $args, 'objects' );
$navigations = array();
foreach ( $components as $key_component => $component ) {
if ( isset( $component->main_nav['rewrite_id'] ) ) {
$navigations[ $key_component ]['main_nav'] = $component->main_nav;
}
if ( isset( $component->sub_nav ) && is_array( $component->sub_nav ) && $component->sub_nav ) {
$navigations[ $key_component ]['sub_nav'] = $component->sub_nav;
}
}
// We possibly need to move some members nav items.
if ( isset( $navigations['members']['sub_nav'], $navigations['profile']['sub_nav'] ) ) {
$profile_subnav_slugs = wp_list_pluck( $navigations['profile']['sub_nav'], 'slug' );
foreach ( $navigations['members']['sub_nav'] as $members_subnav ) {
if ( 'profile' === $members_subnav['parent_slug'] && ! in_array( $members_subnav['slug'], $profile_subnav_slugs, true ) ) {
$navigations['profile']['sub_nav'][] = $members_subnav;
}
}
}
return $navigations;
}
/**
* Get the community visibility value calculated from the
* saved visibility setting.
*
* @since 12.0.0
*
* @param string $component Whether we want the visibility for a single component
* or for all components.
*
* @return arrary|string $retval The calculated visbility settings for the site.
*/
function bp_get_community_visibility( $component = 'global' ) {
$retval = ( 'all' === $component ) ? array( 'global' => 'anyone' ) : 'anyone';
if ( 'rewrites' !== bp_core_get_query_parser() ) {
return $retval;
}
$saved_value = (array) bp_get_option( '_bp_community_visibility', array() );
// If the global value has not been set, we assume that the site is open.
if ( ! isset( $saved_value['global'] ) ) {
$saved_value['global'] = 'anyone';
}
if ( 'all' === $component ) {
// Build the component list.
$retval = array(
'global' => $saved_value['global']
);
$directory_pages = bp_core_get_directory_pages();
foreach ( $directory_pages as $component_id => $component_page ) {
if ( in_array( $component_id, array( 'register', 'activate' ), true ) ) {
continue;
}
$retval[ $component_id ] = isset( $saved_value[ $component_id ] ) ? $saved_value[ $component_id ] : $saved_value['global'];
}
} else {
// We are checking a particular component.
// Fall back to the global value if not set.
$retval = isset( $saved_value[ $component ] ) ? $saved_value[ $component ] : $saved_value['global'];
}
/**
* Filter the community visibility value calculated from the
* saved visibility setting.
*
* @since 12.0.0
*
* @param arrary|string $retval The calculated visbility settings for the site.
* @param string $component The component value to get the visibility for.
*/
return apply_filters( 'bp_get_community_visibility', $retval, $component );
}
/**
* Returns the list of unread Admin Notification IDs.
*
* @since 11.4.0
*
* @return array The list of unread Admin Notification IDs.
*/
function bp_core_get_unread_admin_notifications() {
return (array) bp_get_option( 'bp_unread_admin_notifications', array() );
}
/**
* Dismisses an Admin Notification.
*
* @since 11.4.0
*
* @param string $notification_id The Admin Notification to dismiss.
*/
function bp_core_dismiss_admin_notification( $notification_id = '' ) {
$unread = bp_core_get_unread_admin_notifications();
$remaining = array_diff( $unread, array( $notification_id ) );
bp_update_option( 'bp_unread_admin_notifications', $remaining );
}
/**
* @since 11.4.0
*
* @return array The list of Admin notifications.
*/
function bp_core_get_admin_notifications() {
$unreads = bp_core_get_unread_admin_notifications();
if ( ! $unreads ) {
return array();
}
$admin_notifications = array(
'bp100-welcome-addons' => (object) array(
'id' => 'bp100-welcome-addons',
'href' => add_query_arg(
array(
'tab' => 'bp-add-ons',
'n' => 'bp100-welcome-addons',
),
bp_get_admin_url( 'plugin-install.php' )
),
'text' => __( 'Discover BuddyPress Add-ons', 'buddypress' ),
'title' => __( 'Hello BuddyPress Add-ons!', 'buddypress' ),
'content' => __( 'Add-ons are features as Plugins or Blocks maintained by the BuddyPress development team & hosted on the WordPress.org plugins directory.', 'buddypress' ) .
__( 'Thanks to this new tab inside your Dashboard screen to add plugins, you’ll be able to find them faster and eventually contribute to beta features early to give the BuddyPress development team your feedbacks.', 'buddypress' ),
'version' => 10.0,
),
'bp114-prepare-for-rewrites' => (object) array(
'id' => 'bp114-prepare-for-rewrites',
'href' => add_query_arg(
array(
'tab' => 'bp-add-ons',
'show' => 'bp-classic',
'n' => 'bp114-prepare-for-rewrites'
),
bp_get_admin_url( 'plugin-install.php' )
),
'text' => __( 'Get The BP Classic Add-on', 'buddypress' ),
'title' => __( 'Get ready for the brand-new BP Rewrites API!', 'buddypress' ),
'content' => __( 'Our next major version (12.0.0) will introduce several large changes that could be incompatible with your site\'s configuration. To prevent problems, we\'ve built the BP Classic Add-on, which you may want to proactively install if any of the following cases:', 'buddypress' ) . '
' .
'' . __( 'Some of your BuddyPress plugins have not been updated lately.', 'buddypress' ) . '
' .
__( 'BuddyPress 12.0.0 introduces the BP Rewrites API, which completely changes the way BuddyPress URLs are built and routed. This fundamental change requires most BuddyPress plugins to update how they deal with BuddyPress URLs. If your BuddyPress plugins have not been updated in the last few months, they are probably not ready for BuddyPress 12.0.0.', 'buddypress' ) . '
' .
'' . __( 'You are still using the BP Default theme.', 'buddypress' ) . '
' .
'' . __( 'You still use a BP Legacy Widget.', 'buddypress' ) . '
' .
__( 'If any of the above items are true, we strongly advise you to install and activate the Classic Add-on before updating to BuddyPress 12.0.0.', 'buddypress' ),
'version' => 11.4,
),
'bp120-new-installs-warning' => (object) array(
'id' => 'bp120-new-installs-warning',
'href' => add_query_arg(
array(
'tab' => 'bp-add-ons',
'show' => 'bp-classic',
'n' => 'bp120-new-installs-warning'
),
bp_get_admin_url( 'plugin-install.php' )
),
'text' => __( 'Get The BP Classic Add-on', 'buddypress' ),
'title' => __( 'Thank you for installing BuddyPress 12.0!', 'buddypress' ),
'content' => __( 'BuddyPress 12.0 introduces major core changes, overhauling the way that BuddyPress builds and parses URLs.', 'buddypress' ) . '
' .
__( 'If you find that your site is not working correctly with the new version, try installing the new BP Classic Add-on that adds backwards compatibility for plugins and themes that have not yet been updated to work with BuddyPress 12.0.', 'buddypress' ),
'version' => 12.0,
),
);
// Only keep unread notifications.
foreach ( array_keys( $admin_notifications ) as $notification_id ) {
if ( ! in_array( $notification_id, $unreads, true ) ) {
unset( $admin_notifications[ $notification_id ] );
}
}
return $admin_notifications;
}