Skip to:
Content

BuddyPress.org


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.