Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/09/2016 11:40:10 AM (10 years ago)
Author:
djpaul
Message:

Add filters and actions to support short-circuiting of standard avatar/cover image uploads/crops.

Fixes #6948

Props DJPaul, imath

File:
1 edited

Legend:

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

    r10497 r10641  
    411411        ), 'attachments_get_attachment_src' );
    412412
     413        /**
     414         * Filters whether or not to handle fetching a BuddyPress image attachment.
     415         *
     416         * If you want to override this function, make sure you return false.
     417         *
     418         * @since 2.5.1
     419         *
     420         * @param null|string $value If null is returned, proceed with default behaviour. Otherwise, value returned verbatim.
     421         * @param array $r {
     422         *     @type string $object_dir The object dir (eg: members/groups). Defaults to members.
     423         *     @type int    $item_id    The object id (eg: a user or a group id). Defaults to current user.
     424         *     @type string $type       The type of the attachment which is also the subdir where files are saved.
     425         *                              Defaults to 'cover-image'
     426         *     @type string $file       The name of the file.
     427         * }
     428         */
     429        $pre_filter = apply_filters( 'bp_attachments_pre_get_attachment', null, $r );
     430        if ( $pre_filter !== null ) {
     431                return $pre_filter;
     432        }
     433
    413434        // Get BuddyPress Attachments Uploads Dir datas.
    414435        $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
     
    478499function bp_attachments_delete_file( $args = array() ) {
    479500        $attachment_path = bp_attachments_get_attachment( 'path', $args );
     501
     502        /**
     503         * Filters whether or not to handle deleting an existing BuddyPress attachment.
     504         *
     505         * If you want to override this function, make sure you return false.
     506         *
     507         * @since 2.5.1
     508         *
     509         * @param bool $value Whether or not to delete the BuddyPress attachment.
     510         * @param array Array of arguments for the attachment deletion.
     511         */
     512        if ( ! apply_filters( 'bp_attachments_pre_delete_file', true, $args ) ) {
     513                return true;
     514        }
    480515
    481516        if ( empty( $attachment_path ) ) {
     
    12241259        }
    12251260
     1261        /**
     1262         * Filters whether or not to handle cover image uploading.
     1263         *
     1264         * If you want to override this function, make sure you return an array with the 'result' key set.
     1265         *
     1266         * @since 2.5.1
     1267         *
     1268         * @param array $value
     1269         * @param array $bp_params
     1270         * @param array $needs_reset Stores original value of certain globals we need to revert to later.
     1271         * @param array $object_data
     1272         */
     1273        $pre_filter = apply_filters( 'bp_attachments_pre_cover_image_ajax_upload', array(), $bp_params, $needs_reset, $object_data );
     1274        if ( isset( $pre_filter['result'] ) ) {
     1275                bp_attachments_json_response( $pre_filter['result'], $is_html4, $pre_filter );
     1276        }
     1277
    12261278        $cover_image_attachment = new BP_Attachment_Cover_Image();
    12271279        $uploaded = $cover_image_attachment->upload( $_FILES );
Note: See TracChangeset for help on using the changeset viewer.