apply_filters( 'pre_attachment_url_to_postid', int|null $post_id, string $url )
- Since
- 6.7.0
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:
- 0 (integer) to indicate the attachment is not found,
- attachment ID (integer) to indicate the attachment ID found,
- null to indicate WordPress should proceed with the lookup.
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 https://www.php.net/manual/en/language.types.boolean.php PHP documentation.
Use the === operator for testing the post ID when developing filters using this hook.
Compatibility
- WordPress
- since 6.7.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Parameters
$post_idint|null- The result of the post ID lookup. Null to indicate no lookup has been attempted. Default null.
$urlstring- The URL being looked up.
Where this hook fires · 1
wp-includes/media.php:5694attachment_url_to_postid()
Source code
* @since 6.7.0 * * @param int|null $post_id The result of the post ID lookup. Null to indicate * no lookup has been attempted. Default null. * @param string $url The URL being looked up. */ $post_id = apply_filters( 'pre_attachment_url_to_postid', null, $url ); if ( null !== $post_id ) { return (int) $post_id; } $dir = wp_get_upload_dir(); $path = $url;Changelog
Introduced in 6.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.