bp_core_delete_existing_avatar

Delete an existing avatar.

Description

bp_core_delete_existing_avatar( (string) $args = '' ); 

Parameters (1)

0. $args — Optional. (string) => ''
Array of function parameters.

Options

  • item_id (bool|int) => to the current item of type $object

    ID of the item whose avatar you're deleting.

  • object (string) => ''

    Object type of the item whose avatar you're deleting. user,, group., blog, or custom. Default: user,.

array(

    /**
     * ID of the item whose avatar you're deleting.
     *
     * @type bool|int
     * @default to the current item of type $object
     */
    'item_id' => to the current item of type $object,

    /**
     * Object type of the item whose avatar you're deleting. 'user', 'group', 'blog', or custom.
     * Default: 'user'.
     *
     * @type string
     * @default ''
     */
    'object' => ''
);        


Usage

  1. if ( !function_exists( 'bp_core_delete_existing_avatar' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-avatars.php'; 
  3.  
  4. // Array of function parameters. 
  5. $args = array( 
  6. 'item_id' => to the current item of type $object, 
  7. 'object' => '' 
  8. ); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_core_delete_existing_avatar($args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-avatars.php  
  1. function bp_core_delete_existing_avatar( $args = '' ) { 
  2.  
  3. $defaults = array( 
  4. 'item_id' => false,  
  5. 'object' => 'user', // User OR group OR blog OR custom type (if you use filters). 
  6. 'avatar_dir' => false 
  7. ); 
  8.  
  9. $args = wp_parse_args( $args, $defaults ); 
  10. extract( $args, EXTR_SKIP ); 
  11.  
  12. /** 
  13. * Filters whether or not to handle deleting an existing avatar. 
  14. * If you want to override this function, make sure you return false. 
  15. * @since 2.5.1 
  16. * @param bool $value Whether or not to delete the avatar. 
  17. * @param array $args { 
  18. * Array of function parameters. 
  19. * @type bool|int $item_id ID of the item whose avatar you're deleting. 
  20. * Defaults to the current item of type $object. 
  21. * @type string $object Object type of the item whose avatar you're 
  22. * deleting. 'user', 'group', 'blog', or custom. 
  23. * Default: 'user'. 
  24. * @type bool|string $avatar_dir Subdirectory where avatar is located. 
  25. * Default: false, which falls back on the default location 
  26. * corresponding to the $object. 
  27. * } 
  28. */ 
  29. return true; 
  30.  
  31. if ( empty( $item_id ) ) { 
  32. if ( 'user' == $object ) 
  33. $item_id = bp_displayed_user_id(); 
  34. elseif ( 'group' == $object ) 
  35. $item_id =buddypress)->groups->current_group->id; 
  36. elseif ( 'blog' == $object ) 
  37. $item_id = $current_blog->id; 
  38.  
  39. /** This filter is documented in bp-core/bp-core-avatars.php */ 
  40. $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object ); 
  41.  
  42. if ( !$item_id ) return false; 
  43.  
  44. if ( empty( $avatar_dir ) ) { 
  45. if ( 'user' == $object ) 
  46. $avatar_dir = 'avatars'; 
  47. elseif ( 'group' == $object ) 
  48. $avatar_dir = 'group-avatars'; 
  49. elseif ( 'blog' == $object ) 
  50. $avatar_dir = 'blog-avatars'; 
  51.  
  52. /** This filter is documented in bp-core/bp-core-avatars.php */ 
  53. $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object ); 
  54.  
  55. if ( !$avatar_dir ) return false; 
  56.  
  57. /** This filter is documented in bp-core/bp-core-avatars.php */ 
  58. $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir ); 
  59.  
  60. if ( !file_exists( $avatar_folder_dir ) ) 
  61. return false; 
  62.  
  63. if ( $av_dir = opendir( $avatar_folder_dir ) ) { 
  64. while ( false !== ( $avatar_file = readdir($av_dir) ) ) { 
  65. if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file ) 
  66. @unlink( $avatar_folder_dir . '/' . $avatar_file ); 
  67. closedir($av_dir); 
  68.  
  69. @rmdir( $avatar_folder_dir ); 
  70.  
  71. /** 
  72. * Fires after deleting an existing avatar. 
  73. * @since 1.1.0 
  74. * @param array $args Array of arguments used for avatar deletion. 
  75. */ 
  76.  
  77. return true;