Filters the attachment ID to allow short-circuit the function.
Description
Allows plugins to short-circuit attachment ID lookups. Plugins making use of this function should return: <ul> <li>0 (integer) to indicate the attachment is not found,</li> <li>attachment ID (integer) to indicate the attachment ID found,</li> <li>null to indicate WordPress should proceed with the lookup.</li> </ul> Warning: The post ID may be null or zero, both of which cast to a boolean false. For information about casting to booleans see the <a href="https://www.php.net/manual/en/language.types.boolean.php">https://www.php.net/manual/en/language.types.boolean.php</a> PHP documentation.Use the === operator for testing the post ID when developing filters using this hook.
Parameters
$post_idint|null
The result of the post ID lookup. Null to indicate no lookup has been attempted. Default null.
5520* @since 6.7.05521*5522* @param int|null$post_id The result of the post ID lookup.Null to indicate5523* no lookup has been attempted.Defaultnull.5524* @param string$url The URL being looked up.5525*/5526$post_id=apply_filters('pre_attachment_url_to_postid',null,$url);5527if(null!==$post_id){5528return(int)$post_id;5529}55305531$dir=wp_get_upload_dir();5532$path=$url;
History
Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.