Skip to:
Content

BuddyPress.org

Changeset 13891


Ignore:
Timestamp:
06/02/2024 01:12:39 AM (2 years ago)
Author:
espellcaste
Message:

WPCS: Part V: miscellaneous fixes for some of the files of the core component.

Follow-up to [13883], [13886], [13887], and [13888]

See #9164 and #7228

Location:
trunk/src/bp-core
Files:
3 edited

Legend:

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

    r13741 r13891  
    3232
    3333                // Add secondary parent item for all BuddyPress components.
    34                 $wp_admin_bar->add_node( array(
    35                         'parent'    => 'my-account',
    36                         'id'        => 'my-account-buddypress',
    37                         'title'     => __( 'My Account', 'buddypress' ),
    38                         'group'     => true,
    39                         'meta'      => array(
    40                                 'class' => 'ab-sub-secondary'
     34                $wp_admin_bar->add_node(
     35                        array(
     36                                'parent' => 'my-account',
     37                                'id'     => 'my-account-buddypress',
     38                                'title'  => __( 'My Account', 'buddypress' ),
     39                                'group'  => true,
     40                                'meta'   => array(
     41                                        'class' => 'ab-sub-secondary',
     42                                ),
    4143                        )
    42                 ) );
     44                );
    4345        }
    4446}
     
    5254function bp_core_load_admin_bar() {
    5355        // Show the Toolbar for logged out users.
    54         if ( ! is_user_logged_in() && (int) bp_get_option( 'hide-loggedout-adminbar' ) != 1 ) {
     56        if ( ! is_user_logged_in() && (int) bp_get_option( 'hide-loggedout-adminbar' ) !== 1 ) {
    5557                show_admin_bar( true );
    5658        }
     
    6870 */
    6971function bp_core_load_admin_bar_css() {
    70         add_action( 'bp_enqueue_scripts',       'bp_core_enqueue_admin_bar_css', 1 );
     72        add_action( 'bp_enqueue_scripts', 'bp_core_enqueue_admin_bar_css', 1 );
    7173        add_action( 'bp_admin_enqueue_scripts', 'bp_core_enqueue_admin_bar_css', 1 );
    7274}
  • trunk/src/bp-core/bp-core-attachments.php

    r13890 r13891  
    7474 * @since 3.0.0
    7575 *
    76  * @return array See wp_upload_dir().
     76 * @param array $args {
     77 *    @type int    $object_id        The ID of the object (Required).
     78 *    @type string $object_directory The object directory (eg: members, groups) (Required).
     79 * }
     80 * @return array
    7781 */
    7882function bp_attachments_cover_image_upload_dir( $args = array() ) {
     
    102106
    103107        // Set the subdir.
    104         $subdir  = '/' . $r['object_directory'] . '/' . $r['object_id'] . '/cover-image';
     108        $subdir = '/' . $r['object_directory'] . '/' . $r['object_id'] . '/cover-image';
    105109
    106110        $upload_dir = bp_attachments_uploads_dir_get();
     
    111115         * @since 2.4.0
    112116         *
    113          * @param array $value      Array containing the path, URL, and other helpful settings.
    114          * @param array $upload_dir The original Uploads dir.
     117         * @param array $image_upload_data Array containing the path, URL, and other helpful settings.
     118         * @param array $upload_dir        The original Uploads dir.
    115119         */
    116         return apply_filters( 'bp_attachments_cover_image_upload_dir', array(
    117                 'path'    => $upload_dir['basedir'] . $subdir,
    118                 'url'     => set_url_scheme( $upload_dir['baseurl'] ) . $subdir,
    119                 'subdir'  => $subdir,
    120                 'basedir' => $upload_dir['basedir'],
    121                 'baseurl' => set_url_scheme( $upload_dir['baseurl'] ),
    122                 'error'   => false,
    123         ), $upload_dir );
     120        return apply_filters(
     121                'bp_attachments_cover_image_upload_dir',
     122                array(
     123                        'path'    => $upload_dir['basedir'] . $subdir,
     124                        'url'     => set_url_scheme( $upload_dir['baseurl'] ) . $subdir,
     125                        'subdir'  => $subdir,
     126                        'basedir' => $upload_dir['basedir'],
     127                        'baseurl' => set_url_scheme( $upload_dir['baseurl'] ),
     128                        'error'   => false,
     129                ),
     130                $upload_dir
     131        );
    124132}
    125133
     
    197205                        // Loop to explode keys using '|'.
    198206                        foreach ( $allowed_types as $allowed_type ) {
    199                                 $t = explode( '|', $allowed_type );
     207                                $t    = explode( '|', $allowed_type );
    200208                                $exts = array_merge( $exts, (array) $t );
    201209                        }
     
    417425                                'crop_h'        => $r['crop_h'],
    418426                                'crop_x'        => $r['crop_x'],
    419                                 'crop_y'        => $r['crop_y']
     427                                'crop_y'        => $r['crop_y'],
    420428                        )
    421429                );
    422430
    423         // It's a cover image we need to fit it to feature's dimensions.
     431                // It's a cover image we need to fit it to feature's dimensions.
    424432        } elseif ( 'cover_image' === $type ) {
    425433                $cover_image = bp_attachments_cover_image_generate_file(
     
    427435                                'file'            => $image_file_path,
    428436                                'component'       => $r['component'],
    429                                 'cover_image_dir' => $attachment_data['path']
     437                                'cover_image_dir' => $attachment_data['path'],
    430438                        )
    431439                );
     
    520528                        $attachment_data = trailingslashit( $type_dir ) . $r['file'];
    521529                }
    522 
    523530        } else {
    524531                $file = false;
    525532
    526533                // Open the directory and get the first file.
    527                 if ( $att_dir = opendir( $type_dir ) ) {
     534                $att_dir = opendir( $type_dir );
     535                if ( $att_dir ) {
    528536
    529537                        while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) {
     
    604612                'file_data_name'      => 'file',
    605613                'multipart_params'    => array(
    606                         'action'          => 'bp_upload_attachment',
    607                         '_wpnonce'        => wp_create_nonce( 'bp-uploader' ),
     614                        'action'   => 'bp_upload_attachment',
     615                        '_wpnonce' => wp_create_nonce( 'bp-uploader' ),
    608616                ),
    609617                'url'                 => admin_url( 'admin-ajax.php', 'relative' ),
    610618                'flash_swf_url'       => includes_url( 'js/plupload/plupload.flash.swf' ),
    611619                'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
    612                 'filters' => array(
    613                         'max_file_size'   => $max_upload_size . 'b',
     620                'filters'             => array(
     621                        'max_file_size' => $max_upload_size . 'b',
    614622                ),
    615623                'multipart'           => true,
     
    625633
    626634        $settings = array(
    627                 'defaults' => $defaults,
    628                 'browser'  => array(
     635                'defaults'      => $defaults,
     636                'browser'       => array(
    629637                        'mobile'    => wp_is_mobile(),
    630638                        'supported' => _device_can_upload(),
     
    692700                        /* translators: %s: File name. */
    693701                        'error_uploading'           => __( '“%s” has failed to upload.', 'buddypress' ),
    694                         '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' )
     702                        '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' ),
    695703                )
    696704        );
     
    705713 * to set specific script data.
    706714 *
    707  * @param string $class Name of the class extending BP_Attachment (eg: BP_Attachment_Avatar).
     715 * @param string $class_name Name of the class extending BP_Attachment (eg: BP_Attachment_Avatar).
    708716 * @return null|WP_Error
    709717 */
    710 function bp_attachments_enqueue_scripts( $class = '' ) {
     718function bp_attachments_enqueue_scripts( $class_name = '' ) {
     719        $class = $class_name;
     720
    711721        // Enqueue me just once per page, please.
    712722        if ( did_action( 'bp_attachments_enqueue_scripts' ) ) {
     
    719729
    720730        // Get an instance of the class and get the script data.
    721         $attachment  = new $class;
     731        $attachment  = new $class();
    722732        $script_data = $attachment->script_data();
    723733
     
    766776
    767777        // Merge other arguments.
    768         $ui_args = array_intersect_key( $args, array(
    769                 'file_data_name' => true,
    770                 'browse_button'  => true,
    771                 'container'      => true,
    772                 'drop_element'   => true,
    773         ) );
     778        $ui_args = array_intersect_key(
     779                $args,
     780                array(
     781                        'file_data_name' => true,
     782                        'browse_button'  => true,
     783                        'container'      => true,
     784                        'drop_element'   => true,
     785                )
     786        );
    774787
    775788        $defaults = array_merge( $defaults, $ui_args );
     
    780793
    781794        if ( isset( $args['mime_types'] ) && $args['mime_types'] ) {
    782                 $defaults['filters']['mime_types'] =  array( array( 'extensions' => $args['mime_types'] ) );
     795                $defaults['filters']['mime_types'] = array( array( 'extensions' => $args['mime_types'] ) );
    783796        }
    784797
     
    793806                // Include the cropping informations for avatars.
    794807                $settings['crop'] = array(
    795                         'full_h'  => bp_core_avatar_full_height(),
    796                         'full_w'  => bp_core_avatar_full_width(),
     808                        'full_h' => bp_core_avatar_full_height(),
     809                        'full_w' => bp_core_avatar_full_width(),
    797810                );
    798811
     
    811824                // Init the Avatar nav.
    812825                $avatar_nav = array(
    813                         'upload'  => array(
     826                        'upload' => array(
    814827                                'id'      => 'upload',
    815828                                'caption' => __( 'Upload', 'buddypress' ),
    816                                 'order'   => 0
     829                                'order'   => 0,
    817830                        ),
    818                         'delete'  => array(
     831                        'delete' => array(
    819832                                'id'      => 'delete',
    820833                                'caption' => __( 'Delete', 'buddypress' ),
    821834                                'order'   => 100,
    822                                 'hide'    => (int) ! $has_avatar
     835                                'hide'    => (int) ! $has_avatar,
    823836                        ),
    824837                );
     
    851864                                'id'      => 'camera',
    852865                                'caption' => __( 'Take Photo', 'buddypress' ),
    853                                 'order'   => 10
     866                                'order'   => 10,
    854867                        );
    855868
    856869                        // Set warning messages.
    857870                        $strings['camera_warnings'] = array(
    858                                 'requesting'  => __( 'Please allow us to access to your camera.', 'buddypress'),
    859                                 'loading'     => __( 'Please wait as we access your camera.', 'buddypress' ),
    860                                 'loaded'      => __( 'Camera loaded. Click on the "Capture" button to take your photo.', 'buddypress' ),
    861                                 'noaccess'    => __( 'It looks like you do not have a webcam or we were unable to get permission to use your webcam. Please upload a photo instead.', 'buddypress' ),
    862                                 'errormsg'    => __( 'Your browser is not supported. Please upload a photo instead.', 'buddypress' ),
    863                                 'videoerror'  => __( 'Video error. Please upload a photo instead.', 'buddypress' ),
    864                                 'ready'       => __( 'Your profile photo is ready. Click on the "Save" button to use this photo.', 'buddypress' ),
    865                                 'nocapture'   => __( 'No photo was captured. Click on the "Capture" button to take your photo.', 'buddypress' ),
     871                                'requesting' => __( 'Please allow us to access to your camera.', 'buddypress' ),
     872                                'loading'    => __( 'Please wait as we access your camera.', 'buddypress' ),
     873                                'loaded'     => __( 'Camera loaded. Click on the "Capture" button to take your photo.', 'buddypress' ),
     874                                'noaccess'   => __( 'It looks like you do not have a webcam or we were unable to get permission to use your webcam. Please upload a photo instead.', 'buddypress' ),
     875                                'errormsg'   => __( 'Your browser is not supported. Please upload a photo instead.', 'buddypress' ),
     876                                'videoerror' => __( 'Video error. Please upload a photo instead.', 'buddypress' ),
     877                                'ready'      => __( 'Your profile photo is ready. Click on the "Save" button to use this photo.', 'buddypress' ),
     878                                'nocapture'  => __( 'No photo was captured. Click on the "Capture" button to take your photo.', 'buddypress' ),
    866879                        );
    867880                }
     
    886899                $settings['nav'] = bp_sort_by_key( apply_filters( 'bp_attachments_avatar_nav', $avatar_nav, $object ), 'order', 'num' );
    887900
    888         // Specific to BuddyPress cover images.
     901                // Specific to BuddyPress cover images.
    889902        } elseif ( 'bp_cover_image_upload' === $defaults['multipart_params']['action'] ) {
    890903
     
    908921
    909922                // Set warning messages.
    910                 $strings['cover_image_warnings'] = apply_filters( 'bp_attachments_cover_image_ui_warnings', array(
    911                         'dimensions'  => sprintf(
    912                                 /* translators: 1: the advised width size in pixels. 2: the advised height size in pixels. */
    913                                 __( 'For better results, make sure to upload an image that is larger than %1$spx wide, and %2$spx tall.', 'buddypress' ),
    914                                 (int) $cover_dimensions['width'],
    915                                 (int) $cover_dimensions['height']
    916                         ),
    917                 ) );
     923                $strings['cover_image_warnings'] = apply_filters(
     924                        'bp_attachments_cover_image_ui_warnings',
     925                        array(
     926                                'dimensions' => sprintf(
     927                                        /* translators: 1: the advised width size in pixels. 2: the advised height size in pixels. */
     928                                        __( 'For better results, make sure to upload an image that is larger than %1$spx wide, and %2$spx tall.', 'buddypress' ),
     929                                        (int) $cover_dimensions['width'],
     930                                        (int) $cover_dimensions['height']
     931                                ),
     932                        )
     933                );
    918934        }
    919935
     
    936952        }
    937953
    938         wp_enqueue_script ( 'bp-plupload' );
    939         wp_localize_script( 'bp-plupload', 'BP_Uploader', array( 'strings' => $strings, 'settings' => $settings ) );
     954        wp_enqueue_script( 'bp-plupload' );
     955        wp_localize_script(
     956                'bp-plupload',
     957                'BP_Uploader',
     958                array(
     959                        'strings'  => $strings,
     960                        'settings' => $settings,
     961                )
     962        );
    940963
    941964        /**
     
    9871010                                        $can = (bool) groups_is_user_admin( bp_loggedin_user_id(), $args['item_id'] ) || bp_current_user_can( 'bp_moderate' );
    9881011                                }
    989                         // User profile photo.
     1012                                // User profile photo.
    9901013                        } elseif ( bp_is_active( 'members' ) && 'user' === $args['object'] ) {
    9911014                                $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can( 'bp_moderate' );
    9921015                        }
    993                 /**
    994                  * No avatar arguments, fallback to bp_user_can_create_groups()
    995                  * or bp_is_item_admin()
    996                  */
     1016                        /**
     1017                         * No avatar arguments, fallback to bp_user_can_create_groups()
     1018                         * or bp_is_item_admin()
     1019                         */
     1020                } elseif ( bp_is_group_create() ) {
     1021                                $can = bp_user_can_create_groups();
    9971022                } else {
    998                         if ( bp_is_group_create() ) {
    999                                 $can = bp_user_can_create_groups();
    1000                         } else {
    1001                                 $can = bp_is_item_admin();
    1002                         }
     1023                        $can = bp_is_item_admin();
    10031024                }
    10041025        }
     
    10271048                wp_send_json( $response );
    10281049
    1029         /**
    1030         * Send specific json response
    1031         * the html4 Plupload handler requires a text/html content-type for older IE.
    1032         * See https://core.trac.wordpress.org/ticket/31037
    1033         */
     1050                /**
     1051                * Send specific json response
     1052                * the html4 Plupload handler requires a text/html content-type for older IE.
     1053                * See https://core.trac.wordpress.org/ticket/31037
     1054                */
    10341055        } else {
    10351056                echo wp_json_encode( $response );
     
    10451066 *
    10461067 * @param string $slug Template part slug. eg 'uploader' for 'uploader.php'.
    1047  * @return bool
    10481068 */
    10491069function bp_attachments_get_template_part( $slug ) {
     
    11371157
    11381158        // Current component is not supported.
    1139         if ( ! in_array( $component, $settings['components'] ) ) {
     1159        if ( ! in_array( $component, $settings['components'], true ) ) {
    11401160                return false;
    11411161        }
     
    11551175function bp_attachments_get_cover_image_dimensions( $component = 'members' ) {
    11561176        // Let's prevent notices when setting the warning strings.
    1157         $default = array( 'width' => 0, 'height' => 0 );
     1177        $default = array(
     1178                'width'  => 0,
     1179                'height' => 0,
     1180        );
    11581181
    11591182        $settings = bp_attachments_get_cover_image_settings( $component );
     
    12011224        }
    12021225
    1203         if ( ( bp_is_group_admin_page() && 'group-cover-image' == bp_get_group_current_admin_tab() )
     1226        if ( ( bp_is_group_admin_page() && 'group-cover-image' === bp_get_group_current_admin_tab() )
    12041227                || ( bp_is_group_create() && bp_is_group_creation_step( 'group-cover-image' ) ) ) {
    12051228                $retval = ! bp_disable_group_cover_image_uploads();
     
    12221245        }
    12231246
    1224         $cover_src = bp_attachments_get_attachment( 'url', array(
    1225                 'item_id'   => $user_id,
    1226         ) );
     1247        $cover_src = bp_attachments_get_attachment(
     1248                'url',
     1249                array(
     1250                        'item_id' => $user_id,
     1251                )
     1252        );
    12271253
    12281254        return (bool) apply_filters( 'bp_attachments_get_user_has_cover_image', $cover_src, $user_id );
     
    12431269        }
    12441270
    1245         $cover_src = bp_attachments_get_attachment( 'url', array(
    1246                 'object_dir' => 'groups',
    1247                 'item_id'    => $group_id,
    1248         ) );
     1271        $cover_src = bp_attachments_get_attachment(
     1272                'url',
     1273                array(
     1274                        'object_dir' => 'groups',
     1275                        'item_id'    => $group_id,
     1276                )
     1277        );
    12491278
    12501279        return (bool) apply_filters( 'bp_attachments_get_group_has_cover_image', $cover_src, $group_id );
     
    13301359                'cover_file'     => $cover_file,
    13311360                'cover_basename' => $cover_basename,
    1332                 'is_too_small'   => $is_too_small
     1361                'is_too_small'   => $is_too_small,
    13331362        );
    13341363}
     
    13381367 *
    13391368 * @since 2.4.0
    1340  *
    1341  * @return string|null A json object containing success data if the upload succeeded,
    1342  *                     error message otherwise.
    13431369 */
    13441370function bp_attachments_cover_image_ajax_upload() {
     1371
    13451372        if ( ! bp_is_post_request() ) {
    13461373                wp_die();
     
    13501377
    13511378        // Sending the json response will be different if the current Plupload runtime is html4.
    1352         $is_html4 = ! empty( $_POST['html4' ] );
     1379        $is_html4 = ! empty( $_POST['html4'] );
    13531380
    13541381        if ( empty( $_POST['bp_params'] ) ) {
     
    13831410        // Member's cover image.
    13841411        if ( 'user' === $bp_params['object'] ) {
    1385                 $object_data = array( 'dir' => 'members', 'component' => 'members' );
     1412                $object_data = array(
     1413                        'dir'       => 'members',
     1414                        'component' => 'members',
     1415                );
    13861416
    13871417                if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) {
    1388                         $needs_reset = array( 'key' => 'displayed_user', 'value' => $bp->displayed_user );
     1418                        $needs_reset            = array(
     1419                                'key'   => 'displayed_user',
     1420                                'value' => $bp->displayed_user,
     1421                        );
    13891422                        $bp->displayed_user->id = $bp_params['item_id'];
    13901423                }
    13911424
    1392         // Group's cover image.
     1425                // Group's cover image.
    13931426        } elseif ( 'group' === $bp_params['object'] ) {
    1394                 $object_data = array( 'dir' => 'groups', 'component' => 'groups' );
     1427                $object_data = array(
     1428                        'dir'       => 'groups',
     1429                        'component' => 'groups',
     1430                );
    13951431
    13961432                if ( ! bp_get_current_group_id() && ! empty( $bp_params['item_id'] ) ) {
    1397                         $needs_reset = array( 'component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group );
     1433                        $needs_reset               = array(
     1434                                'component' => 'groups',
     1435                                'key'       => 'current_group',
     1436                                'value'     => $bp->groups->current_group,
     1437                        );
    13981438                        $bp->groups->current_group = groups_get_group( $bp_params['item_id'] );
    13991439                }
    14001440
    1401         // Other object's cover image.
     1441                // Other object's cover image.
    14021442        } else {
    14031443                $object_data = apply_filters( 'bp_attachments_cover_image_object_dir', array(), $bp_params['object'] );
     
    14271467
    14281468        $cover_image_attachment = new BP_Attachment_Cover_Image();
    1429         $uploaded = $cover_image_attachment->upload( $_FILES );
     1469        $uploaded               = $cover_image_attachment->upload( $_FILES );
    14301470
    14311471        // Reset objects.
     
    14401480        if ( ! empty( $uploaded['error'] ) ) {
    14411481                // Upload error response.
    1442                 bp_attachments_json_response( false, $is_html4, array(
    1443                         'type'    => 'upload_error',
    1444                         'message' => sprintf(
    1445                                 /* translators: %s: the upload error message */
    1446                                 __( 'Upload Failed! Error was: %s', 'buddypress' ),
    1447                                 $uploaded['error']
    1448                         ),
    1449                 ) );
     1482                bp_attachments_json_response(
     1483                        false,
     1484                        $is_html4,
     1485                        array(
     1486                                'type'    => 'upload_error',
     1487                                'message' => sprintf(
     1488                                        /* translators: %s: the upload error message */
     1489                                        __( 'Upload Failed! Error was: %s', 'buddypress' ),
     1490                                        $uploaded['error']
     1491                                ),
     1492                        )
     1493                );
    14501494        }
    14511495
     
    14561500        // The BP Attachments Uploads Dir is not set, stop.
    14571501        if ( ! $bp_attachments_uploads_dir ) {
    1458                 bp_attachments_json_response( false, $is_html4, array(
    1459                         'type'    => 'upload_error',
    1460                         'message' => $error_message,
    1461                 ) );
     1502                bp_attachments_json_response(
     1503                        false,
     1504                        $is_html4,
     1505                        array(
     1506                                'type'    => 'upload_error',
     1507                                'message' => $error_message,
     1508                        )
     1509                );
    14621510        }
    14631511
     
    14671515        if ( 1 === validate_file( $cover_dir ) || ! is_dir( $cover_dir ) ) {
    14681516                // Upload error response.
    1469                 bp_attachments_json_response( false, $is_html4, array(
    1470                         'type'    => 'upload_error',
    1471                         'message' => $error_message,
    1472                 ) );
     1517                bp_attachments_json_response(
     1518                        false,
     1519                        $is_html4,
     1520                        array(
     1521                                'type'    => 'upload_error',
     1522                                'message' => $error_message,
     1523                        )
     1524                );
    14731525        }
    14741526
     
    14801532         * class, let's use it.
    14811533         */
    1482         $cover = bp_attachments_cover_image_generate_file( array(
    1483                 'file'            => $uploaded['file'],
    1484                 'component'       => $object_data['component'],
    1485                 'cover_image_dir' => $cover_dir
    1486         ), $cover_image_attachment );
     1534        $cover = bp_attachments_cover_image_generate_file(
     1535                array(
     1536                        'file'            => $uploaded['file'],
     1537                        'component'       => $object_data['component'],
     1538                        'cover_image_dir' => $cover_dir,
     1539                ),
     1540                $cover_image_attachment
     1541        );
    14871542
    14881543        if ( ! $cover ) {
    1489                 bp_attachments_json_response( false, $is_html4, array(
    1490                         'type'    => 'upload_error',
    1491                         'message' => $error_message,
    1492                 ) );
     1544                bp_attachments_json_response(
     1545                        false,
     1546                        $is_html4,
     1547                        array(
     1548                                'type'    => 'upload_error',
     1549                                'message' => $error_message,
     1550                        )
     1551                );
    14931552        }
    14941553
     
    15531612
    15541613        // Finally return the cover image url to the UI.
    1555         bp_attachments_json_response( true, $is_html4, array(
    1556                 'name'          => $name,
    1557                 'url'           => $cover_url,
    1558                 'feedback_code' => $feedback_code,
    1559         ) );
     1614        bp_attachments_json_response(
     1615                true,
     1616                $is_html4,
     1617                array(
     1618                        'name'          => $name,
     1619                        'url'           => $cover_url,
     1620                        'feedback_code' => $feedback_code,
     1621                )
     1622        );
    15601623}
    15611624add_action( 'wp_ajax_bp_cover_image_upload', 'bp_attachments_cover_image_ajax_upload' );
     
    15651628 *
    15661629 * @since 2.4.0
    1567  *
    1568  * @return string|null A json object containing success data if the cover image was deleted
    1569  *                     error message otherwise.
    15701630 */
    15711631function bp_attachments_cover_image_ajax_delete() {
     1632
    15721633        if ( ! bp_is_post_request() ) {
    15731634                wp_send_json_error();
     
    15941655                $dir       = 'members';
    15951656
    1596         // Set it for any other cases.
     1657                // Set it for any other cases.
    15971658        } else {
    15981659                $component = $args['object'] . 's';
     
    16011662
    16021663        // Handle delete.
    1603         if ( bp_attachments_delete_file( array( 'item_id' => $args['item_id'], 'object_dir' => $dir, 'type' => 'cover-image' ) ) ) {
     1664        if ( bp_attachments_delete_file(
     1665                array(
     1666                        'item_id'    => $args['item_id'],
     1667                        'object_dir' => $dir,
     1668                        'type'       => 'cover-image',
     1669                )
     1670        ) ) {
    16041671                $item_id = (int) $args['item_id'];
    16051672
     
    16401707
    16411708        } else {
    1642                 wp_send_json_error( array(
    1643                         'feedback_code' => 2,
    1644                 ) );
     1709                wp_send_json_error(
     1710                        array(
     1711                                'feedback_code' => 2,
     1712                        )
     1713                );
    16451714        }
    16461715}
     
    17291798                $supported_file = bp_attachments_get_file_object( $file );
    17301799
    1731                 if ( is_null( $supported_file) ) {
     1800                if ( is_null( $supported_file ) ) {
    17321801                        continue;
    17331802                }
     
    17621831                $supported_file = bp_attachments_get_file_object( $file );
    17631832
    1764                 if ( is_null( $supported_file) ) {
     1833                if ( is_null( $supported_file ) ) {
    17651834                        continue;
    17661835                }
  • trunk/src/bp-core/bp-core-avatars.php

    r13890 r13891  
    5656        $bp = buddypress();
    5757
    58         $bp->avatar        = new stdClass;
    59         $bp->avatar->thumb = new stdClass;
    60         $bp->avatar->full  = new stdClass;
     58        $bp->avatar        = new stdClass();
     59        $bp->avatar->thumb = new stdClass();
     60        $bp->avatar->full  = new stdClass();
    6161
    6262        // Dimensions.
     
    7676        // These have to be set on page load in order to avoid infinite filter loops at runtime.
    7777        $bp->avatar->upload_path = bp_core_avatar_upload_path();
    78         $bp->avatar->url = bp_core_avatar_url();
     78        $bp->avatar->url         = bp_core_avatar_url();
    7979
    8080        // Cache the root blog's show_avatars setting, to avoid unnecessary
     
    8383
    8484        // Backpat for pre-1.5.
    85         if ( ! defined( 'BP_AVATAR_UPLOAD_PATH' ) )
     85        if ( ! defined( 'BP_AVATAR_UPLOAD_PATH' ) ) {
    8686                define( 'BP_AVATAR_UPLOAD_PATH', $bp->avatar->upload_path );
     87        }
    8788
    8889        // Backpat for pre-1.5.
    89         if ( ! defined( 'BP_AVATAR_URL' ) )
     90        if ( ! defined( 'BP_AVATAR_URL' ) ) {
    9091                define( 'BP_AVATAR_URL', $bp->avatar->url );
     92        }
    9193
    9294        /**
     
    112114        }
    113115
    114         /** this filter is documented in wp-admin/options-discussion.php */
     116        /** This filter is documented in wp-admin/options-discussion.php */
    115117        $gravatar_defaults = apply_filters(
    116118                'avatar_defaults',
     
    264266                switch ( $params['object'] ) {
    265267
    266                         case 'blog'  :
     268                        case 'blog':
    267269                                $params['item_id'] = get_current_blog_id();
    268270                                break;
    269271
    270                         case 'group' :
     272                        case 'group':
    271273                                if ( bp_is_active( 'groups' ) ) {
    272274                                        $params['item_id'] = $bp->groups->current_group->id;
     
    277279                                break;
    278280
    279                         case 'user'  :
    280                         default      :
     281                        case 'user':
     282                        default:
    281283                                $params['item_id'] = bp_displayed_user_id();
    282284                                break;
     
    305307                switch ( $params['object'] ) {
    306308
    307                         case 'blog'  :
     309                        case 'blog':
    308310                                $params['avatar_dir'] = 'blog-avatars';
    309311                                break;
    310312
    311                         case 'group' :
     313                        case 'group':
    312314                                if ( bp_is_active( 'groups' ) ) {
    313315                                        $params['avatar_dir'] = 'group-avatars';
     
    318320                                break;
    319321
    320                         case 'user'  :
    321                         default      :
     322                        case 'user':
     323                        default:
    322324                                $params['avatar_dir'] = 'avatars';
    323325                                break;
     
    346348                switch ( $params['object'] ) {
    347349
    348                         case 'blog'  :
     350                        case 'blog':
    349351                                $item_name = get_blog_option( $params['item_id'], 'blogname' );
    350352                                break;
    351353
    352                         case 'group' :
     354                        case 'group':
    353355                                $item_name = bp_get_group_name( groups_get_group( $params['item_id'] ) );
    354356                                break;
    355357
    356                         case 'user'  :
    357                         default :
     358                        case 'user':
     359                        default:
    358360                                $item_name = bp_core_get_user_displayname( $params['item_id'] );
    359361                                break;
     
    370372                 * @param array  $params Array of parameters for the request.
    371373                 */
    372                 $item_name = apply_filters( 'bp_core_avatar_alt', $item_name, $params['item_id'], $params['object'], $params );
     374                $item_name     = apply_filters( 'bp_core_avatar_alt', $item_name, $params['item_id'], $params['object'], $params );
    373375                $params['alt'] = sprintf( $params['alt'], $item_name );
    374376        }
     
    429431        if ( false !== $params['width'] ) {
    430432                // Width has been specified. No modification necessary.
    431         } elseif ( 'thumb' == $params['type'] ) {
     433        } elseif ( 'thumb' === $params['type'] ) {
    432434                $params['width'] = bp_core_avatar_thumb_width();
    433435        } else {
     
    439441        if ( false !== $params['height'] ) {
    440442                // Height has been specified. No modification necessary.
    441         } elseif ( 'thumb' == $params['type'] ) {
     443        } elseif ( 'thumb' === $params['type'] ) {
    442444                $params['height'] = bp_core_avatar_thumb_height();
    443445        } else {
     
    467469
    468470        // Merge classes.
    469         $avatar_classes = array_merge( $avatar_classes, array(
    470                 $params['object'] . '-' . $params['item_id'] . '-avatar',
    471                 'avatar-' . $params['width'],
    472         ) );
     471        $avatar_classes = array_merge(
     472                $avatar_classes,
     473                array(
     474                        $params['object'] . '-' . $params['item_id'] . '-avatar',
     475                        'avatar-' . $params['width'],
     476                )
     477        );
    473478
    474479        // Sanitize each class.
     
    479484
    480485        // Set img URL and DIR based on prepopulated constants.
    481         $avatar_loc        = new stdClass();
    482         $avatar_loc->path  = trailingslashit( bp_core_avatar_upload_path() );
    483         $avatar_loc->url   = trailingslashit( bp_core_avatar_url() );
    484 
    485         $avatar_loc->dir   = trailingslashit( $params['avatar_dir'] );
     486        $avatar_loc       = new stdClass();
     487        $avatar_loc->path = trailingslashit( bp_core_avatar_upload_path() );
     488        $avatar_loc->url  = trailingslashit( bp_core_avatar_url() );
     489
     490        $avatar_loc->dir = trailingslashit( $params['avatar_dir'] );
    486491
    487492        /**
     
    495500         * @param string $value Subdirectory where the requested avatar should be found.
    496501         */
    497         $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', ( $avatar_loc->url  . $avatar_loc->dir . $params['item_id'] ), $params['item_id'], $params['object'], $params['avatar_dir'] );
     502        $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', ( $avatar_loc->url . $avatar_loc->dir . $params['item_id'] ), $params['item_id'], $params['object'], $params['avatar_dir'] );
    498503
    499504        /**
     
    514519         * or thumbnail image.
    515520         */
    516         $avatar_size              = ( 'full' == $params['type'] ) ? '-bpfull' : '-bpthumb';
    517         $legacy_user_avatar_name  = ( 'full' == $params['type'] ) ? '-avatar2' : '-avatar1';
    518         $legacy_group_avatar_name = ( 'full' == $params['type'] ) ? '-groupavatar-full' : '-groupavatar-thumb';
     521        $avatar_size              = ( 'full' === $params['type'] ) ? '-bpfull' : '-bpthumb';
     522        $legacy_user_avatar_name  = ( 'full' === $params['type'] ) ? '-avatar2' : '-avatar1';
     523        $legacy_group_avatar_name = ( 'full' === $params['type'] ) ? '-groupavatar-full' : '-groupavatar-thumb';
    519524
    520525        // Check for directory.
     
    538543                                // Check for current avatar.
    539544                                foreach ( $avatar_files as $key => $value ) {
    540                                         if ( strpos ( $value, $avatar_size )!== false ) {
    541                                                 $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
     545                                        if ( strpos( $value, $avatar_size ) !== false ) {
     546                                                $avatar_url = $avatar_folder_url . '/' . $avatar_files[ $key ];
    542547                                        }
    543548                                }
    544549
    545550                                // Legacy avatar check.
    546                                 if ( !isset( $avatar_url ) ) {
     551                                if ( ! isset( $avatar_url ) ) {
    547552                                        foreach ( $avatar_files as $key => $value ) {
    548                                                 if ( strpos ( $value, $legacy_user_avatar_name )!== false ) {
    549                                                         $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
     553                                                if ( strpos( $value, $legacy_user_avatar_name ) !== false ) {
     554                                                        $avatar_url = $avatar_folder_url . '/' . $avatar_files[ $key ];
    550555                                                }
    551556                                        }
    552557
    553558                                        // Legacy group avatar check.
    554                                         if ( !isset( $avatar_url ) ) {
     559                                        if ( ! isset( $avatar_url ) ) {
    555560                                                foreach ( $avatar_files as $key => $value ) {
    556                                                         if ( strpos ( $value, $legacy_group_avatar_name )!== false ) {
    557                                                                 $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
     561                                                        if ( strpos( $value, $legacy_group_avatar_name ) !== false ) {
     562                                                                $avatar_url = $avatar_folder_url . '/' . $avatar_files[ $key ];
    558563                                                        }
    559564                                                }
     
    589594                                 * @param string $avatar_folder_dir Avatar DIR path.
    590595                                 */
    591                                 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id  . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    592 
    593                         // ...or only the URL
     596                                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     597
     598                                // ...or only the URL
    594599                        } else {
    595600
     
    625630                if ( empty( $bp->grav_default->{$params['object']} ) ) {
    626631                        $default_grav = 'wavatar';
    627                 } elseif ( 'mystery' == $bp->grav_default->{$params['object']} ) {
     632                } elseif ( 'mystery' === $bp->grav_default->{$params['object']} ) {
    628633
    629634                        /**
     
    642647                // Set gravatar object.
    643648                if ( empty( $params['email'] ) ) {
    644                         if ( 'user' == $params['object'] ) {
     649                        if ( 'user' === $params['object'] ) {
    645650                                $params['email'] = bp_core_get_user_email( $params['item_id'] );
    646                         } elseif ( 'group' == $params['object'] || 'blog' == $params['object'] ) {
     651                        } elseif ( 'group' === $params['object'] || 'blog' === $params['object'] ) {
    647652                                $params['email'] = $params['item_id'] . '-' . $params['object'] . '@' . bp_get_domain();
    648653                        }
     
    670675
    671676                // Append email hash to Gravatar.
    672                 $gravatar .=  md5( strtolower( $params['email'] ) );
     677                $gravatar .= md5( strtolower( $params['email'] ) );
    673678
    674679                // Main Gravatar URL args.
    675680                $url_args = array(
    676                         's' => $params['width']
     681                        's' => $params['width'],
    677682                );
    678683
     
    716721
    717722                // Set up the Gravatar URL.
    718                 $gravatar = esc_url( add_query_arg(
    719                         rawurlencode_deep( array_filter( $url_args ) ),
    720                         $gravatar
    721                 ) );
    722 
    723         // No avatar was found, and we've been told not to use a gravatar.
     723                $gravatar = esc_url(
     724                        add_query_arg(
     725                                rawurlencode_deep( array_filter( $url_args ) ),
     726                                $gravatar
     727                        )
     728                );
     729
     730                // No avatar was found, and we've been told not to use a gravatar.
    724731        } else {
    725732
     
    771778                'item_id'    => false,
    772779                'object'     => 'user', // User OR group OR blog OR custom type (if you use filters).
    773                 'avatar_dir' => false
     780                'avatar_dir' => false,
    774781        );
    775782
     
    851858        if ( $av_dir = opendir( $avatar_folder_dir ) ) {
    852859                while ( false !== ( $avatar_file = readdir( $av_dir ) ) ) {
    853                         if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file ) {
     860                        if ( ( preg_match( '/-bpfull/', $avatar_file ) || preg_match( '/-bpthumb/', $avatar_file ) ) && '.' !== $avatar_file && '..' !== $avatar_file ) {
    854861                                @unlink( $avatar_folder_dir . '/' . $avatar_file );
    855862                        }
     
    905912
    906913        // Handle delete.
    907         if ( bp_core_delete_existing_avatar( array( 'item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'] ) ) ) {
     914        if ( bp_core_delete_existing_avatar(
     915                array(
     916                        'item_id' => $avatar_data['item_id'],
     917                        'object'  => $avatar_data['object'],
     918                )
     919        ) ) {
    908920                $return = array(
    909                         'avatar' => esc_url( bp_core_fetch_avatar( array(
    910                                 'object'  => $avatar_data['object'],
    911                                 'item_id' => $avatar_data['item_id'],
    912                                 'html'    => false,
    913                                 'type'    => 'full',
    914                         ) ) ),
     921                        'avatar'        => esc_url(
     922                                bp_core_fetch_avatar(
     923                                        array(
     924                                                'object'  => $avatar_data['object'],
     925                                                'item_id' => $avatar_data['item_id'],
     926                                                'html'    => false,
     927                                                'type'    => 'full',
     928                                        )
     929                                )
     930                        ),
    915931                        'feedback_code' => 4,
    916932                        'item_id'       => $avatar_data['item_id'],
     
    919935                wp_send_json_success( $return );
    920936        } else {
    921                 wp_send_json_error( array(
    922                         'feedback_code' => 3,
    923                 ) );
     937                wp_send_json_error(
     938                        array(
     939                                'feedback_code' => 3,
     940                        )
     941                );
    924942        }
    925943}
     
    966984
    967985        // Upload the file.
    968         $avatar_attachment = new BP_Attachment_Avatar();
     986        $avatar_attachment          = new BP_Attachment_Avatar();
    969987        $bp->avatar_admin->original = $avatar_attachment->upload( $file, $upload_dir_filter );
    970988
     
    10301048 *
    10311049 * @since 2.3.0
    1032  *
    1033  * @return string|null A JSON object containing success data if the upload succeeded
    1034  *                     error message otherwise.
    10351050 */
    10361051function bp_avatar_ajax_upload() {
     1052
    10371053        if ( ! bp_is_post_request() ) {
    10381054                wp_die();
     
    10441060         */
    10451061        $is_html4 = false;
    1046         if ( ! empty( $_POST['html4' ] ) ) {
     1062        if ( ! empty( $_POST['html4'] ) ) {
    10471063                $is_html4 = true;
    10481064        }
     
    10551071
    10561072        // We need it to carry on.
    1057         if ( ! empty( $_POST['bp_params' ] ) ) {
    1058                 $bp_params = $_POST['bp_params' ];
     1073        if ( ! empty( $_POST['bp_params'] ) ) {
     1074                $bp_params = $_POST['bp_params'];
    10591075        } else {
    10601076                bp_attachments_json_response( false, $is_html4 );
     
    10711087        }
    10721088
    1073         $bp = buddypress();
     1089        $bp                             = buddypress();
    10741090        $bp_params['upload_dir_filter'] = '';
    1075         $needs_reset = array();
     1091        $needs_reset                    = array();
    10761092
    10771093        if ( 'user' === $bp_params['object'] && bp_is_active( 'members' ) ) {
     
    10791095
    10801096                if ( ! bp_displayed_user_id() && ! empty( $bp_params['item_id'] ) ) {
    1081                         $needs_reset = array( 'key' => 'displayed_user', 'value' => $bp->displayed_user );
     1097                        $needs_reset            = array(
     1098                                'key'   => 'displayed_user',
     1099                                'value' => $bp->displayed_user,
     1100                        );
    10821101                        $bp->displayed_user->id = $bp_params['item_id'];
    10831102                }
     
    10861105
    10871106                if ( ! bp_get_current_group_id() && ! empty( $bp_params['item_id'] ) ) {
    1088                         $needs_reset = array( 'component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group );
     1107                        $needs_reset               = array(
     1108                                'component' => 'groups',
     1109                                'key'       => 'current_group',
     1110                                'value'     => $bp->groups->current_group,
     1111                        );
    10891112                        $bp->groups->current_group = groups_get_group( $bp_params['item_id'] );
    10901113                }
     
    11091132         */
    11101133        if ( isset( $bp_params['ui_available_width'] ) ) {
    1111                 $bp->avatar_admin->ui_available_width =  (int) $bp_params['ui_available_width'];
     1134                $bp->avatar_admin->ui_available_width = (int) $bp_params['ui_available_width'];
    11121135        }
    11131136
     
    11481171
    11491172                // Upload error reply.
    1150                 bp_attachments_json_response( false, $is_html4, array(
    1151                         'type'    => 'upload_error',
    1152                         'message' => $message,
    1153                 ) );
     1173                bp_attachments_json_response(
     1174                        false,
     1175                        $is_html4,
     1176                        array(
     1177                                'type'    => 'upload_error',
     1178                                'message' => $message,
     1179                        )
     1180                );
    11541181        }
    11551182
     
    11611188
    11621189        // Set the name of the file.
    1163         $name = $_FILES['file']['name'];
     1190        $name       = $_FILES['file']['name'];
    11641191        $name_parts = pathinfo( $name );
    1165         $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) );
     1192        $name       = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) );
    11661193
    11671194        // Finally return the avatar to the editor.
    1168         bp_attachments_json_response( true, $is_html4, array(
    1169                 'name'      => $name,
    1170                 'url'       => $bp->avatar_admin->image->url,
    1171                 'width'     => $uploaded_image[0],
    1172                 'height'    => $uploaded_image[1],
    1173                 'feedback'  => $feedback_message,
    1174         ) );
     1195        bp_attachments_json_response(
     1196                true,
     1197                $is_html4,
     1198                array(
     1199                        'name'     => $name,
     1200                        'url'      => $bp->avatar_admin->image->url,
     1201                        'width'    => $uploaded_image[0],
     1202                        'height'   => $uploaded_image[1],
     1203                        'feedback' => $feedback_message,
     1204                )
     1205        );
    11751206}
    11761207add_action( 'wp_ajax_bp_avatar_upload', 'bp_avatar_ajax_upload' );
     
    11821213 * @since 10.0.0 Adds the `$return` param to eventually return the crop result.
    11831214 *
    1184  * @param string $data    Base64 encoded image.
    1185  * @param int    $item_id Item to associate.
    1186  * @param string $return  Whether to get the crop `array` or a `boolean`. Defaults to `boolean`.
    1187  * @return array|bool True on success, false on failure.
    1188  */
    1189 function bp_avatar_handle_capture( $data = '', $item_id = 0, $return = 'boolean' ) {
     1215 * @param string $data    Optional. Base64 encoded image.
     1216 * @param int    $item_id Optional. Item to associate.
     1217 * @param string $retval  Optional. Whether to get the crop `array` or a `boolean`. Defaults to `boolean`.
     1218 * @return array|bool
     1219 */
     1220function bp_avatar_handle_capture( $data = '', $item_id = 0, $retval = 'boolean' ) {
     1221        $return = $retval;
     1222
    11901223        if ( empty( $data ) || empty( $item_id ) ) {
    11911224                return false;
     
    12291262
    12301263        // It's not a regular upload, we may need to create this folder.
    1231         if( ! is_dir( $avatar_folder_dir ) ) {
     1264        if ( ! is_dir( $avatar_folder_dir ) ) {
    12321265                if ( ! wp_mkdir_p( $avatar_folder_dir ) ) {
    12331266                        return false;
     
    12411274
    12421275                // Crop to default values.
    1243                 $crop_args = array( 'item_id' => $item_id, 'original_file' => $avatar_to_crop, 'crop_x' => 0, 'crop_y' => 0 );
     1276                $crop_args = array(
     1277                        'item_id'       => $item_id,
     1278                        'original_file' => $avatar_to_crop,
     1279                        'crop_x'        => 0,
     1280                        'crop_y'        => 0,
     1281                );
    12441282
    12451283                if ( 'array' === $return ) {
     
    12481286
    12491287                return bp_core_avatar_handle_crop( $crop_args );
    1250         } else {
    1251                 return false;
    1252         }
     1288        }
     1289
     1290        return false;
    12531291}
    12541292
     
    12761314 *     @type int         $crop_y        The vertical starting point of the crop. Default: 0.
    12771315 * }
    1278  * @param string       $return Whether to get the crop `array` or a `boolean`. Defaults to `boolean`.
    1279  * @return array|bool True or the crop result on success, false on failure.
    1280  */
    1281 function bp_core_avatar_handle_crop( $args = '', $return = 'boolean' ) {
     1316 * @param string       $retval Optional. Whether to get the crop `array` or a `boolean`. Defaults to `boolean`.
     1317 * @return array|bool
     1318 */
     1319function bp_core_avatar_handle_crop( $args = '', $retval = 'boolean' ) {
    12821320
    12831321        $r = bp_parse_args(
     
    13181356        }
    13191357
    1320         if ( 'array' === $return ) {
     1358        if ( 'array' === $retval ) {
    13211359                return $cropped;
    13221360        }
     
    13291367 *
    13301368 * @since 2.3.0
    1331  *
    1332  * @return string|null A JSON object containing success data if the crop/capture succeeded
    1333  *                     error message otherwise.
    13341369 */
    13351370function bp_avatar_ajax_set() {
     1371
    13361372        if ( ! bp_is_post_request() ) {
    13371373                wp_send_json_error();
     
    13711407
    13721408                if ( ! $cropped_webcam_avatar ) {
    1373                         wp_send_json_error( array(
    1374                                 'feedback_code' => 1
    1375                         ) );
     1409                        wp_send_json_error(
     1410                                array(
     1411                                        'feedback_code' => 1,
     1412                                )
     1413                        );
    13761414
    13771415                } else {
    13781416                        $return = array(
    1379                                 'avatar' => esc_url(
     1417                                'avatar'        => esc_url(
    13801418                                        bp_core_fetch_avatar(
    13811419                                                array(
     
    14191457                $avatar_dir = 'avatars';
    14201458
    1421         // Defaults to object-avatars dir.
     1459                // Defaults to object-avatars dir.
    14221460        } else {
    14231461                $avatar_dir = sanitize_key( $avatar_data['object'] ) . '-avatars';
     
    14331471                'crop_h'        => $avatar_data['crop_h'],
    14341472                'crop_x'        => $avatar_data['crop_x'],
    1435                 'crop_y'        => $avatar_data['crop_y']
     1473                'crop_y'        => $avatar_data['crop_y'],
    14361474        );
    14371475
     
    14411479        if ( $cropped_avatar ) {
    14421480                $return = array(
    1443                         'avatar' => esc_url(
     1481                        'avatar'        => esc_url(
    14441482                                bp_core_fetch_avatar(
    14451483                                        array(
     
    14681506                wp_send_json_success( $return );
    14691507        } else {
    1470                 wp_send_json_error( array(
    1471                         'feedback_code' => 1,
    1472                 ) );
     1508                wp_send_json_error(
     1509                        array(
     1510                                'feedback_code' => 1,
     1511                        )
     1512                );
    14731513        }
    14741514}
     
    14931533                $user = get_user_by( 'id', absint( $id_or_email ) );
    14941534        } elseif ( $id_or_email instanceof WP_User ) {
    1495                 // User Object
     1535                // User Object.
    14961536                $user = $id_or_email;
    14971537        } elseif ( $id_or_email instanceof WP_Post ) {
    1498                 // Post Object
     1538                // Post Object.
    14991539                $user = get_user_by( 'id', (int) $id_or_email->post_author );
    15001540        } elseif ( $id_or_email instanceof WP_Comment ) {
     
    15211561
    15221562        // Get the BuddyPress avatar URL.
    1523         if ( $bp_avatar = bp_core_fetch_avatar( $args ) ) {
     1563        $bp_avatar = bp_core_fetch_avatar( $args );
     1564        if ( $bp_avatar ) {
    15241565                return $bp_avatar;
    15251566        }
     
    15351576 *
    15361577 * @param array $file The $_FILES array.
    1537  * @return bool True if no errors are found. False if there are errors.
     1578 * @return bool
    15381579 */
    15391580function bp_core_check_avatar_upload( $file ) {
    1540         if ( isset( $file['error'] ) && $file['error'] )
     1581        if ( isset( $file['error'] ) && $file['error'] ) {
    15411582                return false;
     1583        }
    15421584
    15431585        return true;
     
    15531595 */
    15541596function bp_core_check_avatar_size( $file ) {
    1555         if ( $file['file']['size'] > bp_core_avatar_original_max_filesize() )
     1597        if ( $file['file']['size'] > bp_core_avatar_original_max_filesize() ) {
    15561598                return false;
     1599        }
    15571600
    15581601        return true;
     
    15951638 */
    15961639function bp_core_get_allowed_avatar_mimes() {
    1597         $allowed_types  = bp_core_get_allowed_avatar_types();
     1640        $allowed_types = bp_core_get_allowed_avatar_types();
    15981641
    15991642        return bp_attachments_get_allowed_mimes( 'avatar', $allowed_types );
     
    16281671
    16291672        switch ( $type ) {
    1630                 case 'upload_path' :
     1673                case 'upload_path':
    16311674                        $constant = 'BP_AVATAR_UPLOAD_PATH';
    16321675                        $key      = 'basedir';
     
    16341677                        break;
    16351678
    1636                 case 'url' :
     1679                case 'url':
    16371680                        $constant = 'BP_AVATAR_URL';
    16381681                        $key      = 'baseurl';
     
    16401683                        break;
    16411684
    1642                 default :
     1685                default:
    16431686                        return $retval;
    1644 
    1645                         break;
    16461687        }
    16471688
     
    16591700                                $upload_dir = $bp->avatar->upload_dir;
    16601701
    1661                         // No cache, so query for it.
     1702                                // No cache, so query for it.
    16621703                        } else {
    16631704
     
    17021743         * @since 1.2.0
    17031744         *
    1704          * @param string $value Absolute upload path for the WP installation.
     1745         * @param string $upload_path Absolute upload path for the WP installation.
    17051746         */
    17061747        return apply_filters( 'bp_core_avatar_upload_path', bp_core_get_upload_dir() );
     
    17211762         * @since 1.2.0
    17221763         *
    1723          * @param string $value Raw base URL for the root site upload location.
     1764         * @param string $avatar_url Raw base URL for the root site upload location.
    17241765         */
    17251766        return apply_filters( 'bp_core_avatar_url', bp_core_get_upload_dir( 'url' ) );
     
    17361777function bp_get_user_has_avatar( $user_id = 0 ) {
    17371778
    1738         if ( empty( $user_id ) )
     1779        if ( empty( $user_id ) ) {
    17391780                $user_id = bp_displayed_user_id();
     1781        }
    17401782
    17411783        $retval = false;
    1742         if ( bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true, 'html' => false, 'type' => 'full' ) ) != bp_core_avatar_default( 'local' ) )
     1784        if ( bp_core_fetch_avatar(
     1785                array(
     1786                        'item_id' => $user_id,
     1787                        'no_grav' => true,
     1788                        'html'    => false,
     1789                        'type'    => 'full',
     1790                )
     1791        ) !== bp_core_avatar_default( 'local' ) ) {
    17431792                $retval = true;
     1793        }
    17441794
    17451795        /**
     
    17951845         * @since 1.5.0
    17961846         *
    1797          * @param int $value Value for the 'thumb' avatar width setting.
     1847         * @param int $avatar_thumb_width Value for the 'thumb' avatar width setting.
    17981848         */
    17991849        return apply_filters( 'bp_core_avatar_thumb_width', bp_core_avatar_dimension( 'thumb', 'width' ) );
     
    18141864         * @since 1.5.0
    18151865         *
    1816          * @param int $value Value for the 'thumb' avatar height setting.
     1866         * @param int $avatar_thumb_height Value for the 'thumb' avatar height setting.
    18171867         */
    18181868        return apply_filters( 'bp_core_avatar_thumb_height', bp_core_avatar_dimension( 'thumb', 'height' ) );
     
    18331883         * @since 1.5.0
    18341884         *
    1835          * @param int $value Value for the 'full' avatar width setting.
     1885         * @param int $avatar_full_width Value for the 'full' avatar width setting.
    18361886         */
    18371887        return apply_filters( 'bp_core_avatar_full_width', bp_core_avatar_dimension( 'full', 'width' ) );
     
    18521902         * @since 1.5.0
    18531903         *
    1854          * @param int $value Value for the 'full' avatar height setting.
     1904         * @param int $avatar_full_height Value for the 'full' avatar height setting.
    18551905         */
    18561906        return apply_filters( 'bp_core_avatar_full_height', bp_core_avatar_dimension( 'full', 'height' ) );
     
    18711921         * @since 1.5.0
    18721922         *
    1873          * @param int $value Value for the max width.
     1923         * @param int $original_max_width Value for the max width.
    18741924         */
    18751925        return apply_filters( 'bp_core_avatar_original_max_width', (int) buddypress()->avatar->original_max_width );
     
    18901940         * @since 1.5.0
    18911941         *
    1892          * @param int $value Value for the max filesize.
     1942         * @param int $original_max_filesize Value for the max filesize.
    18931943         */
    18941944        return apply_filters( 'bp_core_avatar_original_max_filesize', (int) buddypress()->avatar->original_max_filesize );
     
    19121962                $avatar = BP_AVATAR_DEFAULT;
    19131963
    1914         // Use the local default image.
     1964                // Use the local default image.
    19151965        } elseif ( 'local' === $type ) {
    19161966                $size = '';
     
    19191969                        ( isset( $params['width'] ) && $params['width'] <= 50 )
    19201970                ) {
    1921 
    19221971                        $size = '-50';
    19231972                }
     
    19251974                $avatar = buddypress()->plugin_url . "bp-core/images/mystery-man{$size}.jpg";
    19261975
    1927         // Use Gravatar's mystery person as fallback.
     1976                // Use Gravatar's mystery person as fallback.
    19281977        } else {
    19291978                $size = '';
     
    19822031                $avatar = BP_AVATAR_DEFAULT_THUMB;
    19832032
    1984         // Use the local default image.
     2033                // Use the local default image.
    19852034        } elseif ( 'local' === $type ) {
    19862035                $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man-50.jpg';
    19872036
    1988         // Use Gravatar's mystery person as fallback.
     2037                // Use Gravatar's mystery person as fallback.
    19892038        } else {
    19902039                $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&amp;s=' . bp_core_avatar_thumb_width();
     
    20212070                $reset_w = bp_is_group_admin_screen( 'group-avatar' );
    20222071
    2023         // Group's avatar create screen.
     2072                // Group's avatar create screen.
    20242073        } elseif ( bp_is_group_create() ) {
    20252074                /**
     
    20292078                $reset_w = 'group-avatar' === bp_action_variable( 1 );
    20302079
    2031         // User's change avatar screen.
     2080                // User's change avatar screen.
    20322081        } else {
    20332082                $reset_w = bp_is_user_change_avatar();
     
    20602109                        $retval = ! bp_disable_group_avatar_uploads();
    20612110
    2062                 // Group Manage.
     2111                        // Group Manage.
    20632112                } elseif ( bp_is_group_admin_page() && bp_is_group_admin_screen( 'group-avatar' ) && 'crop-image' !== bp_get_avatar_admin_step() ) {
    20642113                        $retval = ! bp_disable_group_avatar_uploads();
     
    21642213         * @since 10.0.0
    21652214         *
    2166          * @param bool $value True to disable avatar history. False otherwise.
     2215         * @param bool $avatar_history True to disable avatar history. False otherwise.
    21672216         *                    Default: `false`.
    21682217         */
     
    22352284
    22362285        $avatars     = array();
    2237         $history_url = trailingslashit( bp_core_avatar_url() ) .  $avatar_dir . '/' . $item_id . '/history';
     2286        $history_url = trailingslashit( bp_core_avatar_url() ) . $avatar_dir . '/' . $item_id . '/history';
    22382287
    22392288        foreach ( $historic_avatars as $historic_avatar ) {
     
    23182367                        }
    23192368
    2320                         $is_full  = preg_match( "/-bpfull/", $current_avatar->name );
    2321                         $is_thumb = preg_match( "/-bpthumb/", $current_avatar->name );
     2369                        $is_full  = preg_match( '/-bpfull/', $current_avatar->name );
     2370                        $is_thumb = preg_match( '/-bpthumb/', $current_avatar->name );
    23222371
    23232372                        if ( $is_full || $is_thumb ) {
     
    23952444                } else {
    23962445                        foreach ( $avatar_types as $type_key => $avatar_path ) {
    2397                                 $filename  = wp_basename( $avatar_path );
    2398                                 $avatar_id = pathinfo( $filename, PATHINFO_FILENAME );
     2446                                $filename     = wp_basename( $avatar_path );
     2447                                $avatar_id    = pathinfo( $filename, PATHINFO_FILENAME );
    23992448                                $recycle_path = $avatar_dir_path . '/' . str_replace( $avatar_id, $recycle_timestamp . '-bp' . $type_key, $filename );
    24002449
     
    24702519                        $gmdate      = gmdate( 'Y-m-d H:i:s', $avatars_history[ $latest_id ]->last_modified );
    24712520                        $date        = strtotime( get_date_from_gmt( $gmdate ) );
    2472                         $history_url = trailingslashit( bp_core_avatar_url() ) .  $avatar_dir . '/' . $item_id . '/history';
     2521                        $history_url = trailingslashit( bp_core_avatar_url() ) . $avatar_dir . '/' . $item_id . '/history';
    24732522
    24742523                        // Prepare the avatar object for JavaScript.
Note: See TracChangeset for help on using the changeset viewer.