Skip to:
Content

BuddyPress.org

Changeset 12558


Ignore:
Timestamp:
02/29/2020 04:02:35 PM (6 years ago)
Author:
imath
Message:

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

  • Adapt Cover functions to relate to the Members component.
  • Deprecate functions no more used.
  • Add the handler to change the cover into the Members component.

See #8156

Location:
trunk/src
Files:
2 added
5 edited

Legend:

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

    r12507 r12558  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 /**
    14  * Check if the current WordPress version is using Plupload 2.1.1
    15  *
    16  * Plupload 2.1.1 was introduced in WordPress 3.9. Our bp-plupload.js
    17  * script requires it. So we need to make sure the current WordPress
    18  * match with our needs.
    19  *
    20  * @since 2.3.0
    21  * @since 3.0.0 This is always true.
    22  *
    23  * @return bool Always true.
    24  */
    25 function bp_attachments_is_wp_version_supported() {
    26         return true;
    27 }
    2812
    2913/**
     
    9377 */
    9478function bp_attachments_cover_image_upload_dir( $args = array() ) {
    95         // Default values are for profiles.
     79        // Default values are for members.
    9680        $object_id = bp_displayed_user_id();
    9781
     
    289273 *     @type int    $item_id   The ID of the object (Required). Default: 0.
    290274 *     @type string $object    The object type (eg: group, user, blog) (Required). Default: 'user'.
    291  *     @type string $component The component for the object (eg: groups, xprofile, blogs). Default: ''.
     275 *     @type string $component The component for the object (eg: groups, members, blogs). Default: ''.
    292276 *     @type string $image     The absolute path to the image (Required). Default: ''.
    293277 *     @type int    $crop_w    Crop width. Default: 0.
     
    326310        if ( empty( $r['component'] ) ) {
    327311                if ( 'user' === $r['object'] ) {
    328                         $r['component'] = 'xprofile';
     312                        $r['component'] = 'members';
    329313                } else {
    330314                        $r['component'] = $r['object'] . 's';
     
    358342                        $dir_args = array( $r['item_id'] );
    359343
    360                         // In case  of xprofile, we need an extra argument.
    361                         if ( 'xprofile' === $r['component'] ) {
     344                        // In case  of members, we need an extra argument.
     345                        if ( 'members' === $r['component'] ) {
    362346                                $dir_args = array( false, $r['item_id'] );
    363347                        }
     
    376360                $object_subdir = 'members';
    377361
    378                 if ( 'xprofile' !== $r['component'] ) {
     362                if ( 'members' !== $r['component'] ) {
    379363                        $object_subdir = sanitize_key( $r['component'] );
    380364                }
     
    646630 */
    647631function bp_attachments_get_plupload_l10n() {
    648         // Localization strings.
    649         return apply_filters( 'bp_attachments_get_plupload_l10n', array(
     632        /**
     633         * Use this filter to edit localization strings.
     634         *
     635         * @since 2.3.0
     636         *
     637         * @param array $value An associative array of the localization strings.
     638         */
     639        return apply_filters(
     640                'bp_attachments_get_plupload_l10n',
     641                array(
    650642                        'queue_limit_exceeded'      => __( 'You have attempted to queue too many files.', 'buddypress' ),
    651643                        'file_exceeds_size_limit'   => __( '%s exceeds the maximum upload size for this site.', 'buddypress' ),
     
    671663                        'error_uploading'           => __( '“%s” has failed to upload.', 'buddypress' ),
    672664                        'has_avatar_warning'        => __( 'If you'd like to delete the existing profile photo but not upload a new one, please use the delete tab.', 'buddypress' )
    673         ) );
     665                )
     666        );
    674667}
    675668
     
    820813                $defaults['multi_selection'] = false;
    821814
    822                 // Default cover component is xprofile.
    823                 $cover_component = 'xprofile';
     815                // Default cover component is members.
     816                $cover_component = 'members';
    824817
    825818                // Get the object we're editing the cover image of.
     
    915908                                }
    916909                        // User profile photo.
    917                         } elseif ( bp_is_active( 'xprofile' ) && 'user' === $args['object'] ) {
     910                        } elseif ( bp_is_active( 'members' ) && 'user' === $args['object'] ) {
    918911                                $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can( 'bp_moderate' );
    919912                        }
     
    1004997 * @since 2.4.0
    1005998 *
    1006  * @param string $component The component to get the settings for ("xprofile" for user or "groups").
     999 * @param string $component The component to get the settings for ("members" for user or "groups").
    10071000 * @return false|array The cover image settings in array, false on failure.
    10081001 */
    1009 function bp_attachments_get_cover_image_settings( $component = 'xprofile' ) {
     1002function bp_attachments_get_cover_image_settings( $component = 'members' ) {
    10101003        // Default parameters.
    10111004        $args = array();
     
    10181011        }
    10191012
     1013        // Set default args.
     1014        $default_args = wp_parse_args(
     1015                $args,
     1016                array(
     1017                        'components'    => array(),
     1018                        'width'         => 1300,
     1019                        'height'        => 225,
     1020                        'callback'      => '',
     1021                        'theme_handle'  => '',
     1022                        'default_cover' => '',
     1023                )
     1024        );
     1025
     1026        // Handle deprecated xProfile fitler.
     1027        if ( 'members' === $component ) {
     1028                /** This filter is documented in wp-includes/deprecated.php */
     1029                $args = apply_filters_deprecated( 'bp_before_xprofile_cover_image_settings_parse_args', array( $default_args ), '6.0.0', 'bp_before_members_cover_image_settings_parse_args' );
     1030        }
     1031
    10201032        /**
    10211033         * Then let people override/set the feature using this dynamic filter
    10221034         *
    10231035         * Eg: for the user's profile cover image use:
    1024          * add_filter( 'bp_before_xprofile_cover_image_settings_parse_args', 'your_filter', 10, 1 );
     1036         * add_filter( 'bp_before_members_cover_image_settings_parse_args', 'your_filter', 10, 1 );
    10251037         *
    10261038         * @since 2.4.0
     
    10281040         * @param array $settings The cover image settings
    10291041         */
    1030         $settings = bp_parse_args( $args, array(
    1031                 'components'    => array(),
    1032                 'width'         => 1300,
    1033                 'height'        => 225,
    1034                 'callback'      => '',
    1035                 'theme_handle'  => '',
    1036                 'default_cover' => '',
    1037         ), $component . '_cover_image_settings' );
     1042        $settings = bp_parse_args( $args, $default_args, $component . '_cover_image_settings' );
     1043
     1044        // Handle deprecated xProfile fitler.
     1045        if ( 'members' === $component ) {
     1046                /** This filter is documented in wp-includes/deprecated.php */
     1047                $settings = apply_filters_deprecated( 'bp_after_xprofile_cover_image_settings_parse_args', array( $settings ), '6.0.0', 'bp_after_members_cover_image_settings_parse_args' );
     1048        }
    10381049
    10391050        if ( empty( $settings['components'] ) || empty( $settings['callback'] ) || empty( $settings['theme_handle'] ) ) {
     
    10551066 * @since 2.4.0
    10561067 *
    1057  * @param string $component The BuddyPress component concerned ("xprofile" for user or "groups").
     1068 * @param string $component The BuddyPress component concerned ("members" for user or "groups").
    10581069 * @return array|bool An associative array containing the advised width and height for the cover image. False if settings are empty.
    10591070 */
    1060 function bp_attachments_get_cover_image_dimensions( $component = 'xprofile' ) {
     1071function bp_attachments_get_cover_image_dimensions( $component = 'members' ) {
    10611072        // Let's prevent notices when setting the warning strings.
    10621073        $default = array( 'width' => 0, 'height' => 0 );
     
    10941105
    10951106        $current_component = bp_current_component();
    1096         if ( bp_is_active( 'xprofile' ) && bp_is_current_component( 'xprofile' ) ) {
    1097                 $current_component = 'xprofile';
     1107        if ( bp_is_user() ) {
     1108                $current_component = 'members';
    10981109        }
    10991110
     
    11621173 * @param array                          $args {
    11631174 *     @type string $file            The absolute path to the image. Required.
    1164  *     @type string $component       The component for the object (eg: groups, xprofile). Required.
     1175 *     @type string $component       The component for the object (eg: groups, members). Required.
    11651176 *     @type string $cover_image_dir The Cover image dir to write the image into. Required.
    11661177 * }
     
    12831294        // Member's cover image.
    12841295        if ( 'user' === $bp_params['object'] ) {
    1285                 $object_data = array( 'dir' => 'members', 'component' => 'xprofile' );
     1296                $object_data = array( 'dir' => 'members', 'component' => 'members' );
    12861297
    12871298                if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) {
     
    14001411
    14011412        // Set the name of the file.
    1402         $name = $_FILES['file']['name'];
     1413        $name       = $_FILES['file']['name'];
    14031414        $name_parts = pathinfo( $name );
    1404         $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) );
     1415        $name       = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) );
     1416
     1417        // Set some arguments for filters.
     1418        $item_id   = (int) $bp_params['item_id'];
     1419        $component = $object_data['component'];
    14051420
    14061421        /**
    14071422         * Fires if the new cover image was successfully uploaded.
    14081423         *
    1409          * The dynamic portion of the hook will be xprofile in case of a user's
     1424         * The dynamic portion of the hook will be members in case of a user's
    14101425         * cover image, groups in case of a group's cover image. For instance:
    1411          * Use add_action( 'xprofile_cover_image_uploaded' ) to run your specific
     1426         * Use add_action( 'members_cover_image_uploaded' ) to run your specific
    14121427         * code once the user has set his cover image.
    14131428         *
     
    14211436         */
    14221437        do_action(
    1423                 $object_data['component'] . '_cover_image_uploaded',
    1424                 (int) $bp_params['item_id'],
     1438                $component . '_cover_image_uploaded',
     1439                $item_id,
    14251440                $name,
    14261441                $cover_url,
    14271442                $feedback_code
    14281443        );
     1444
     1445        // Handle deprecated xProfile action.
     1446        if ( 'members' === $component ) {
     1447                /** This filter is documented in wp-includes/deprecated.php */
     1448                do_action_deprecated(
     1449                        'xprofile_cover_image_uploaded',
     1450                        array(
     1451                                $item_id,
     1452                                $name,
     1453                                $cover_url,
     1454                                $feedback_code,
     1455                        ),
     1456                        '6.0.0',
     1457                        'members_cover_image_deleted'
     1458                );
     1459        }
    14291460
    14301461        // Finally return the cover image url to the UI.
     
    14671498        // Set object for the user's case.
    14681499        if ( 'user' === $args['object'] ) {
    1469                 $component = 'xprofile';
     1500                $component = 'members';
    14701501                $dir       = 'members';
    14711502
     
    14781509        // Handle delete.
    14791510        if ( bp_attachments_delete_file( array( 'item_id' => $args['item_id'], 'object_dir' => $dir, 'type' => 'cover-image' ) ) ) {
     1511                $item_id = (int) $args['item_id'];
     1512
    14801513                /**
    14811514                 * Fires if the cover image was successfully deleted.
    14821515                 *
    1483                  * The dynamic portion of the hook will be xprofile in case of a user's
     1516                 * The dynamic portion of the hook will be members in case of a user's
    14841517                 * cover image, groups in case of a group's cover image. For instance:
    1485                  * Use add_action( 'xprofile_cover_image_deleted' ) to run your specific
     1518                 * Use add_action( 'members_cover_image_deleted' ) to run your specific
    14861519                 * code once the user has deleted his cover image.
    14871520                 *
     
    14901523                 * @param int $item_id Inform about the item id the cover image was deleted for.
    14911524                 */
    1492                 do_action( "{$component}_cover_image_deleted", (int) $args['item_id'] );
     1525                do_action( "{$component}_cover_image_deleted", $item_id );
     1526
     1527                // Handle deprecated xProfile action.
     1528                if ( 'members' === $component ) {
     1529                        /** This filter is documented in wp-includes/deprecated.php */
     1530                        do_action_deprecated( 'xprofile_cover_image_deleted', array( $item_id ), '6.0.0', 'members_cover_image_deleted' );
     1531                }
    14931532
    14941533                $response = array(
  • trunk/src/bp-core/bp-core-cssjs.php

    r12401 r12558  
    443443
    444444                $cover_image_object = array(
    445                         'component' => 'xprofile',
     445                        'component' => 'members',
    446446                        'object' => $bp->displayed_user
    447447                );
     
    480480                $object_dir = $cover_image_object['component'];
    481481
    482                 if ( 'xprofile' === $object_dir ) {
     482                if ( 'members' === $object_dir ) {
    483483                        $object_dir = 'members';
    484484                }
  • trunk/src/bp-core/bp-core-theme-compatibility.php

    r12546 r12558  
    465465                'name'     => 'cover_image',
    466466                'settings' => array(
    467                         'components'   => array( 'xprofile', 'groups' ),
     467                        'components'   => array( 'members', 'groups' ),
    468468                        'width'        => $bp_content_width,
    469469                        'height'       => $top_offset + round( $avatar_height / 2 ),
  • trunk/src/bp-groups/bp-groups-template.php

    r12429 r12558  
    913913 */
    914914function bp_group_use_cover_image_header() {
    915         return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads() && bp_attachments_is_wp_version_supported();
     915        return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads();
    916916}
    917917
  • trunk/src/bp-templates/bp-nouveau/buddypress-functions.php

    r12524 r12558  
    147147                        'name'     => 'cover_image',
    148148                        'settings' => array(
    149                                 'components'   => array( 'xprofile', 'groups' ),
     149                                'components'   => array( 'members', 'groups' ),
    150150                                'width'        => $width,
    151151                                'height'       => $top_offset + round( $avatar_height / 2 ),
Note: See TracChangeset for help on using the changeset viewer.