is_local_attachment

Check if the attachment URI is local one and is really an attachment.

Description

is_local_attachment( (string) $url ); 

Parameters (1)

0. $url (string)
URL to check

Usage

  1. if ( !function_exists( 'is_local_attachment' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // URL to check 
  5. $url = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_local_attachment($url); 
  9.  

Defined (1)

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

/wp-includes/post.php  
  1. function is_local_attachment($url) { 
  2. if (strpos($url, home_url()) === false) 
  3. return false; 
  4. if (strpos($url, home_url('/?attachment_id=')) !== false) 
  5. return true; 
  6. if ( $id = url_to_postid($url) ) { 
  7. $post = get_post($id); 
  8. if ( 'attachment' == $post->post_type ) 
  9. return true; 
  10. return false;