Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/15/2015 07:57:03 PM (9 years ago)
Author:
tw2113
Message:

[Samus Aran]
I first battled the documentation inconsistencies on planet Zebes. It was there that I foiled the plans of the
Space Pirate leader Mother Brain to use the issues to attack galactic civilization...

I next fought the inconsistencies on their homeworld SR388. I completely eradicated them except for an @since tag,
which after hatching followed me like a confused child...

I personally delivered it to the Galactic Research Station at Ceres so scientists could study its energy production qualities...

The scientists' findings were astounding! They discovered that the powers of the docs inconsistencies
might be harnessed for the good of galactic civilization!

Satisfied that all was well, I left the station to seek a new bounty to hunt. But, I had hardly gone beyond the asteroid
belt when I picked up a distress signal!

Ceres station was under attack!

More documentation cleanup for part of BP-Core component.

See #6398.

File:
1 edited

Legend:

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

    r10193 r10356  
    1717 * match with our needs.
    1818 *
    19  * @since  2.3.0
     19 * @since 2.3.0
    2020 *
    2121 * @return bool True if WordPress is 3.9+, false otherwise.
     
    2626
    2727/**
    28  * Get the Attachments Uploads dir data
    29  *
    30  * @since  2.4.0
    31  *
    32  * @param  string        $data The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'
    33  *                       Leave empty to get all datas.
    34  * @return string|array  The needed Upload dir data.
     28 * Get the Attachments Uploads dir data.
     29 *
     30 * @since 2.4.0
     31 *
     32 * @param string $data The data to get. Possible values are: 'dir', 'basedir' & 'baseurl'.
     33 *                     Leave empty to get all datas.
     34 * @return string|array The needed Upload dir data.
    3535 */
    3636function bp_attachments_uploads_dir_get( $data = '' ) {
     
    4343        $upload_data = bp_upload_dir();
    4444
    45         // Build the Upload data array for BuddyPress attachments
     45        // Build the Upload data array for BuddyPress attachments.
    4646        foreach ( $upload_data as $key => $value ) {
    4747            if ( 'basedir' === $key || 'baseurl' === $key ) {
     
    5252        }
    5353
    54         // Add the dir to the array
     54        // Add the dir to the array.
    5555        $upload_data['dir'] = $attachments_dir;
    5656
     
    6565     * Filter here to edit the Attachments upload dir data.
    6666     *
    67      * @since  2.4.0
    68      *
    69      * @param  string|array $retval      The needed Upload dir data or the full array of data
    70      * @param  string       $data        The data requested
     67     * @since 2.4.0
     68     *
     69     * @param string|array $retval The needed Upload dir data or the full array of data
     70     * @param string       $data   The data requested
    7171     */
    7272    return apply_filters( 'bp_attachments_uploads_dir_get', $retval, $data );
     
    7474
    7575/**
    76  * Get the max upload file size for any attachment
    77  *
    78  * @since  2.4.0
    79  *
    80  * @param  string $type A string to inform about the type of attachment
    81  *                      we wish to get the max upload file size for
    82  * @return int    max upload file size for any attachment
     76 * Get the max upload file size for any attachment.
     77 *
     78 * @since 2.4.0
     79 *
     80 * @param string $type A string to inform about the type of attachment
     81 *                     we wish to get the max upload file size for.
     82 * @return int Max upload file size for any attachment.
    8383 */
    8484function bp_attachments_get_max_upload_file_size( $type = '' ) {
     
    9494     * Filter here to edit the max upload file size.
    9595     *
    96      * @since  2.4.0
    97      *
    98      * @param  int    $fileupload_maxk Max upload file size for any attachment
    99      * @param  string $type            The attachment type (eg: 'avatar' or 'cover_image')
     96     * @since 2.4.0
     97     *
     98     * @param int    $fileupload_maxk Max upload file size for any attachment.
     99     * @param string $type            The attachment type (eg: 'avatar' or 'cover_image').
    100100     */
    101101    return apply_filters( 'bp_attachments_get_max_upload_file_size', $fileupload_maxk, $type );
     
    103103
    104104/**
    105  * Get allowed types for any attachment
    106  *
    107  * @since  2.4.0
    108  *
    109  * @param  string $type The extension types to get.
    110  *                       Default: 'avatar'
    111  * @return array         The list of allowed extensions for attachments
     105 * Get allowed types for any attachment.
     106 *
     107 * @since 2.4.0
     108 *
     109 * @param string $type The extension types to get.
     110 *                     Default: 'avatar'.
     111 * @return array The list of allowed extensions for attachments.
    112112 */
    113113function bp_attachments_get_allowed_types( $type = 'avatar' ) {
    114     // Defaults to BuddyPress supported image extensions
     114    // Defaults to BuddyPress supported image extensions.
    115115    $exts = array( 'jpeg', 'gif', 'png' );
    116116
    117117    /**
    118118     * It's not a BuddyPress feature, get the allowed extensions
    119      * matching the $type requested
     119     * matching the $type requested.
    120120     */
    121121    if ( 'avatar' !== $type && 'cover_image' !== $type ) {
    122         // Reset the default exts
     122        // Reset the default exts.
    123123        $exts = array();
    124124
     
    136136
    137137                /**
    138                  * Search for allowed mimes matching the type
     138                 * Search for allowed mimes matching the type.
    139139                 *
    140                  * eg: using 'application/vnd.oasis' as the $type
     140                 * Eg: using 'application/vnd.oasis' as the $type
    141141                 * parameter will get all OpenOffice extensions supported
    142142                 * by WordPress and allowed for the current user.
     
    148148                $allowed_types = array_keys( $allowed_mimes );
    149149
    150                 // Loop to explode keys using '|'
     150                // Loop to explode keys using '|'.
    151151                foreach ( $allowed_types as $allowed_type ) {
    152152                    $t = explode( '|', $allowed_type );
     
    160160     * Filter here to edit the allowed extensions by attachment type.
    161161     *
    162      * @since  2.4.0
    163      *
    164      * @param  array  $exts List of allowed extensions
    165      * @param  string $type The requested file type
     162     * @since 2.4.0
     163     *
     164     * @param array  $exts List of allowed extensions.
     165     * @param string $type The requested file type.
    166166     */
    167167    return apply_filters( 'bp_attachments_get_allowed_types', $exts, $type );
     
    173173 * @since 2.4.0
    174174 *
    175  * @param  string $type         The extension types to get (Optional).
    176  * @param  array $allowed_types List of allowed extensions
    177  * @return array                List of allowed mime types
     175 * @param string $type          The extension types to get (Optional).
     176 * @param array  $allowed_types List of allowed extensions.
     177 * @return array List of allowed mime types.
    178178 */
    179179function bp_attachments_get_allowed_mimes( $type = '', $allowed_types = array() ) {
     
    196196
    197197/**
    198  * Check the uploaded attachment type is allowed
    199  *
    200  * @since  2.4.0
    201  *
    202  * @param  string $file          Full path to the file.
    203  * @param  string $filename      The name of the file (may differ from $file due to $file being
    204  *                               in a tmp directory).
    205  * @param  array  $allowed_mimes The attachment allowed mimes (Required)
    206  * @return bool                  True if the attachment type is allowed. False otherwise
     198 * Check the uploaded attachment type is allowed.
     199 *
     200 * @since 2.4.0
     201 *
     202 * @param string $file          Full path to the file.
     203 * @param string $filename      The name of the file (may differ from $file due to $file being
     204 *                              in a tmp directory).
     205 * @param array  $allowed_mimes The attachment allowed mimes (Required).
     206 * @return bool True if the attachment type is allowed. False otherwise
    207207 */
    208208function bp_attachments_check_filetype( $file, $filename, $allowed_mimes ) {
     
    221221 * @since 2.4.0
    222222 *
    223  * @param  string $type        The attachment type to create (avatar or cover_image). Default: avatar.
    224  * @param  array  $args {
     223 * @param string $type The attachment type to create (avatar or cover_image). Default: avatar.
     224 * @param array  $args {
    225225 *     @type int    $item_id   The ID of the object (Required). Default: 0.
    226226 *     @type string $object    The object type (eg: group, user, blog) (Required). Default: 'user'.
     
    232232 *     @type int    $crop_y    The vertical starting point of the crop. Default: 0.
    233233 * }
    234  * @return bool  True on success, false otherwise.
     234 * @return bool True on success, false otherwise.
    235235 */
    236236function bp_attachments_create_item_type( $type = 'avatar', $args = array() ) {
     
    254254    }
    255255
    256     // Make sure the file path is safe
     256    // Make sure the file path is safe.
    257257    if ( 0 !== validate_file( $r['image'] ) ) {
    258258        return false;
    259259    }
    260260
    261     // Set the component if not already done
     261    // Set the component if not already done.
    262262    if ( empty( $r['component'] ) ) {
    263263        if ( 'user' === $r['object'] ) {
     
    277277    }
    278278
    279     // Init the Attachment data
     279    // Init the Attachment data.
    280280    $attachment_data = array();
    281281
    282282    if ( 'avatar' === $type ) {
    283         // Set crop width for the avatar if not given
     283        // Set crop width for the avatar if not given.
    284284        if ( empty( $r['crop_w'] ) ) {
    285285            $r['crop_w'] = bp_core_avatar_full_width();
    286286        }
    287287
    288         // Set crop height for the avatar if not given
     288        // Set crop height for the avatar if not given.
    289289        if ( empty( $r['crop_h'] ) ) {
    290290            $r['crop_h'] = bp_core_avatar_full_height();
     
    294294            $dir_args = array( $r['item_id'] );
    295295
    296             // In case  of xprofile, we need an extra argument
     296            // In case  of xprofile, we need an extra argument.
    297297            if ( 'xprofile' === $r['component'] ) {
    298298                $dir_args = array( false, $r['item_id'] );
     
    304304        $attachment_data = bp_attachments_uploads_dir_get();
    305305
    306         // Default to members for xProfile
     306        // Default to members for xProfile.
    307307        $object_subdir = 'members';
    308308
     
    311311        }
    312312
    313         // Set Subdir
     313        // Set Subdir.
    314314        $attachment_data['subdir'] = $object_subdir . '/' . $r['item_id'] . '/cover-image';
    315315
    316         // Set Path
     316        // Set Path.
    317317        $attachment_data['path'] = trailingslashit( $attachment_data['basedir'] ) . $attachment_data['subdir'];
    318318    }
     
    322322    }
    323323
    324     // It's not a regular upload, we may need to create some folders
     324    // It's not a regular upload, we may need to create some folders.
    325325    if ( ! is_dir( $attachment_data['path'] ) ) {
    326326        if ( ! wp_mkdir_p( $attachment_data['path'] ) ) {
     
    329329    }
    330330
    331     // Set the image name and path
     331    // Set the image name and path.
    332332    $image_file_name = wp_unique_filename( $attachment_data['path'], basename( $r['image'] ) );
    333333    $image_file_path = $attachment_data['path'] . '/' . $image_file_name;
    334334
    335     // Copy the image file into the avatar dir
     335    // Copy the image file into the avatar dir.
    336336    if ( ! copy( $r['image'], $image_file_path ) ) {
    337337        return false;
    338338    }
    339339
    340     // Init the response
     340    // Init the response.
    341341    $created = false;
    342342
     
    354354        ) );
    355355
    356     // It's a cover image we need to fit it to feature's dimensions
     356    // It's a cover image we need to fit it to feature's dimensions.
    357357    } elseif ( 'cover_image' === $type ) {
    358358        $cover_image = bp_attachments_cover_image_generate_file( array(
     
    365365    }
    366366
    367     // Remove copied file if it fails
     367    // Remove copied file if it fails.
    368368    if ( ! $created ) {
    369369        @unlink( $image_file_path );
    370370    }
    371371
    372     // Return the response
     372    // Return the response.
    373373    return $created;
    374374}
    375375
    376376/**
    377  * Get the url or the path for a type of attachment
    378  *
    379  * @since  2.4.0
    380  *
    381  * @param  string $data whether to get the url or the path
    382  * @param  array  $args {
     377 * Get the url or the path for a type of attachment.
     378 *
     379 * @since 2.4.0
     380 *
     381 * @param string $data whether to get the url or the path.
     382 * @param array  $args {
    383383 *     @type string $object_dir  The object dir (eg: members/groups). Defaults to members.
    384384 *     @type int    $item_id     The object id (eg: a user or a group id). Defaults to current user.
     
    387387 *     @type string $file        The name of the file.
    388388 * }
    389  * @return string|bool the url or the path to the attachment, false otherwise
     389 * @return string|bool The url or the path to the attachment, false otherwise
    390390 */
    391391function bp_attachments_get_attachment( $data = 'url', $args = array() ) {
    392     // Default value
     392    // Default value.
    393393    $attachment_data = false;
    394394
     
    400400    ), 'attachments_get_attachment_src' );
    401401
    402     // Get BuddyPress Attachments Uploads Dir datas
     402    // Get BuddyPress Attachments Uploads Dir datas.
    403403    $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
    404404
     
    424424        $file = false;
    425425
    426         // Open the directory and get the first file
     426        // Open the directory and get the first file.
    427427        if ( $att_dir = opendir( $type_dir ) ) {
    428428
    429429            while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) {
    430                 // Look for the first file having the type in its name
     430                // Look for the first file having the type in its name.
    431431                if ( false !== strpos( $attachment_file, $r['type'] ) && empty( $file ) ) {
    432432                    $file = $attachment_file;
     
    453453 * Delete an attachment for the given arguments
    454454 *
    455  * @since  2.4.0
    456  *
    457  * @param  array $args
    458  * @see    bp_attachments_get_attachment() For more information on accepted arguments.
    459  * @return bool True if the attachment was deleted, false otherwise
     455 * @since 2.4.0
     456 *
     457 * @see bp_attachments_get_attachment() For more information on accepted arguments.
     458 *
     459 * @param array $args Array of arguments for the attachment deletion.
     460 * @return bool True if the attachment was deleted, false otherwise.
    460461 */
    461462function bp_attachments_delete_file( $args = array() ) {
     
    473474 * Get the BuddyPress Plupload settings.
    474475 *
    475  * @since  2.3.0
    476  *
    477  * @return array list of BuddyPress Plupload settings.
     476 * @since 2.3.0
     477 *
     478 * @return array List of BuddyPress Plupload settings.
    478479 */
    479480function bp_attachments_get_plupload_default_settings() {
     
    523524     * @since 2.3.0
    524525     *
    525      * @param array $params Default Plupload parameters array.
     526     * @param array $settings Default Plupload parameters array.
    526527     */
    527528    return apply_filters( 'bp_attachments_get_plupload_default_settings', $settings );
     
    531532 * Builds localization strings for the BuddyPress Uploader scripts.
    532533 *
    533  * @since  2.3.0
     534 * @since 2.3.0
    534535 *
    535536 * @return array Plupload default localization strings.
    536537 */
    537538function bp_attachments_get_plupload_l10n() {
    538     // Localization strings
     539    // Localization strings.
    539540    return apply_filters( 'bp_attachments_get_plupload_l10n', array(
    540541            'queue_limit_exceeded'      => __( 'You have attempted to queue too many files.', 'buddypress' ),
     
    567568 * Enqueues the script needed for the Uploader UI.
    568569 *
    569  * @see  BP_Attachment::script_data() && BP_Attachment_Avatar::script_data() for examples showing how
     570 * @see BP_Attachment::script_data() && BP_Attachment_Avatar::script_data() for examples showing how
    570571 * to set specific script data.
    571572 *
    572  * @since  2.3.0
    573  *
    574  * @param  string $class name of the class extending BP_Attachment (eg: BP_Attachment_Avatar).
    575  *
     573 * @since 2.3.0
     574 *
     575 * @param string $class Name of the class extending BP_Attachment (eg: BP_Attachment_Avatar).
    576576 * @return null|WP_Error
    577577 */
     
    586586    }
    587587
    588     // Get an instance of the class and get the script data
     588    // Get an instance of the class and get the script data.
    589589    $attachment = new $class;
    590590    $script_data  = $attachment->script_data();
     
    607607    }
    608608
    609     // Get the BuddyPress uploader strings
     609    // Get the BuddyPress uploader strings.
    610610    $strings = bp_attachments_get_plupload_l10n();
    611611
    612     // Get the BuddyPress uploader settings
     612    // Get the BuddyPress uploader settings.
    613613    $settings = bp_attachments_get_plupload_default_settings();
    614614
    615     // Set feedback messages
     615    // Set feedback messages.
    616616    if ( ! empty( $args['feedback_messages'] ) ) {
    617617        $strings['feedback_messages'] = $args['feedback_messages'];
    618618    }
    619619
    620     // Use a temporary var to ease manipulation
     620    // Use a temporary var to ease manipulation.
    621621    $defaults = $settings['defaults'];
    622622
    623     // Set the upload action
     623    // Set the upload action.
    624624    $defaults['multipart_params']['action'] = $args['action'];
    625625
    626     // Set BuddyPress upload parameters if provided
     626    // Set BuddyPress upload parameters if provided.
    627627    if ( ! empty( $args['bp_params'] ) ) {
    628628        $defaults['multipart_params']['bp_params'] = $args['bp_params'];
    629629    }
    630630
    631     // Merge other arguments
     631    // Merge other arguments.
    632632    $ui_args = array_intersect_key( $args, array(
    633633        'file_data_name' => true,
     
    643643    }
    644644
    645     // Specific to BuddyPress Avatars
     645    // Specific to BuddyPress Avatars.
    646646    if ( 'bp_avatar_upload' === $defaults['multipart_params']['action'] ) {
    647647
    648         // Include the cropping informations for avatars
     648        // Include the cropping informations for avatars.
    649649        $settings['crop'] = array(
    650650            'full_h'  => bp_core_avatar_full_height(),
     
    655655        $defaults['multi_selection'] = false;
    656656
    657         // Does the object already has an avatar set
     657        // Does the object already has an avatar set.
    658658        $has_avatar = $defaults['multipart_params']['bp_params']['has_avatar'];
    659659
    660         // What is the object the avatar belongs to
     660        // What is the object the avatar belongs to.
    661661        $object = $defaults['multipart_params']['bp_params']['object'];
    662662
    663         // Init the Avatar nav
     663        // Init the Avatar nav.
    664664        $avatar_nav = array(
    665665            'upload' => array( 'id' => 'upload', 'caption' => __( 'Upload', 'buddypress' ), 'order' => 0  ),
    666666
    667             // The delete view will only show if the object has an avatar
     667            // The delete view will only show if the object has an avatar.
    668668            'delete' => array( 'id' => 'delete', 'caption' => __( 'Delete', 'buddypress' ), 'order' => 100, 'hide' => (int) ! $has_avatar ),
    669669        );
    670670
    671         // Create the Camera Nav if the WebCam capture feature is enabled
     671        // Create the Camera Nav if the WebCam capture feature is enabled.
    672672        if ( bp_avatar_use_webcam() && 'user' === $object ) {
    673673            $avatar_nav['camera'] = array( 'id' => 'camera', 'caption' => __( 'Take Photo', 'buddypress' ), 'order' => 10 );
    674674
    675             // Set warning messages
     675            // Set warning messages.
    676676            $strings['camera_warnings'] = array(
    677677                'requesting'  => __( 'Please allow us to access to your camera.', 'buddypress'),
     
    691691         * @since 2.3.0
    692692         *
    693          * @param array $avatar_nav An associative array of available nav items where each item is an array organized this way:
    694          * $avatar_nav[ $nav_item_id ] {
     693         * @param array  $avatar_nav {
     694         *     An associative array of available nav items where each item is an array organized this way:
     695         *     $avatar_nav[ $nav_item_id ].
    695696         *     @type string $nav_item_id The nav item id in lower case without special characters or space.
    696697         *     @type string $caption     The name of the item nav that will be displayed in the nav.
     
    700701         *                               (only used for the delete nav item).
    701702         * }
    702          * @param string $object the object the avatar belongs to (eg: user or group)
     703         * @param string $object The object the avatar belongs to (eg: user or group).
    703704         */
    704705        $settings['nav'] = bp_sort_by_key( apply_filters( 'bp_attachments_avatar_nav', $avatar_nav, $object ), 'order', 'num' );
    705706
    706     // Specific to BuddyPress cover images
     707    // Specific to BuddyPress cover images.
    707708    } elseif ( 'bp_cover_image_upload' === $defaults['multipart_params']['action'] ) {
    708709
     
    710711        $defaults['multi_selection'] = false;
    711712
    712         // Default cover component is xprofile
     713        // Default cover component is xprofile.
    713714        $cover_component = 'xprofile';
    714715
    715         // Get the object we're editing the cover image of
     716        // Get the object we're editing the cover image of.
    716717        $object = $defaults['multipart_params']['bp_params']['object'];
    717718
    718         // Set the cover component according to the object
     719        // Set the cover component according to the object.
    719720        if ( 'group' === $object ) {
    720721            $cover_component = 'groups';
     
    722723            $cover_component = apply_filters( 'bp_attachments_cover_image_ui_component', $cover_component );
    723724        }
    724         // Get cover image advised dimensions
     725        // Get cover image advised dimensions.
    725726        $cover_dimensions = bp_attachments_get_cover_image_dimensions( $cover_component );
    726727
    727         // Set warning messages
     728        // Set warning messages.
    728729        $strings['cover_image_warnings'] = apply_filters( 'bp_attachments_cover_image_ui_warnings', array(
    729730            'dimensions'  => sprintf(
     
    735736    }
    736737
    737     // Set Plupload settings
     738    // Set Plupload settings.
    738739    $settings['defaults'] = $defaults;
    739740
     
    783784 * Check the current user's capability to edit an avatar for a given object.
    784785 *
    785  * @since  2.3.0
    786  *
    787  * @param  string $capability The capability to check.
    788  * @param  array  $args       An array containing the item_id and the object to check.
    789  *
     786 * @since 2.3.0
     787 *
     788 * @param string $capability The capability to check.
     789 * @param array  $args       An array containing the item_id and the object to check.
    790790 * @return bool
    791791 */
     
    798798         */
    799799        if ( isset( $args['item_id'] ) && isset( $args['object'] ) ) {
    800             // Group profile photo
     800            // Group profile photo.
    801801            if ( bp_is_active( 'groups' ) && 'group' === $args['object'] ) {
    802802                if ( bp_is_group_create() ) {
     
    805805                    $can = (bool) groups_is_user_admin( bp_loggedin_user_id(), $args['item_id'] ) || bp_current_user_can( 'bp_moderate' );
    806806                }
    807             // User profile photo
     807            // User profile photo.
    808808            } elseif ( bp_is_active( 'xprofile' ) && 'user' === $args['object'] ) {
    809809                $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can( 'bp_moderate' );
     
    828828 * Send a JSON response back to an Ajax upload request.
    829829 *
    830  * @since  2.3.0
    831  *
    832  * @param  bool  $success  True for a success, false otherwise.
    833  * @param  bool  $is_html4 True if the Plupload runtime used is html4, false otherwise.
    834  * @param  mixed $data     Data to encode as JSON, then print and die.
     830 * @since 2.3.0
     831 *
     832 * @param bool  $success  True for a success, false otherwise.
     833 * @param bool  $is_html4 True if the Plupload runtime used is html4, false otherwise.
     834 * @param mixed $data     Data to encode as JSON, then print and die.
    835835 */
    836836function bp_attachments_json_response( $success, $is_html4 = false, $data = null ) {
     
    841841    }
    842842
    843     // Send regular json response
     843    // Send regular json response.
    844844    if ( ! $is_html4 ) {
    845845        wp_send_json( $response );
     
    863863 *
    864864 * @param string $slug Template part slug. eg 'uploader' for 'uploader.php'.
    865  *
    866865 * @return bool
    867866 */
     
    892891 * Get the cover image settings
    893892 *
    894  * @since  2.4.0
    895  *
    896  * @param  string $component the component to get the settings for ("xprofile" for user or "groups")
    897  * @return array            the cover image settings
     893 * @since 2.4.0
     894 *
     895 * @param string $component The component to get the settings for ("xprofile" for user or "groups").
     896 * @return array The cover image settings.
    898897 */
    899898function bp_attachments_get_cover_image_settings( $component = 'xprofile' ) {
    900     // Default parameters
     899    // Default parameters.
    901900    $args = array();
    902901
    903     // First look in BP Theme Compat
     902    // First look in BP Theme Compat.
    904903    $cover_image = bp_get_theme_compat_feature( 'cover_image' );
    905904
     
    911910     * Then let people override/set the feature using this dynamic filter
    912911     *
    913      * eg: for the user's profile cover image use :
     912     * Eg: for the user's profile cover image use:
    914913     * add_filter( 'bp_before_xprofile_cover_image_settings_parse_args', 'your_filter', 10, 1 );
    915914     *
    916915     * @since  2.4.0
    917916     *
    918      * @param array $settings the cover image settings
     917     * @param array $settings The cover image settings
    919918     */
    920919    $settings = bp_parse_args( $args, array(
     
    931930    }
    932931
    933     // Current component is not supported
     932    // Current component is not supported.
    934933    if ( ! in_array( $component, $settings['components'] ) ) {
    935934        return false;
    936935    }
    937936
    938     // Finally return the settings
     937    // Finally return the settings.
    939938    return $settings;
    940939}
     
    943942 * Get cover image Width and Height
    944943 *
    945  * @since  2.4.0
    946  *
    947  * @param  string $component the BuddyPress component concerned ("xprofile" for user or "groups")
    948  * @return array             an associative array containing the advised width and height for the cover image
     944 * @since 2.4.0
     945 *
     946 * @param string $component The BuddyPress component concerned ("xprofile" for user or "groups").
     947 * @return array An associative array containing the advised width and height for the cover image.
    949948 */
    950949function bp_attachments_get_cover_image_dimensions( $component = 'xprofile' ) {
    951     // Let's prevent notices when setting the warning strings
     950    // Let's prevent notices when setting the warning strings.
    952951    $default = array( 'width' => 0, 'height' => 0 );
    953952
     
    958957    }
    959958
    960     // Get width and height
     959    // Get width and height.
    961960    $wh = array_intersect_key( $settings, $default );
    962961
     
    964963     * Filter here to edit the cover image dimensions if needed.
    965964     *
    966      * @since  2.4.0
    967      *
    968      * @param  array  $wh        an associative array containing the width and height values
    969      * @param  array  $settings  an associative array containing all the feature settings
    970      * @param  string $compnent  the requested component
     965     * @since 2.4.0
     966     *
     967     * @param array  $wh       An associative array containing the width and height values.
     968     * @param array  $settings An associative array containing all the feature settings.
     969     * @param string $compnent The requested component.
    971970     */
    972971    return apply_filters( 'bp_attachments_get_cover_image_dimensions', $wh, $settings, $component );
     
    974973
    975974/**
    976  * Are we on a page to edit a cover image ?
    977  *
    978  * @since  2.4.0
    979  *
    980  * @return bool True if on a page to edit a cover image, false otherwise
     975 * Are we on a page to edit a cover image?
     976 *
     977 * @since 2.4.0
     978 *
     979 * @return bool True if on a page to edit a cover image, false otherwise.
    981980 */
    982981function bp_attachments_cover_image_is_edit() {
     
    10051004
    10061005/**
    1007  * Does the user has a cover image ?
    1008  *
    1009  * @since  2.4.0
    1010  *
    1011  * @param  int $user_id
    1012  * @return bool True if the user has a cover image, false otherwise
     1006 * Does the user has a cover image?
     1007 *
     1008 * @since 2.4.0
     1009 *
     1010 * @param int $user_id User ID to retrieve cover image for.
     1011 * @return bool True if the user has a cover image, false otherwise.
    10131012 */
    10141013function bp_attachments_get_user_has_cover_image( $user_id = 0 ) {
     
    10251024
    10261025/**
    1027  * Does the group has a cover image ?
    1028  *
    1029  * @since  2.4.0
    1030  *
    1031  * @param  int $group_id
    1032  * @return bool True if the group has a cover image, false otherwise
     1026 * Does the group has a cover image?
     1027 *
     1028 * @since 2.4.0
     1029 *
     1030 * @param int $group_id Group ID to check cover image existence for.
     1031 * @return bool True if the group has a cover image, false otherwise.
    10331032 */
    10341033function bp_attachments_get_group_has_cover_image( $group_id = 0 ) {
     
    10501049 * @since 2.4.0
    10511050 *
    1052  * @param  array  $args {
     1051 * @param array                     $args {
    10531052 *     @type string $file            The absolute path to the image. Required.
    10541053 *     @type string $component       The component for the object (eg: groups, xprofile). Required.
    10551054 *     @type string $cover_image_dir The Cover image dir to write the image into. Required.
    10561055 * }
    1057  * @param  BP_Attachment_Cover_Image $cover_image_class The class to use to fit the cover image.
    1058  * @return bool|array          An array containing cover image data on success, false otherwise.
     1056 * @param BP_Attachment_Cover_Image $cover_image_class The class to use to fit the cover image.
     1057 * @return bool|array An array containing cover image data on success, false otherwise.
    10591058 */
    10601059function bp_attachments_cover_image_generate_file( $args = array(), $cover_image_class = null ) {
    1061     // Bail if an argument is missing
     1060    // Bail if an argument is missing.
    10621061    if ( empty( $args['file'] ) || empty( $args['component'] ) || empty( $args['cover_image_dir'] ) ) {
    10631062        return false;
    10641063    }
    10651064
    1066     // Get advised dimensions for the cover image
     1065    // Get advised dimensions for the cover image.
    10671066    $dimensions = bp_attachments_get_cover_image_dimensions( $args['component'] );
    10681067
     
    10811080    }
    10821081
    1083     // Resize the image so that it fit with the cover image dimensions
     1082    // Resize the image so that it fit with the cover image dimensions.
    10841083    $cover_image  = $cover_image_class->fit( $args['file'], $dimensions );
    10851084    $is_too_small = false;
    10861085
    1087     // Image is too small in width and height
     1086    // Image is too small in width and height.
    10881087    if ( empty( $cover_image ) ) {
    10891088        $cover_file = $cover_image_class->generate_filename( $args['file'] );
     
    10951094        $cover_file = $cover_image['path'];
    10961095
    1097         // Image is too small in width or height
     1096        // Image is too small in width or height.
    10981097        if ( $cover_image['width'] < $dimensions['width'] || $cover_image['height'] < $dimensions['height'] ) {
    10991098            $is_too_small = true;
     
    11111110    if ( $att_dir = opendir( $args['cover_image_dir'] ) ) {
    11121111        while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) {
    1113             // skip directories and the new cover image
     1112            // Skip directories and the new cover image.
    11141113            if ( 2 < strlen( $attachment_file ) && 0 !== strpos( $attachment_file, '.' ) && $cover_basename !== $attachment_file ) {
    11151114                @unlink( $args['cover_image_dir'] . '/' . $attachment_file );
     
    11291128 * Ajax Upload and set a cover image
    11301129 *
    1131  * @since  2.4.0
    1132  *
    1133  * @return  string|null A json object containing success data if the upload succeeded
    1134  *                      error message otherwise.
     1130 * @since 2.4.0
     1131 *
     1132 * @return string|null A json object containing success data if the upload succeeded
     1133 *                     error message otherwise.
    11351134 */
    11361135function bp_attachments_cover_image_ajax_upload() {
    1137     // Bail if not a POST action
     1136    // Bail if not a POST action.
    11381137    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
    11391138        wp_die();
     
    11491148    }
    11501149
    1151     // Check the nonce
     1150    // Check the nonce.
    11521151    check_admin_referer( 'bp-uploader' );
    11531152
    1154     // Init the BuddyPress parameters
     1153    // Init the BuddyPress parameters.
    11551154    $bp_params = array();
    11561155
    1157     // We need it to carry on
     1156    // We need it to carry on.
    11581157    if ( ! empty( $_POST['bp_params'] ) ) {
    11591158        $bp_params = bp_parse_args( $_POST['bp_params'], array(
     
    11651164    }
    11661165
    1167     // We need the object to set the uploads dir filter
     1166    // We need the object to set the uploads dir filter.
    11681167    if ( empty( $bp_params['object'] ) ) {
    11691168        bp_attachments_json_response( false, $is_html4 );
    11701169    }
    11711170
    1172     // Capability check
     1171    // Capability check.
    11731172    if ( ! bp_attachments_current_user_can( 'edit_cover_image', $bp_params ) ) {
    11741173        bp_attachments_json_response( false, $is_html4 );
     
    11781177    $needs_reset = array();
    11791178
    1180     // Member's cover image
     1179    // Member's cover image.
    11811180    if ( 'user' === $bp_params['object'] ) {
    11821181        $object_data = array( 'dir' => 'members', 'component' => 'xprofile' );
     
    11871186        }
    11881187
    1189     // Group's cover image
     1188    // Group's cover image.
    11901189    } elseif ( 'group' === $bp_params['object'] ) {
    11911190        $object_data = array( 'dir' => 'groups', 'component' => 'groups' );
     
    11991198        }
    12001199
    1201     // Other object's cover image
     1200    // Other object's cover image.
    12021201    } else {
    12031202        $object_data = apply_filters( 'bp_attachments_cover_image_object_dir', array(), $bp_params['object'] );
    12041203    }
    12051204
    1206     // Stop here in case of a missing parameter for the object
     1205    // Stop here in case of a missing parameter for the object.
    12071206    if ( empty( $object_data['dir'] ) || empty( $object_data['component'] ) ) {
    12081207        bp_attachments_json_response( false, $is_html4 );
     
    12121211    $uploaded = $cover_image_attachment->upload( $_FILES );
    12131212
    1214     // Reset objects
     1213    // Reset objects.
    12151214    if ( ! empty( $needs_reset ) ) {
    12161215        if ( ! empty( $needs_reset['component'] ) ) {
     
    12221221
    12231222    if ( ! empty( $uploaded['error'] ) ) {
    1224         // Upload error response
     1223        // Upload error response.
    12251224        bp_attachments_json_response( false, $is_html4, array(
    12261225            'type'    => 'upload_error',
     
    12291228    }
    12301229
    1231     // Default error message
     1230    // Default error message.
    12321231    $error_message = __( 'There was a problem uploading the cover image.', 'buddypress' );
    12331232
    1234     // Get BuddyPress Attachments Uploads Dir datas
     1233    // Get BuddyPress Attachments Uploads Dir datas.
    12351234    $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
    12361235
     
    12391238
    12401239    if ( ! is_dir( $cover_dir ) ) {
    1241         // Upload error response
     1240        // Upload error response.
    12421241        bp_attachments_json_response( false, $is_html4, array(
    12431242            'type'    => 'upload_error',
     
    12601259
    12611260    if ( ! $cover ) {
    1262         // Upload error response
     1261        // Upload error response.
    12631262        bp_attachments_json_response( false, $is_html4, array(
    12641263            'type'    => 'upload_error',
     
    12671266    }
    12681267
    1269     // Build the url to the file
     1268    // Build the url to the file.
    12701269    $cover_url = trailingslashit( $bp_attachments_uploads_dir['baseurl'] ) . $cover_subdir . '/' . $cover['cover_basename'];
    12711270
    1272     // Init Feedback code, 1 is success
     1271    // Init Feedback code, 1 is success.
    12731272    $feedback_code = 1;
    12741273
    1275     // 0 is the size warning
     1274    // 0 is the size warning.
    12761275    if ( $cover['is_too_small'] ) {
    12771276        $feedback_code = 0;
    12781277    }
    12791278
    1280     // Set the name of the file
     1279    // Set the name of the file.
    12811280    $name = $_FILES['file']['name'];
    12821281    $name_parts = pathinfo( $name );
     
    12971296    do_action( $object_data['component'] . '_cover_image_uploaded', (int) $bp_params['item_id'] );
    12981297
    1299     // Finally return the cover image url to the UI
     1298    // Finally return the cover image url to the UI.
    13001299    bp_attachments_json_response( true, $is_html4, array(
    13011300        'name'          => $name,
     
    13261325    }
    13271326
    1328     // Check the nonce
     1327    // Check the nonce.
    13291328    check_admin_referer( 'bp_delete_cover_image', 'nonce' );
    13301329
    1331     // Capability check
     1330    // Capability check.
    13321331    if ( ! bp_attachments_current_user_can( 'edit_cover_image', $cover_image_data ) ) {
    13331332        wp_send_json_error();
    13341333    }
    13351334
    1336     // Set object for the user's case
     1335    // Set object for the user's case.
    13371336    if ( 'user' === $cover_image_data['object'] ) {
    13381337        $component = 'xprofile';
    13391338        $dir       = 'members';
    13401339
    1341     // Set it for any other cases
     1340    // Set it for any other cases.
    13421341    } else {
    13431342        $component = $cover_image_data['object'] . 's';
     
    13451344    }
    13461345
    1347     // Handle delete
     1346    // Handle delete.
    13481347    if ( bp_attachments_delete_file( array( 'item_id' => $cover_image_data['item_id'], 'object_dir' => $dir, 'type' => 'cover-image' ) ) ) {
    13491348
    1350         // Defaults no cover image
     1349        // Defaults no cover image.
    13511350        $response = array(
    13521351            'reset_url'     => '',
     
    13541353        );
    13551354
    1356         // Get cover image settings in case there's a default header
     1355        // Get cover image settings in case there's a default header.
    13571356        $cover_params = bp_attachments_get_cover_image_settings( $component );
    13581357
    1359         // Check if there's a default cover
     1358        // Check if there's a default cover.
    13601359        if ( ! empty( $cover_params['default_cover'] ) ) {
    13611360            $response['reset_url'] = $cover_params['default_cover'];
    13621361        }
    13631362
    1364         // Finally send the reset url
     1363        // Finally send the reset url.
    13651364        wp_send_json_success( $response );
    13661365
Note: See TracChangeset for help on using the changeset viewer.