Advertisement
fauzanjeg

Remove Avatar (Photo Profile) if is not found

Oct 5th, 2021
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. /* Remove Avatar (Photo Profile) if is not found */
  2. function custom_avatar_url( $url, $id_or_email, $args ) {
  3.     $url_args = array(
  4.         's' => $args['size'],
  5.         'd' => '404',
  6.         'f' => $args['force_default'] ? 'y' : false,
  7.         'r' => $args['rating'],
  8.     );
  9.  
  10.     $custom_url = add_query_arg(
  11.         rawurlencode_deep( array_filter( $url_args ) ),
  12.         set_url_scheme( $url, $args['scheme'] )
  13.     );
  14.  
  15.     $response = wp_remote_get( $custom_url );
  16.  
  17.     if ( 404 === wp_remote_retrieve_response_code( $response ) ) {
  18.         return false;
  19.     }
  20.  
  21.     return $custom_url;
  22. }
  23. add_filter( 'get_avatar_url', 'custom_avatar_url', 99, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement