diff --git src/bp-core/admin/bp-core-admin-settings.php src/bp-core/admin/bp-core-admin-settings.php
index 2bab95e9e..cf8d43468 100644
--- src/bp-core/admin/bp-core-admin-settings.php
+++ src/bp-core/admin/bp-core-admin-settings.php
@@ -147,42 +147,25 @@ function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
return $value ? 0 : 1;
}
-/** XProfile ******************************************************************/
+/** Members *******************************************************************/
/**
* Profile settings section description for the settings page.
*
* @since 1.6.0
*/
-function bp_admin_setting_callback_xprofile_section() { }
-
-/**
- * Enable BP->WP profile syncing field.
- *
- * @since 1.6.0
- *
- */
-function bp_admin_setting_callback_profile_sync() {
-?>
-
- />
-
-
-
-
/>
-
@@ -198,6 +182,30 @@ function bp_admin_setting_callback_cover_image_uploads() {
WP profile syncing field.
+ *
+ * @since 1.6.0
+ *
+ */
+function bp_admin_setting_callback_profile_sync() {
+?>
+
+ />
+
+
+ 0, 'height' => 0 );
@@ -1093,8 +1093,8 @@ function bp_attachments_cover_image_is_edit() {
$retval = false;
$current_component = bp_current_component();
- if ( bp_is_active( 'xprofile' ) && bp_is_current_component( 'xprofile' ) ) {
- $current_component = 'xprofile';
+ if ( bp_is_user() ) {
+ $current_component = 'members';
}
if ( ! bp_is_active( $current_component, 'cover_image' ) ) {
@@ -1161,7 +1161,7 @@ function bp_attachments_get_group_has_cover_image( $group_id = 0 ) {
*
* @param array $args {
* @type string $file The absolute path to the image. Required.
- * @type string $component The component for the object (eg: groups, xprofile). Required.
+ * @type string $component The component for the object (eg: groups, members). Required.
* @type string $cover_image_dir The Cover image dir to write the image into. Required.
* }
* @param BP_Attachment_Cover_Image|null $cover_image_class The class to use to fit the cover image.
@@ -1282,7 +1282,7 @@ function bp_attachments_cover_image_ajax_upload() {
// Member's cover image.
if ( 'user' === $bp_params['object'] ) {
- $object_data = array( 'dir' => 'members', 'component' => 'xprofile' );
+ $object_data = array( 'dir' => 'members', 'component' => 'members' );
if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) {
$needs_reset = array( 'key' => 'displayed_user', 'value' => $bp->displayed_user );
@@ -1406,9 +1406,9 @@ function bp_attachments_cover_image_ajax_upload() {
/**
* Fires if the new cover image was successfully uploaded.
*
- * The dynamic portion of the hook will be xprofile in case of a user's
+ * The dynamic portion of the hook will be members 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
+ * Use add_action( 'members_cover_image_uploaded' ) to run your specific
* code once the user has set his cover image.
*
* @since 2.4.0
@@ -1466,7 +1466,7 @@ function bp_attachments_cover_image_ajax_delete() {
// Set object for the user's case.
if ( 'user' === $args['object'] ) {
- $component = 'xprofile';
+ $component = 'members';
$dir = 'members';
// Set it for any other cases.
@@ -1480,9 +1480,9 @@ function bp_attachments_cover_image_ajax_delete() {
/**
* Fires if the cover image was successfully deleted.
*
- * The dynamic portion of the hook will be xprofile in case of a user's
+ * The dynamic portion of the hook will be members 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_deleted' ) to run your specific
+ * Use add_action( 'members_cover_image_deleted' ) to run your specific
* code once the user has deleted his cover image.
*
* @since 2.8.0
diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php
index 1c6bd5823..2699dfe8d 100644
--- src/bp-core/bp-core-avatars.php
+++ src/bp-core/bp-core-avatars.php
@@ -992,8 +992,8 @@ function bp_avatar_ajax_upload() {
$bp_params['upload_dir_filter'] = '';
$needs_reset = array();
- if ( 'user' === $bp_params['object'] && bp_is_active( 'xprofile' ) ) {
- $bp_params['upload_dir_filter'] = 'xprofile_avatar_upload_dir';
+ if ( 'user' === $bp_params['object'] && bp_is_active( 'members' ) ) {
+ $bp_params['upload_dir_filter'] = 'bp_members_avatar_upload_dir';
if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) {
$needs_reset = array( 'key' => 'displayed_user', 'value' => $bp->displayed_user );
@@ -1284,20 +1284,19 @@ function bp_avatar_ajax_set() {
'item_id' => $avatar_data['item_id'],
);
+ /** This action is documented in wp-includes/deprecated.php */
+ do_action_deprecated( 'xprofile_avatar_uploaded', array( (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data ), '6.0.0', 'bp_members_avatar_uploaded' );
+
/**
* Fires if the new avatar was successfully captured.
*
- * @since 1.1.0 Used to inform the avatar was successfully cropped
- * @since 2.3.4 Add two new parameters to inform about the user id and
- * about the way the avatar was set (eg: 'crop' or 'camera')
- * Move the action at the right place, once the avatar is set
- * @since 2.8.0 Added the `$avatar_data` parameter.
+ * @since 6.0.0
*
* @param string $item_id Inform about the user id the avatar was set for.
* @param string $type Inform about the way the avatar was set ('camera').
* @param array $avatar_data Array of parameters passed to the avatar handler.
*/
- do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data );
+ do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data );
wp_send_json_success( $return );
}
@@ -1342,8 +1341,11 @@ function bp_avatar_ajax_set() {
);
if ( 'user' === $avatar_data['object'] ) {
+ /** This action is documented in wp-includes/deprecated.php */
+ do_action_deprecated( 'xprofile_avatar_uploaded', array( (int) $avatar_data['item_id'], $avatar_data['type'], $r ), '6.0.0', 'bp_members_avatar_uploaded' );
+
/** This action is documented in bp-core/bp-core-avatars.php */
- do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );
+ do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );
} elseif ( 'group' === $avatar_data['object'] ) {
/** This action is documented in bp-groups/bp-groups-screens.php */
do_action( 'groups_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );
@@ -1923,11 +1925,6 @@ add_action( 'bp_parse_query', 'bp_core_avatar_reset_query', 10, 1 );
function bp_avatar_is_front_edit() {
$retval = false;
- // No need to carry on if the current WordPress version is not supported.
- if ( ! bp_attachments_is_wp_version_supported() ) {
- return $retval;
- }
-
if ( bp_is_user_change_avatar() && 'crop-image' !== bp_get_avatar_admin_step() ) {
$retval = ! bp_core_get_root_option( 'bp-disable-avatar-uploads' );
}
diff --git src/bp-core/bp-core-cssjs.php src/bp-core/bp-core-cssjs.php
index de96cf465..5e5691f51 100644
--- src/bp-core/bp-core-cssjs.php
+++ src/bp-core/bp-core-cssjs.php
@@ -442,7 +442,7 @@ function bp_add_cover_image_inline_css( $return = false ) {
}
$cover_image_object = array(
- 'component' => 'xprofile',
+ 'component' => 'members',
'object' => $bp->displayed_user
);
} elseif ( bp_is_group() ) {
@@ -479,7 +479,7 @@ function bp_add_cover_image_inline_css( $return = false ) {
$object_dir = $cover_image_object['component'];
- if ( 'xprofile' === $object_dir ) {
+ if ( 'members' === $object_dir ) {
$object_dir = 'members';
}
diff --git src/bp-core/bp-core-theme-compatibility.php src/bp-core/bp-core-theme-compatibility.php
index e8fbfa455..f68254065 100644
--- src/bp-core/bp-core-theme-compatibility.php
+++ src/bp-core/bp-core-theme-compatibility.php
@@ -464,7 +464,7 @@ function bp_register_theme_compat_default_features() {
bp_set_theme_compat_feature( 'legacy', array(
'name' => 'cover_image',
'settings' => array(
- 'components' => array( 'xprofile', 'groups' ),
+ 'components' => array( 'members', 'groups' ),
'width' => $bp_content_width,
'height' => $top_offset + round( $avatar_height / 2 ),
'callback' => 'bp_legacy_theme_cover_image',
diff --git src/bp-core/classes/class-bp-admin.php src/bp-core/classes/class-bp-admin.php
index 5631f1753..33b36761d 100644
--- src/bp-core/classes/class-bp-admin.php
+++ src/bp-core/classes/class-bp-admin.php
@@ -394,6 +394,21 @@ class BP_Admin {
add_settings_field( '_bp_theme_package_id', __( 'Template Pack', 'buddypress' ), 'bp_admin_setting_callback_theme_package_id', 'buddypress', 'bp_main', array( 'label_for' => '_bp_theme_package_id' ) );
register_setting( 'buddypress', '_bp_theme_package_id', 'sanitize_text_field' );
+ /* Members Section **************************************************/
+
+ // Add the main section.
+ add_settings_section( 'bp_members', _x( 'Members Settings', 'BuddyPress setting tab', 'buddypress' ), 'bp_admin_setting_callback_members_section', 'buddypress' );
+
+ // Avatars.
+ add_settings_field( 'bp-disable-avatar-uploads', __( 'Profile Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', 'bp_members' );
+ register_setting( 'buddypress', 'bp-disable-avatar-uploads', 'intval' );
+
+ // Cover images.
+ if ( bp_is_active( 'members', 'cover_image' ) ) {
+ add_settings_field( 'bp-disable-cover-image-uploads', __( 'Cover Image Uploads', 'buddypress' ), 'bp_admin_setting_callback_cover_image_uploads', 'buddypress', 'bp_members' );
+ register_setting( 'buddypress', 'bp-disable-cover-image-uploads', 'intval' );
+ }
+
/* XProfile Section **************************************************/
if ( bp_is_active( 'xprofile' ) ) {
@@ -401,16 +416,6 @@ class BP_Admin {
// Add the main section.
add_settings_section( 'bp_xprofile', _x( 'Profile Settings', 'BuddyPress setting tab', 'buddypress' ), 'bp_admin_setting_callback_xprofile_section', 'buddypress' );
- // Avatars.
- add_settings_field( 'bp-disable-avatar-uploads', __( 'Profile Photo Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', 'bp_xprofile' );
- register_setting( 'buddypress', 'bp-disable-avatar-uploads', 'intval' );
-
- // Cover images.
- if ( bp_is_active( 'xprofile', 'cover_image' ) ) {
- add_settings_field( 'bp-disable-cover-image-uploads', __( 'Cover Image Uploads', 'buddypress' ), 'bp_admin_setting_callback_cover_image_uploads', 'buddypress', 'bp_xprofile' );
- register_setting( 'buddypress', 'bp-disable-cover-image-uploads', 'intval' );
- }
-
// Profile sync setting.
add_settings_field( 'bp-disable-profile-sync', __( 'Profile Syncing', 'buddypress' ), 'bp_admin_setting_callback_profile_sync', 'buddypress', 'bp_xprofile' );
register_setting ( 'buddypress', 'bp-disable-profile-sync', 'intval' );
diff --git src/bp-core/deprecated/6.0.php src/bp-core/deprecated/6.0.php
new file mode 100644
index 000000000..cf75d5b8e
--- /dev/null
+++ src/bp-core/deprecated/6.0.php
@@ -0,0 +1,63 @@
+current_member_type );
}
+
+/**
+ * Setup the avatar upload directory for a user.
+ *
+ * @since 6.0.0
+ *
+ * @param string $directory The root directory name. Optional.
+ * @param int $user_id The user ID. Optional.
+ * @return array Array containing the path, URL, and other helpful settings.
+ */
+function bp_members_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {
+
+ // Use displayed user if no user ID was passed.
+ if ( empty( $user_id ) ) {
+ $user_id = bp_displayed_user_id();
+ }
+
+ // Failsafe against accidentally nooped $directory parameter.
+ if ( empty( $directory ) ) {
+ $directory = 'avatars';
+ }
+
+ $path = bp_core_avatar_upload_path() . '/' . $directory. '/' . $user_id;
+ $newbdir = $path;
+ $newurl = bp_core_avatar_url() . '/' . $directory. '/' . $user_id;
+ $newburl = $newurl;
+ $newsubdir = '/' . $directory. '/' . $user_id;
+
+ /**
+ * Filters the avatar upload directory for a user.
+ *
+ * @since 6.0.0
+ *
+ * @param array $value Array containing the path, URL, and other helpful settings.
+ */
+ return apply_filters( 'bp_members_avatar_upload_dir', array(
+ 'path' => $path,
+ 'url' => $newurl,
+ 'subdir' => $newsubdir,
+ 'basedir' => $newbdir,
+ 'baseurl' => $newburl,
+ 'error' => false
+ ) );
+}
diff --git src/bp-members/bp-members-template.php src/bp-members/bp-members-template.php
index 17701f866..787487802 100644
--- src/bp-members/bp-members-template.php
+++ src/bp-members/bp-members-template.php
@@ -1510,7 +1510,7 @@ function bp_get_displayed_user_nav() {
* False otherwise
*/
function bp_displayed_user_use_cover_image_header() {
- return (bool) bp_is_active( 'xprofile', 'cover_image' ) && ! bp_disable_cover_image_uploads() && bp_attachments_is_wp_version_supported();
+ return (bool) bp_is_active( 'members', 'cover_image' ) && ! bp_disable_cover_image_uploads();
}
/** Avatars *******************************************************************/
@@ -2645,3 +2645,34 @@ function bp_members_component_link( $component, $action = '', $query_args = '',
if ( !empty( $url ) )
return $url;
}
+
+
+/**
+ * Render an avatar delete link.
+ *
+ * @since 1.1.0
+ * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file.
+ */
+function bp_avatar_delete_link() {
+ echo bp_get_avatar_delete_link();
+}
+
+ /**
+ * Return an avatar delete link.
+ *
+ * @since 1.1.0
+ * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file.
+ *
+ * @return string
+ */
+ function bp_get_avatar_delete_link() {
+
+ /**
+ * Filters the link used for deleting an avatar.
+ *
+ * @since 1.1.0
+ *
+ * @param string $value Nonced URL used for deleting an avatar.
+ */
+ return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_profile_slug() . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) );
+ }
diff --git src/bp-members/classes/class-bp-members-admin.php src/bp-members/classes/class-bp-members-admin.php
index ad00eafdb..964b7a25c 100644
--- src/bp-members/classes/class-bp-members-admin.php
+++ src/bp-members/classes/class-bp-members-admin.php
@@ -642,6 +642,22 @@ class BP_Members_Admin {
*/
$js = apply_filters( 'bp_members_admin_js', $js );
wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
+
+ if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && buddypress()->avatar->show_avatars ) {
+ /**
+ * Get Thickbox.
+ *
+ * We cannot simply use add_thickbox() here as WordPress is not playing
+ * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
+ * Using media-upload might be interesting in the future for the send to editor stuff
+ * and we make sure the tb_window is wide enough
+ */
+ wp_enqueue_style ( 'thickbox' );
+ wp_enqueue_script( 'media-upload' );
+
+ // Get Avatar Uploader.
+ bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
+ }
}
/**
@@ -723,6 +739,7 @@ class BP_Members_Admin {
* help, and setting up screen options.
*
* @since 2.0.0
+ * @since 6.0.0 The `delete_avatar` action is now managed into this method.
*/
public function user_admin_load() {
@@ -819,16 +836,31 @@ class BP_Members_Admin {
$display_name = __( 'Member', 'buddypress' );
}
+ // Set the screen id.
+ $screen_id = get_current_screen()->id;
+
// User Stat metabox.
add_meta_box(
'bp_members_admin_user_stats',
sprintf( _x( "%s's Stats", 'members user-admin edit screen', 'buddypress' ), $display_name ),
array( $this, 'user_admin_stats_metabox' ),
- get_current_screen()->id,
+ $screen_id,
sanitize_key( $this->stats_metabox->context ),
sanitize_key( $this->stats_metabox->priority )
);
+ if ( buddypress()->avatar->show_avatars ) {
+ // Avatar Metabox.
+ add_meta_box(
+ 'bp_members_user_admin_avatar',
+ _x( 'Profile Photo', 'members user-admin edit screen', 'buddypress' ),
+ array( $this, 'user_admin_avatar_metabox' ),
+ $screen_id,
+ 'side',
+ 'low'
+ );
+ }
+
// Member Type metabox. Only added if member types have been registered.
$member_types = bp_get_member_types();
if ( ! empty( $member_types ) ) {
@@ -836,7 +868,7 @@ class BP_Members_Admin {
'bp_members_admin_member_type',
_x( 'Member Type', 'members user-admin edit screen', 'buddypress' ),
array( $this, 'user_admin_member_type_metabox' ),
- get_current_screen()->id,
+ $screen_id,
'side',
'core'
);
@@ -874,6 +906,22 @@ class BP_Members_Admin {
bp_core_redirect( $redirect_to );
+ // Eventually delete avatar.
+ } elseif ( 'delete_avatar' === $doaction ) {
+
+ // Check the nonce.
+ check_admin_referer( 'delete_avatar' );
+
+ $redirect_to = remove_query_arg( '_wpnonce', $redirect_to );
+
+ if ( bp_core_delete_existing_avatar( array( 'item_id' => $user_id ) ) ) {
+ $redirect_to = add_query_arg( 'updated', 'avatar', $redirect_to );
+ } else {
+ $redirect_to = add_query_arg( 'error', 'avatar', $redirect_to );
+ }
+
+ bp_core_redirect( $redirect_to );
+
// Update other stuff once above ones are done.
} else {
$this->redirect = $redirect_to;
@@ -1173,6 +1221,61 @@ class BP_Members_Admin {
ID ) ) {
+ return;
+ } ?>
+
+
+
+ $user->ID,
+ 'object' => 'user',
+ 'type' => 'full',
+ 'title' => $user->display_name
+ ) ); ?>
+
+ ID ) ) :
+
+ $query_args = array(
+ 'user_id' => $user->ID,
+ 'action' => 'delete_avatar'
+ );
+
+ if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
+ $wp_http_referer = wp_unslash( $_REQUEST['wp_http_referer'] );
+ $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $wp_http_referer );
+ $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
+ $query_args['wp_http_referer'] = urlencode( $wp_http_referer );
+ }
+
+ $community_url = add_query_arg( $query_args, $this->edit_profile_url );
+ $delete_link = wp_nonce_url( $community_url, 'delete_avatar' ); ?>
+
+
+
+
+
+
+
+
+
+
+
+ path . 'bp-members/screens/profile.php';
+
+ // Action - Delete avatar.
+ if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
+ require $this->path . 'bp-members/actions/delete-avatar.php';
+ }
+
+ // Sub-nav items.
+ if ( is_user_logged_in() &&
+ in_array( bp_current_action(), array( 'change-avatar', 'change-cover-image' ), true )
+ ) {
+ require $this->path . 'bp-members/screens/' . bp_current_action() . '.php';
+ }
}
// Members - Theme compatibility.
@@ -288,6 +300,49 @@ class BP_Members_Component extends BP_Component {
}
}
+ /**
+ * Get the Avatar and Cover image subnavs.
+ *
+ * @since 6.0.0
+ *
+ * @return array The Avatar and Cover image subnavs.
+ */
+ public function get_avatar_cover_image_subnavs() {
+ $subnavs = array();
+
+ $access = bp_core_can_edit_settings();
+ $slug = bp_get_profile_slug();
+ $profile_link = bp_get_members_component_link( $slug );
+
+ // Change Avatar.
+ if ( buddypress()->avatar->show_avatars ) {
+ $subnavs[] = array(
+ 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ),
+ 'slug' => 'change-avatar',
+ 'parent_url' => $profile_link,
+ 'parent_slug' => $slug,
+ 'screen_function' => 'bp_members_screen_change_avatar',
+ 'position' => 30,
+ 'user_has_access' => $access
+ );
+ }
+
+ // Change Cover image.
+ if ( bp_displayed_user_use_cover_image_header() ) {
+ $subnavs[] = array(
+ 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ),
+ 'slug' => 'change-cover-image',
+ 'parent_url' => $profile_link,
+ 'parent_slug' => $slug,
+ 'screen_function' => 'bp_members_screen_change_cover_image',
+ 'position' => 40,
+ 'user_has_access' => $access
+ );
+ }
+
+ return $subnavs;
+ }
+
/**
* Set up fall-back component navigation if XProfile is inactive.
*
@@ -311,6 +366,7 @@ class BP_Members_Component extends BP_Component {
// Bail if XProfile component is active and there's no custom front page for the user.
if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) {
+ add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) );
return;
}
@@ -339,6 +395,15 @@ class BP_Members_Component extends BP_Component {
'default_subnav_slug' => 'public',
'item_css_id' => buddypress()->profile->id
);
+
+ /**
+ * The xProfile component is active.
+ *
+ * We need to make sure the Change Avatar and Change Cover Image subnavs are
+ * added just like it was the case before.
+ */
+ } else {
+ add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) );
}
/**
@@ -393,7 +458,11 @@ class BP_Members_Component extends BP_Component {
*/
} else {
$main_nav = $this->main_nav;
- $sub_nav[] = $this->sub_nav;
+ $sub_nav = array( $this->sub_nav );
+
+ if ( ! $is_xprofile_active ) {
+ $sub_nav = array_merge( $sub_nav, $this->get_avatar_cover_image_subnavs() );
+ }
}
@@ -417,6 +486,129 @@ class BP_Members_Component extends BP_Component {
// Add the sub nav item.
bp_core_new_subnav_item( $this->sub_nav, 'members' );
+
+ // Get the Avatar and cover image subnavs.
+ $this->setup_xprofile_nav();
+ }
+
+ /**
+ * Set up the xProfile nav.
+ *
+ * @since 6.0.0
+ */
+ public function setup_xprofile_nav() {
+ // Get the Avatar and cover image subnavs.
+ $items = $this->get_avatar_cover_image_subnavs();
+
+ foreach ( $items as $item ) {
+ bp_core_new_subnav_item( $item, 'members' );
+ }
+ }
+
+ /**
+ * Get the Avatar and Cover image admin navs.
+ *
+ * @since 6.0.0
+ *
+ * @param string $admin_bar_menu_id The Admin bar menu ID to attach sub items to.
+ * @return array The Avatar and Cover image admin navs.
+ */
+ public function get_avatar_cover_image_admin_navs( $admin_bar_menu_id = '' ) {
+ $wp_admin_nav = array();
+ $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
+
+ if ( ! $admin_bar_menu_id ) {
+ $admin_bar_menu_id = $this->id;
+ }
+
+ // Edit Avatar.
+ if ( buddypress()->avatar->show_avatars ) {
+ $wp_admin_nav[] = array(
+ 'parent' => 'my-account-' . $admin_bar_menu_id,
+ 'id' => 'my-account-' . $admin_bar_menu_id . '-change-avatar',
+ 'title' => _x( 'Change Profile Photo', 'My Account Profile sub nav', 'buddypress' ),
+ 'href' => trailingslashit( $profile_link . 'change-avatar' ),
+ 'position' => 30
+ );
+ }
+
+ // Edit Cover Image
+ if ( bp_displayed_user_use_cover_image_header() ) {
+ $wp_admin_nav[] = array(
+ 'parent' => 'my-account-' . $admin_bar_menu_id,
+ 'id' => 'my-account-' . $admin_bar_menu_id . '-change-cover-image',
+ 'title' => _x( 'Change Cover Image', 'My Account Profile sub nav', 'buddypress' ),
+ 'href' => trailingslashit( $profile_link . 'change-cover-image' ),
+ 'position' => 40
+ );
+ }
+
+ return $wp_admin_nav;
+ }
+
+ /**
+ * Set up the Admin Bar.
+ *
+ * @since 6.0.0
+ *
+ * @param array $wp_admin_nav Admin Bar items.
+ */
+ public function setup_admin_bar( $wp_admin_nav = array() ) {
+ // Menus for logged in user.
+ if ( is_user_logged_in() ) {
+ $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
+
+ if ( ! bp_is_active( 'xprofile' ) ) {
+ // Add the "Profile" sub menu.
+ $wp_admin_nav[] = array(
+ 'parent' => buddypress()->my_account_menu_id,
+ 'id' => 'my-account-' . $this->id,
+ 'title' => _x( 'Profile', 'My Account Profile', 'buddypress' ),
+ 'href' => $profile_link
+ );
+
+ // View Profile.
+ $wp_admin_nav[] = array(
+ 'parent' => 'my-account-' . $this->id,
+ 'id' => 'my-account-' . $this->id . '-public',
+ 'title' => _x( 'View', 'My Account Profile sub nav', 'buddypress' ),
+ 'href' => $profile_link,
+ 'position' => 10
+ );
+
+ $wp_admin_nav = array_merge( $wp_admin_nav, $this->get_avatar_cover_image_admin_navs() );
+
+ /**
+ * The xProfile is active.
+ *
+ * Add the Change Avatar and Change Cover Image Admin Bar items
+ * to the xProfile Admin Bar Menu.
+ */
+ } else {
+ add_filter( 'bp_xprofile_admin_nav', array( $this, 'setup_xprofile_admin_nav' ), 2 );
+ }
+ }
+
+ parent::setup_admin_bar( $wp_admin_nav );
+ }
+
+ /**
+ * Adds "Profile > Change Avatar" & "Profile > Change Cover Image" subnav item
+ * under the "Profile" adminbar menu.
+ *
+ * @since 6.0.0
+ *
+ * @param array $wp_admin_nav The Profile adminbar nav array.
+ * @return array
+ */
+ public function setup_xprofile_admin_nav( $wp_admin_nav ) {
+ $items = $this->get_avatar_cover_image_admin_navs( buddypress()->profile->id );
+
+ if ( $items ) {
+ $wp_admin_nav = array_merge( $wp_admin_nav, $items );
+ }
+
+ return $wp_admin_nav;
}
/**
diff --git src/bp-xprofile/screens/change-avatar.php src/bp-members/screens/change-avatar.php
similarity index 56%
rename from src/bp-xprofile/screens/change-avatar.php
rename to src/bp-members/screens/change-avatar.php
index dc9da918a..5c4bcf440 100644
--- src/bp-xprofile/screens/change-avatar.php
+++ src/bp-members/screens/change-avatar.php
@@ -1,20 +1,18 @@
Change Avatar" screen handler
+ * Members: Change Avatar screen handler
*
* @package BuddyPress
- * @subpackage XProfileScreens
- * @since 3.0.0
+ * @subpackage MembersScreens
+ * @since 6.0.0
*/
/**
- * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
- *
- * @since 1.0.0
+ * Handle the display of the profile Change Avatar page by loading the correct template file.
*
+ * @since 6.0.0
*/
-function xprofile_screen_change_avatar() {
-
+function bp_members_screen_change_avatar() {
// Bail if not the correct screen.
if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
return false;
@@ -40,7 +38,7 @@ function xprofile_screen_change_avatar() {
check_admin_referer( 'bp_avatar_upload' );
// Pass the file to the avatar upload handler.
- if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {
+ if ( bp_core_avatar_handle_upload( $_FILES, 'bp_members_avatar_upload_dir' ) ) {
$bp->avatar_admin->step = 'crop-image';
// Make sure we include the jQuery jCrop file for image cropping.
@@ -67,35 +65,43 @@ function xprofile_screen_change_avatar() {
bp_core_add_message( __( 'There was a problem cropping your profile photo.', 'buddypress' ), 'error' );
} else {
+ /** This action is documented in wp-includes/deprecated.php */
+ do_action_deprecated( 'xprofile_avatar_uploaded', array( (int) $args['item_id'], 'crop' ), '6.0.0', 'bp_members_avatar_uploaded' );
+
/**
* Fires right before the redirect, after processing a new avatar.
*
- * @since 1.1.0
- * @since 2.3.4 Add two new parameters to inform about the user id and
- * about the way the avatar was set (eg: 'crop' or 'camera').
+ * @since 6.0.0
*
* @param string $item_id Inform about the user id the avatar was set for.
* @param string $value Inform about the way the avatar was set ('crop').
*/
- do_action( 'xprofile_avatar_uploaded', (int) $args['item_id'], 'crop' );
+ do_action( 'bp_members_avatar_uploaded', (int) $args['item_id'], 'crop' );
+
bp_core_add_message( __( 'Your new profile photo was uploaded successfully.', 'buddypress' ) );
bp_core_redirect( bp_displayed_user_domain() );
}
}
+ /** This action is documented in wp-includes/deprecated.php */
+ do_action_deprecated( 'xprofile_screen_change_avatar', array(), '6.0.0', 'bp_members_screen_change_avatar' );
+
/**
- * Fires right before the loading of the XProfile change avatar screen template file.
+ * Fires right before the loading of the Member Change Avatar screen template file.
*
- * @since 1.0.0
+ * @since 6.0.0
*/
- do_action( 'xprofile_screen_change_avatar' );
+ do_action( 'bp_members_screen_change_avatar' );
+
+ /** This filter is documented in wp-includes/deprecated.php */
+ $template = apply_filters_deprecated( 'xprofile_template_change_avatar', array( 'members/single/home' ), '6.0.0', 'bp_members_template_change_avatar' );
/**
- * Filters the template to load for the XProfile change avatar screen.
+ * Filters the template to load for the Member Change Avatar page screen.
*
- * @since 1.0.0
+ * @since 6.0.0
*
- * @param string $template Path to the XProfile change avatar template to load.
+ * @param string $template Path to the Member template to load.
*/
- bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/home' ) );
-}
\ No newline at end of file
+ bp_core_load_template( apply_filters( 'bp_members_template_change_avatar', $template ) );
+}
diff --git src/bp-members/screens/change-cover-image.php src/bp-members/screens/change-cover-image.php
new file mode 100644
index 000000000..3cd69acf7
--- /dev/null
+++ src/bp-members/screens/change-cover-image.php
@@ -0,0 +1,42 @@
+id, array(
'name' => 'cover_image',
'settings' => array(
- 'components' => array( 'xprofile', 'groups' ),
+ 'components' => array( 'members', 'groups' ),
'width' => $width,
'height' => $top_offset + round( $avatar_height / 2 ),
'callback' => 'bp_nouveau_theme_cover_image',
diff --git src/bp-xprofile/bp-xprofile-functions.php src/bp-xprofile/bp-xprofile-functions.php
index 2ba68eaf8..d32e3668d 100644
--- src/bp-xprofile/bp-xprofile-functions.php
+++ src/bp-xprofile/bp-xprofile-functions.php
@@ -705,52 +705,6 @@ function xprofile_override_user_fullnames() {
}
add_action( 'bp_setup_globals', 'xprofile_override_user_fullnames', 100 );
-/**
- * Setup the avatar upload directory for a user.
- *
- * @since 1.0.0
- *
- * @package BuddyPress Core
- *
- * @param string $directory The root directory name. Optional.
- * @param int $user_id The user ID. Optional.
- * @return array Array containing the path, URL, and other helpful settings.
- */
-function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {
-
- // Use displayed user if no user ID was passed.
- if ( empty( $user_id ) ) {
- $user_id = bp_displayed_user_id();
- }
-
- // Failsafe against accidentally nooped $directory parameter.
- if ( empty( $directory ) ) {
- $directory = 'avatars';
- }
-
- $path = bp_core_avatar_upload_path() . '/' . $directory. '/' . $user_id;
- $newbdir = $path;
- $newurl = bp_core_avatar_url() . '/' . $directory. '/' . $user_id;
- $newburl = $newurl;
- $newsubdir = '/' . $directory. '/' . $user_id;
-
- /**
- * Filters the avatar upload directory for a user.
- *
- * @since 1.1.0
- *
- * @param array $value Array containing the path, URL, and other helpful settings.
- */
- return apply_filters( 'xprofile_avatar_upload_dir', array(
- 'path' => $path,
- 'url' => $newurl,
- 'subdir' => $newsubdir,
- 'basedir' => $newbdir,
- 'baseurl' => $newburl,
- 'error' => false
- ) );
-}
-
/**
* When search_terms are passed to BP_User_Query, search against xprofile fields.
*
diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php
index 6f5a3c10a..7e8556775 100644
--- src/bp-xprofile/bp-xprofile-template.php
+++ src/bp-xprofile/bp-xprofile-template.php
@@ -1204,34 +1204,6 @@ function bp_current_profile_group_id() {
return (int) apply_filters( 'bp_get_current_profile_group_id', $profile_group_id );
}
-/**
- * Render an avatar delete link.
- *
- * @since 1.1.0
- */
-function bp_avatar_delete_link() {
- echo bp_get_avatar_delete_link();
-}
-
- /**
- * Return an avatar delete link.
- *
- * @since 1.1.0
- *
- * @return string
- */
- function bp_get_avatar_delete_link() {
-
- /**
- * Filters the link used for deleting an avatar.
- *
- * @since 1.1.0
- *
- * @param string $value Nonced URL used for deleting an avatar.
- */
- return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_profile_slug() . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) );
- }
-
/**
* Render an edit profile button.
*
diff --git src/bp-xprofile/classes/class-bp-xprofile-component.php src/bp-xprofile/classes/class-bp-xprofile-component.php
index b43879d34..439c02886 100644
--- src/bp-xprofile/classes/class-bp-xprofile-component.php
+++ src/bp-xprofile/classes/class-bp-xprofile-component.php
@@ -112,16 +112,9 @@ class BP_XProfile_Component extends BP_Component {
if ( bp_is_profile_component() ) {
require $this->path . 'bp-xprofile/screens/public.php';
- // Action - Delete avatar.
- if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
- require $this->path . 'bp-xprofile/actions/delete-avatar.php';
- }
-
// Sub-nav items.
- if ( is_user_logged_in() &&
- in_array( bp_current_action(), array( 'edit', 'change-avatar', 'change-cover-image' ), true )
- ) {
- require $this->path . 'bp-xprofile/screens/' . bp_current_action() . '.php';
+ if ( is_user_logged_in() && 'edit' === bp_current_action() ) {
+ require $this->path . 'bp-xprofile/screens/edit.php';
}
}
@@ -278,32 +271,6 @@ class BP_XProfile_Component extends BP_Component {
'user_has_access' => $access
);
- // Change Avatar.
- if ( buddypress()->avatar->show_avatars ) {
- $sub_nav[] = array(
- 'name' => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ),
- 'slug' => 'change-avatar',
- 'parent_url' => $profile_link,
- 'parent_slug' => $slug,
- 'screen_function' => 'xprofile_screen_change_avatar',
- 'position' => 30,
- 'user_has_access' => $access
- );
- }
-
- // Change Cover image.
- if ( bp_displayed_user_use_cover_image_header() ) {
- $sub_nav[] = array(
- 'name' => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ),
- 'slug' => 'change-cover-image',
- 'parent_url' => $profile_link,
- 'parent_slug' => $slug,
- 'screen_function' => 'xprofile_screen_change_cover_image',
- 'position' => 40,
- 'user_has_access' => $access
- );
- }
-
// The Settings > Profile nav item can only be set up after
// the Settings component has run its own nav routine.
add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) );
@@ -387,27 +354,6 @@ class BP_XProfile_Component extends BP_Component {
'href' => trailingslashit( $profile_link . 'edit' ),
'position' => 20
);
-
- // Edit Avatar.
- if ( buddypress()->avatar->show_avatars ) {
- $wp_admin_nav[] = array(
- 'parent' => 'my-account-' . $this->id,
- 'id' => 'my-account-' . $this->id . '-change-avatar',
- 'title' => _x( 'Change Profile Photo', 'My Account Profile sub nav', 'buddypress' ),
- 'href' => trailingslashit( $profile_link . 'change-avatar' ),
- 'position' => 30
- );
- }
-
- if ( bp_displayed_user_use_cover_image_header() ) {
- $wp_admin_nav[] = array(
- 'parent' => 'my-account-' . $this->id,
- 'id' => 'my-account-' . $this->id . '-change-cover-image',
- 'title' => _x( 'Change Cover Image', 'My Account Profile sub nav', 'buddypress' ),
- 'href' => trailingslashit( $profile_link . 'change-cover-image' ),
- 'position' => 40
- );
- }
}
parent::setup_admin_bar( $wp_admin_nav );
diff --git src/bp-xprofile/classes/class-bp-xprofile-user-admin.php src/bp-xprofile/classes/class-bp-xprofile-user-admin.php
index f24a4e047..73db1afec 100644
--- src/bp-xprofile/classes/class-bp-xprofile-user-admin.php
+++ src/bp-xprofile/classes/class-bp-xprofile-user-admin.php
@@ -56,47 +56,14 @@ class BP_XProfile_User_Admin {
* @since 2.0.0
*/
private function setup_actions() {
- // Enqueue scripts.
- add_action( 'bp_members_admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 1 );
// Register the metabox in Member's community admin profile.
add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 );
- // Saves the profile actions for user ( avatar, profile fields ).
+ // Saves the profile actions for user ( profile fields ).
add_action( 'bp_members_admin_update_user', array( $this, 'user_admin_load' ), 10, 4 );
}
- /**
- * Enqueue needed scripts.
- *
- * @since 2.3.0
- *
- * @param int $screen_id Screen ID being displayed.
- */
- public function enqueue_scripts( $screen_id ) {
- if ( ( false === strpos( $screen_id, 'users_page_bp-profile-edit' )
- && false === strpos( $screen_id, 'profile_page_bp-profile-edit' ) )
- || bp_core_get_root_option( 'bp-disable-avatar-uploads' )
- || ! buddypress()->avatar->show_avatars
- || ! bp_attachments_is_wp_version_supported() ) {
- return;
- }
-
- /**
- * Get Thickbox.
- *
- * We cannot simply use add_thickbox() here as WordPress is not playing
- * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
- * Using media-upload might be interesting in the future for the send to editor stuff
- * and we make sure the tb_window is wide enough
- */
- wp_enqueue_style ( 'thickbox' );
- wp_enqueue_script( 'media-upload' );
-
- // Get Avatar Uploader.
- bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
- }
-
/**
* Register the xProfile metabox on Community Profile admin page.
*
@@ -155,18 +122,6 @@ class BP_XProfile_User_Admin {
'core'
);
}
-
- if ( buddypress()->avatar->show_avatars ) {
- // Avatar Metabox.
- add_meta_box(
- 'bp_xprofile_user_admin_avatar',
- _x( 'Profile Photo', 'xprofile user-admin edit screen', 'buddypress' ),
- array( $this, 'user_admin_avatar_metabox' ),
- $screen_id,
- 'side',
- 'low'
- );
- }
}
/**
@@ -176,6 +131,7 @@ class BP_XProfile_User_Admin {
* requests.
*
* @since 2.0.0
+ * @since 6.0.0 The `delete_avatar` action is now managed into BP_Members_Admin::user_admin_load().
*
* @param string $doaction Action being run.
* @param int $user_id ID for the user whose profile is being saved.
@@ -184,23 +140,9 @@ class BP_XProfile_User_Admin {
*/
public function user_admin_load( $doaction = '', $user_id = 0, $request = array(), $redirect_to = '' ) {
- // Eventually delete avatar.
- if ( 'delete_avatar' === $doaction ) {
-
- check_admin_referer( 'delete_avatar' );
+ // Update profile fields.
+ if ( isset( $_POST['field_ids'] ) ) {
- $redirect_to = remove_query_arg( '_wpnonce', $redirect_to );
-
- if ( bp_core_delete_existing_avatar( array( 'item_id' => $user_id ) ) ) {
- $redirect_to = add_query_arg( 'updated', 'avatar', $redirect_to );
- } else {
- $redirect_to = add_query_arg( 'error', 'avatar', $redirect_to );
- }
-
- bp_core_redirect( $redirect_to );
-
- } elseif ( isset( $_POST['field_ids'] ) ) {
- // Update profile fields.
// Check the nonce.
check_admin_referer( 'edit-bp-profile_' . $user_id );
@@ -434,60 +376,5 @@ class BP_XProfile_User_Admin {
ID ) ) {
- return;
- } ?>
-
-
-
- $user->ID,
- 'object' => 'user',
- 'type' => 'full',
- 'title' => $user->display_name
- ) ); ?>
-
- ID ) ) :
-
- $query_args = array(
- 'user_id' => $user->ID,
- 'action' => 'delete_avatar'
- );
-
- if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
- $wp_http_referer = wp_unslash( $_REQUEST['wp_http_referer'] );
- $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $wp_http_referer );
- $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
- $query_args['wp_http_referer'] = urlencode( $wp_http_referer );
- }
-
- $community_url = add_query_arg( $query_args, buddypress()->members->admin->edit_profile_url );
- $delete_link = wp_nonce_url( $community_url, 'delete_avatar' ); ?>
-
-
-
-
-
-
-
-
-
-
-
- Change Cover Image" screen handler
- *
- * @package BuddyPress
- * @subpackage XProfileScreens
- * @since 3.0.0
- */
-
-/**
- * Displays the change cover image page.
- *
- * @since 2.4.0
- */
-function xprofile_screen_change_cover_image() {
-
- // Bail if not the correct screen.
- if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
- return false;
- }
-
- /**
- * Fires right before the loading of the XProfile change cover image screen template file.
- *
- * @since 2.4.0
- */
- do_action( 'xprofile_screen_change_cover_image' );
-
- /**
- * Filters the template to load for the XProfile cover image screen.
- *
- * @since 2.4.0
- *
- * @param string $template Path to the XProfile cover image template to load.
- */
- bp_core_load_template( apply_filters( 'xprofile_template_cover_image', 'members/single/home' ) );
-}
\ No newline at end of file
diff --git tests/phpunit/testcases/core/class-bp-attachment.php tests/phpunit/testcases/core/class-bp-attachment.php
index b967a778e..80f933f5d 100644
--- tests/phpunit/testcases/core/class-bp-attachment.php
+++ tests/phpunit/testcases/core/class-bp-attachment.php
@@ -238,13 +238,13 @@ class BP_Tests_BP_Attachment_TestCases extends BP_UnitTestCase {
);
/* No error */
- $user_avatar = $avatar_attachment->upload( $_FILES, 'xprofile_avatar_upload_dir' );
+ $user_avatar = $avatar_attachment->upload( $_FILES, 'bp_members_avatar_upload_dir' );
$this->assertEquals( $user_avatar['file'], $bp->avatar->upload_path . '/avatars/' . $u1 .'/mystery-man.jpg' );
/* File size error */
add_filter( 'bp_core_avatar_original_max_filesize', array( $this, 'max_filesize' ) );
- $user_avatar = $avatar_attachment->upload( $_FILES, 'xprofile_avatar_upload_dir' );
+ $user_avatar = $avatar_attachment->upload( $_FILES, 'bp_members_avatar_upload_dir' );
remove_filter( 'bp_core_avatar_original_max_filesize', array( $this, 'max_filesize' ) );
$this->assertFalse( empty( $user_avatar['error'] ) );
@@ -253,7 +253,7 @@ class BP_Tests_BP_Attachment_TestCases extends BP_UnitTestCase {
$_FILES[ $avatar_attachment->file_input ]['name'] = 'buddypress_logo.pdf';
$_FILES[ $avatar_attachment->file_input ]['type'] = 'application/pdf';
- $user_avatar = $avatar_attachment->upload( $_FILES, 'xprofile_avatar_upload_dir' );
+ $user_avatar = $avatar_attachment->upload( $_FILES, 'bp_members_avatar_upload_dir' );
$this->assertFalse( empty( $user_avatar['error'] ) );
// clean up!