Skip to:
Content

BuddyPress.org

Changeset 12555


Ignore:
Timestamp:
02/29/2020 03:38:06 PM (6 years ago)
Author:
imath
Message:

Move Avatars & Cover from xProfile to Members component : step 3

Move the Avatar upload directory filter from the xProfile functions to the Members functions.
Move the Avatar template functions from xProfile to the Members component.

See #8156

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-avatars.php

    r12536 r12555  
    10061006        $needs_reset = array();
    10071007
    1008         if ( 'user' === $bp_params['object'] && bp_is_active( 'xprofile' ) ) {
    1009                 $bp_params['upload_dir_filter'] = 'xprofile_avatar_upload_dir';
     1008        if ( 'user' === $bp_params['object'] && bp_is_active( 'members' ) ) {
     1009                $bp_params['upload_dir_filter'] = 'bp_members_avatar_upload_dir';
    10101010
    10111011                if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) {
     
    12981298                        );
    12991299
     1300                        /** This action is documented in wp-includes/deprecated.php */
     1301                        do_action_deprecated( 'xprofile_avatar_uploaded', array( (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data ), '6.0.0', 'bp_members_avatar_uploaded' );
     1302
    13001303                        /**
    13011304                         * Fires if the new avatar was successfully captured.
    13021305                         *
    1303                          * @since 1.1.0 Used to inform the avatar was successfully cropped
    1304                          * @since 2.3.4 Add two new parameters to inform about the user id and
    1305                          *              about the way the avatar was set (eg: 'crop' or 'camera')
    1306                          *              Move the action at the right place, once the avatar is set
    1307                          * @since 2.8.0 Added the `$avatar_data` parameter.
     1306                         * @since 6.0.0
    13081307                         *
    13091308                         * @param string $item_id     Inform about the user id the avatar was set for.
     
    13111310                         * @param array  $avatar_data Array of parameters passed to the avatar handler.
    13121311                         */
    1313                         do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data );
     1312                        do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data );
    13141313
    13151314                        wp_send_json_success( $return );
     
    13561355
    13571356                if ( 'user' === $avatar_data['object'] ) {
     1357                        /** This action is documented in wp-includes/deprecated.php */
     1358                        do_action_deprecated( 'xprofile_avatar_uploaded', array( (int) $avatar_data['item_id'], $avatar_data['type'], $r ), '6.0.0', 'bp_members_avatar_uploaded' );
     1359
    13581360                        /** This action is documented in bp-core/bp-core-avatars.php */
    1359                         do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );
     1361                        do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );
    13601362                } elseif ( 'group' === $avatar_data['object'] ) {
    13611363                        /** This action is documented in bp-groups/bp-groups-screens.php */
     
    19371939        $retval = false;
    19381940
    1939         // No need to carry on if the current WordPress version is not supported.
    1940         if ( ! bp_attachments_is_wp_version_supported() ) {
    1941                 return $retval;
    1942         }
    1943 
    19441941        if ( bp_is_user_change_avatar() && 'crop-image' !== bp_get_avatar_admin_step() ) {
    19451942                $retval = ! bp_core_get_root_option( 'bp-disable-avatar-uploads' );
  • trunk/src/bp-members/bp-members-functions.php

    r12503 r12555  
    28492849        return apply_filters( 'bp_get_current_member_type', buddypress()->current_member_type );
    28502850}
     2851
     2852/**
     2853 * Setup the avatar upload directory for a user.
     2854 *
     2855 * @since 6.0.0
     2856 *
     2857 * @param string $directory The root directory name. Optional.
     2858 * @param int    $user_id   The user ID. Optional.
     2859 * @return array Array containing the path, URL, and other helpful settings.
     2860 */
     2861function bp_members_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {
     2862
     2863        // Use displayed user if no user ID was passed.
     2864        if ( empty( $user_id ) ) {
     2865                $user_id = bp_displayed_user_id();
     2866        }
     2867
     2868        // Failsafe against accidentally nooped $directory parameter.
     2869        if ( empty( $directory ) ) {
     2870                $directory = 'avatars';
     2871        }
     2872
     2873        $path      = bp_core_avatar_upload_path() . '/' . $directory. '/' . $user_id;
     2874        $newbdir   = $path;
     2875        $newurl    = bp_core_avatar_url() . '/' . $directory. '/' . $user_id;
     2876        $newburl   = $newurl;
     2877        $newsubdir = '/' . $directory. '/' . $user_id;
     2878
     2879        /**
     2880         * Filters the avatar upload directory for a user.
     2881         *
     2882         * @since 6.0.0
     2883         *
     2884         * @param array $value Array containing the path, URL, and other helpful settings.
     2885         */
     2886        return apply_filters( 'bp_members_avatar_upload_dir', array(
     2887                'path'    => $path,
     2888                'url'     => $newurl,
     2889                'subdir'  => $newsubdir,
     2890                'basedir' => $newbdir,
     2891                'baseurl' => $newburl,
     2892                'error'   => false
     2893        ) );
     2894}
  • trunk/src/bp-members/bp-members-template.php

    r12336 r12555  
    15111511 */
    15121512function bp_displayed_user_use_cover_image_header() {
    1513         return (bool) bp_is_active( 'xprofile', 'cover_image' ) && ! bp_disable_cover_image_uploads() && bp_attachments_is_wp_version_supported();
     1513        return (bool) bp_is_active( 'members', 'cover_image' ) && ! bp_disable_cover_image_uploads();
    15141514}
    15151515
     
    26462646                        return $url;
    26472647        }
     2648
     2649
     2650/**
     2651 * Render an avatar delete link.
     2652 *
     2653 * @since 1.1.0
     2654 * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file.
     2655 */
     2656function bp_avatar_delete_link() {
     2657        echo bp_get_avatar_delete_link();
     2658}
     2659
     2660        /**
     2661         * Return an avatar delete link.
     2662         *
     2663         * @since 1.1.0
     2664         * @since 6.0.0 Moved from /bp-xprofile/bp-xprofile-template.php to this file.
     2665         *
     2666         * @return string
     2667         */
     2668        function bp_get_avatar_delete_link() {
     2669
     2670                /**
     2671                 * Filters the link used for deleting an avatar.
     2672                 *
     2673                 * @since 1.1.0
     2674                 *
     2675                 * @param string $value Nonced URL used for deleting an avatar.
     2676                 */
     2677                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' ) );
     2678        }
  • trunk/src/bp-xprofile/bp-xprofile-functions.php

    r12533 r12555  
    707707
    708708/**
    709  * Setup the avatar upload directory for a user.
    710  *
    711  * @since 1.0.0
    712  *
    713  * @package BuddyPress Core
    714  *
    715  * @param string $directory The root directory name. Optional.
    716  * @param int    $user_id   The user ID. Optional.
    717  * @return array Array containing the path, URL, and other helpful settings.
    718  */
    719 function xprofile_avatar_upload_dir( $directory = 'avatars', $user_id = 0 ) {
    720 
    721         // Use displayed user if no user ID was passed.
    722         if ( empty( $user_id ) ) {
    723                 $user_id = bp_displayed_user_id();
    724         }
    725 
    726         // Failsafe against accidentally nooped $directory parameter.
    727         if ( empty( $directory ) ) {
    728                 $directory = 'avatars';
    729         }
    730 
    731         $path      = bp_core_avatar_upload_path() . '/' . $directory. '/' . $user_id;
    732         $newbdir   = $path;
    733         $newurl    = bp_core_avatar_url() . '/' . $directory. '/' . $user_id;
    734         $newburl   = $newurl;
    735         $newsubdir = '/' . $directory. '/' . $user_id;
    736 
    737         /**
    738          * Filters the avatar upload directory for a user.
    739          *
    740          * @since 1.1.0
    741          *
    742          * @param array $value Array containing the path, URL, and other helpful settings.
    743          */
    744         return apply_filters( 'xprofile_avatar_upload_dir', array(
    745                 'path'    => $path,
    746                 'url'     => $newurl,
    747                 'subdir'  => $newsubdir,
    748                 'basedir' => $newbdir,
    749                 'baseurl' => $newburl,
    750                 'error'   => false
    751         ) );
    752 }
    753 
    754 /**
    755709 * When search_terms are passed to BP_User_Query, search against xprofile fields.
    756710 *
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r12529 r12555  
    12061206
    12071207/**
    1208  * Render an avatar delete link.
    1209  *
    1210  * @since 1.1.0
    1211  */
    1212 function bp_avatar_delete_link() {
    1213         echo bp_get_avatar_delete_link();
    1214 }
    1215 
    1216         /**
    1217          * Return an avatar delete link.
    1218          *
    1219          * @since 1.1.0
    1220          *
    1221          * @return string
    1222          */
    1223         function bp_get_avatar_delete_link() {
    1224 
    1225                 /**
    1226                  * Filters the link used for deleting an avatar.
    1227                  *
    1228                  * @since 1.1.0
    1229                  *
    1230                  * @param string $value Nonced URL used for deleting an avatar.
    1231                  */
    1232                 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' ) );
    1233         }
    1234 
    1235 /**
    12361208 * Render an edit profile button.
    12371209 *
  • trunk/tests/phpunit/testcases/core/class-bp-attachment.php

    r11737 r12555  
    239239
    240240                /* No error */
    241                 $user_avatar = $avatar_attachment->upload( $_FILES, 'xprofile_avatar_upload_dir' );
     241                $user_avatar = $avatar_attachment->upload( $_FILES, 'bp_members_avatar_upload_dir' );
    242242                $this->assertEquals( $user_avatar['file'], $bp->avatar->upload_path . '/avatars/' . $u1 .'/mystery-man.jpg' );
    243243
     
    245245                add_filter( 'bp_core_avatar_original_max_filesize', array( $this, 'max_filesize' ) );
    246246
    247                 $user_avatar = $avatar_attachment->upload( $_FILES, 'xprofile_avatar_upload_dir' );
     247                $user_avatar = $avatar_attachment->upload( $_FILES, 'bp_members_avatar_upload_dir' );
    248248
    249249                remove_filter( 'bp_core_avatar_original_max_filesize', array( $this, 'max_filesize' ) );
     
    254254                $_FILES[ $avatar_attachment->file_input ]['type'] = 'application/pdf';
    255255
    256                 $user_avatar = $avatar_attachment->upload( $_FILES, 'xprofile_avatar_upload_dir' );
     256                $user_avatar = $avatar_attachment->upload( $_FILES, 'bp_members_avatar_upload_dir' );
    257257                $this->assertFalse( empty( $user_avatar['error'] ) );
    258258
Note: See TracChangeset for help on using the changeset viewer.