Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/16/2015 10:11:05 PM (10 years ago)
Author:
imath
Message:

Avatar UI: Add Conditional functions and new BP Attachment methods

  • bp_avatar_is_front_edit() checks if the user is editing his or a group avatar on front-end
  • bp_avatar_use_webcam() checks if the Camera feature should be enabled. By default, it is not the case for touch devices as it can introduce some confustions with the possibility of using the camera of the device to take a selfie, save it as an image an upload it using the Browse button of the Avatar UI. Chrome and Firefox are the only browsers supporting getUserMedia.

NB: these two functions can be filtered to disallow the Camera feature or to completely disallow the new Avatar UI if you prefer to carry on using the legacy UI.

BP_Attachment::script_data() and BP_Attachment_Avatar::script_data() are two new methods to build the javascript localization data. The bp_attachment_avatar_params filter is fired if the current object is not a group or a user and can be used to build the params of another object such as a blog. You can also use the filter bp_attachment_avatar_script_data if you need to override data for any object.

Props boonebgorges, DJPaul.

See #6290
See #6278

File:
1 edited

Legend:

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

    r9740 r9755  
    13741374}
    13751375add_action( 'bp_parse_query', 'bp_core_avatar_reset_query', 10, 1 );
     1376
     1377/**
     1378 * Checks whether Avatar UI should be loaded
     1379 *
     1380 * @since  BuddyPress (2.3.0)
     1381 *
     1382 * @return bool True if Avatar UI should load, false otherwise
     1383 */
     1384function bp_avatar_is_front_edit() {
     1385    $retval = false;
     1386
     1387    if ( bp_is_user_change_avatar() && 'crop-image' !== bp_get_avatar_admin_step() ) {
     1388        $retval = ! bp_core_get_root_option( 'bp-disable-avatar-uploads' );
     1389    }
     1390
     1391    if ( bp_is_active( 'groups' ) ) {
     1392        // Group creation
     1393        if ( bp_is_group_create() && bp_is_group_creation_step( 'group-avatar' ) && 'crop-image' !== bp_get_avatar_admin_step() ) {
     1394            $retval = ! bp_core_get_root_option( 'bp-disable-avatar-uploads' );
     1395
     1396        // Group Manage
     1397        } elseif ( bp_is_group_admin_page() && bp_is_group_admin_screen( 'group-avatar' ) && 'crop-image' !== bp_get_avatar_admin_step() ) {
     1398            $retval = ! bp_core_get_root_option( 'bp-disable-avatar-uploads' );
     1399        }
     1400    }
     1401
     1402    /**
     1403     * Use this filter if you need to :
     1404     * - Load the avatar UI for a component that is !groups or !user (return true regarding your conditions)
     1405     * - Completely disable the avatar UI introduced in 2.3 (eg: __return_false())
     1406     *
     1407     * @since  BuddyPress (2.3.0)
     1408     *
     1409     * @var  bool whether to load the Avatar UI
     1410     */
     1411    return apply_filters( 'bp_avatar_is_front_edit', $retval );
     1412}
     1413
     1414/**
     1415 * Checks whether the Webcam Avatar UI part should be loaded
     1416 *
     1417 * @since  BuddyPress (2.3.0)
     1418 *
     1419 * @return bool True to load the Webcam Avatar UI part. False otherwise.
     1420 */
     1421function bp_avatar_use_webcam() {
     1422    /**
     1423     * Do not use the webcam feature for mobile devices
     1424     * to avoid possible confusions.
     1425     */
     1426    if ( wp_is_mobile() ) {
     1427        return false;
     1428    }
     1429
     1430    /**
     1431     * Use this filter if you need to disable the webcam capture feature
     1432     * by returning false.
     1433     *
     1434     * @since  BuddyPress (2.3.0)
     1435     *
     1436     * @var  bool whether to load Webcam Avatar UI part
     1437     */
     1438    return apply_filters( 'bp_avatar_use_webcam', true );
     1439}
Note: See TracChangeset for help on using the changeset viewer.