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.
5688* @since 6.7.05689*5690* @param int|null$post_id The result of the post ID lookup.Null to indicate5691* no lookup has been attempted.Defaultnull.5692* @param string$url The URL being looked up.5693*/5694$post_id=apply_filters('pre_attachment_url_to_postid',null,$url);5695if(null!==$post_id){5696return(int)$post_id;5697}56985699$dir=wp_get_upload_dir();5700$path=$url;
History
Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.