Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/09/2015 05:07:56 AM (10 years ago)
Author:
tw2113
Message:

More updates to BP-Core docs.

See #6398.

File:
1 edited

Legend:

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

    r10012 r10039  
    11<?php
    2 
    32/**
    43 * BuddyPress Avatars.
    5  */
    6 
    7 // Exit if accessed directly
     4 *
     5 * @package BuddyPress
     6 */
     7
     8// Exit if accessed directly.
    89defined( 'ABSPATH' ) || exit;
    910
    10 /***
     11/**
    1112 * Set up the constants we need for avatar support.
    1213 */
     
    326327    /** Sanity Checks *********************************************************/
    327328
    328     // Get a fallback for the 'alt' parameter, create html output
     329    // Get a fallback for the 'alt' parameter, create html output.
    329330    if ( empty( $params['alt'] ) ) {
    330331        $params['alt'] = __( 'Profile Photo', 'buddypress' );
     
    332333    $html_alt = ' alt="' . esc_attr( $params['alt'] ) . '"';
    333334
    334     // Filter image title and create html string
     335    // Filter image title and create html string.
    335336    $html_title = '';
    336337
     
    351352    }
    352353
    353     // Set CSS ID and create html string
     354    // Set CSS ID and create html string.
    354355    $html_css_id = '';
    355356
     
    531532                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id  . $html_width . $html_height . $html_alt . $html_title . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    532533
    533                 // ...or only the URL
     534            // ...or only the URL
    534535            } else {
    535536
     
    612613        }
    613614
    614         // No avatar was found, and we've been told not to use a gravatar.
     615    // No avatar was found, and we've been told not to use a gravatar.
    615616    } else {
    616617
     
    644645 * @param array|string $args {
    645646 *     Array of function parameters.
    646  *     @type bool|int $item_id ID of the item whose avatar you're deleting.
    647  *           Defaults to the current item of type $object.
    648  *     @type string $object Object type of the item whose avatar you're
    649  *           deleting. 'user', 'group', 'blog', or custom. Default: 'user'.
     647 *     @type bool|int    $item_id    ID of the item whose avatar you're deleting.
     648 *                                   Defaults to the current item of type $object.
     649 *     @type string      $object     Object type of the item whose avatar you're
     650 *                                   deleting. 'user', 'group', 'blog', or custom.
     651 *                                   Default: 'user'.
    650652 *     @type bool|string $avatar_dir Subdirectory where avatar is located.
    651  *           Default: false, which falls back on the default location
    652  *           corresponding to the $object.
     653 *                                   Default: false, which falls back on the default location
     654 *                                   corresponding to the $object.
    653655 * }
    654656 * @return bool True on success, false on failure.
     
    730732 */
    731733function bp_avatar_ajax_delete() {
    732     // Bail if not a POST action
     734    // Bail if not a POST action.
    733735    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
    734736        wp_send_json_error();
     
    810812    }
    811813
    812     // Setup some variables
     814    // Setup some variables.
    813815    $bp          = buddypress();
    814816    $upload_path = bp_core_avatar_upload_path();
    815817
    816     // Upload the file
     818    // Upload the file.
    817819    $avatar_attachment = new BP_Attachment_Avatar();
    818820    $bp->avatar_admin->original = $avatar_attachment->upload( $file, $upload_dir_filter );
    819821
    820     // In case of an error, stop the process and display a feedback to the user
     822    // In case of an error, stop the process and display a feedback to the user.
    821823    if ( ! empty( $bp->avatar_admin->original['error'] ) ) {
    822824        bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
     
    824826    }
    825827
    826     // Maybe resize
     828    // Maybe resize.
    827829    $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'] );
    828830    $bp->avatar_admin->image   = new stdClass();
     
    838840    }
    839841
    840     // Check for WP_Error on what should be an image
     842    // Check for WP_Error on what should be an image.
    841843    if ( is_wp_error( $bp->avatar_admin->image->dir ) ) {
    842844        bp_core_add_message( sprintf( __( 'Upload failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->image->dir->get_error_message() ), 'error' );
     
    844846    }
    845847
    846     // If the uploaded image is smaller than the "full" dimensions, throw a warning
     848    // If the uploaded image is smaller than the "full" dimensions, throw a warning.
    847849    if ( $avatar_attachment->is_too_small( $bp->avatar_admin->image->file ) ) {
    848850        bp_core_add_message( sprintf( __( 'You have selected an image that is smaller than recommended. For best results, upload a picture larger than %d x %d pixels.', 'buddypress' ), bp_core_avatar_full_width(), bp_core_avatar_full_height() ), 'error' );
    849851    }
    850852
    851     // Set the url value for the image
     853    // Set the url value for the image.
    852854    $bp->avatar_admin->image->url = bp_core_avatar_url() . $bp->avatar_admin->image->dir;
    853855
     
    10051007
    10061008 /**
    1007  * Handle avatar webcam capture.
    1008  *
    1009  * @since BuddyPress (2.3.0)
    1010  *
    1011  * @param string $data     Base64 encoded image.
    1012  * @param int    $item_id.
     1009  * Handle avatar webcam capture.
    10131010  *
    1014  * @return bool True on success, false on failure.
    1015  */
     1011  * @since BuddyPress (2.3.0)
     1012  *
     1013  * @param string $data    Base64 encoded image.
     1014  * @param int    $item_id Item to associate.
     1015  *
     1016  * @return bool True on success, false on failure.
     1017  */
    10161018function bp_avatar_handle_capture( $data = '', $item_id = 0 ) {
    10171019    if ( empty( $data ) || empty( $item_id ) ) {
     
    10211023    $avatar_dir = bp_core_avatar_upload_path() . '/avatars';
    10221024
    1023     // It's not a regular upload, we may need to create this folder
     1025    // It's not a regular upload, we may need to create this folder.
    10241026    if ( ! file_exists( $avatar_dir ) ) {
    10251027        if ( ! wp_mkdir_p( $avatar_dir ) ) {
     
    10401042    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', $avatar_dir . '/' . $item_id, $item_id, 'user', 'avatars' );
    10411043
    1042     // It's not a regular upload, we may need to create this folder
     1044    // It's not a regular upload, we may need to create this folder.
    10431045    if( ! is_dir( $avatar_folder_dir ) ) {
    10441046        if ( ! wp_mkdir_p( $avatar_folder_dir ) ) {
     
    14491451    }
    14501452
    1451     // See if the value has already been calculated and stashed in the $bp global
     1453    // See if the value has already been calculated and stashed in the $bp global.
    14521454    if ( isset( $bp->avatar->$type ) ) {
    14531455        $retval = $bp->avatar->$type;
    14541456    } else {
    1455         // If this value has been set in a constant, just use that
     1457        // If this value has been set in a constant, just use that.
    14561458        if ( defined( $constant ) ) {
    14571459            $retval = constant( $constant );
    14581460        } else {
    14591461
    1460             // Use cached upload dir data if available
     1462            // Use cached upload dir data if available.
    14611463            if ( ! empty( $bp->avatar->upload_dir ) ) {
    14621464                $upload_dir = $bp->avatar->upload_dir;
    14631465
    1464             // No cache, so query for it
     1466            // No cache, so query for it.
    14651467            } else {
    14661468
    1467                 // Get upload directory information from current site
     1469                // Get upload directory information from current site.
    14681470                $upload_dir = bp_upload_dir();
    14691471
    1470                 // Stash upload directory data for later use
     1472                // Stash upload directory data for later use.
    14711473                $bp->avatar->upload_dir = $upload_dir;
    14721474            }
    14731475
    1474             // Directory does not exist and cannot be created
     1476            // Directory does not exist and cannot be created.
    14751477            if ( ! empty( $upload_dir['error'] ) ) {
    14761478                $retval = '';
     
    14881490        }
    14891491
    1490         // Stash in $bp for later use
     1492        // Stash in $bp for later use.
    14911493        $bp->avatar->$type = $retval;
    14921494    }
Note: See TracChangeset for help on using the changeset viewer.