pre_attachment_url_to_postid
Filters the attachment ID to allow short-circuit the function.
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 PHP documentation. Use the === operator for testing the post ID when developing filters using this hook.
Использование
add_filter( 'pre_attachment_url_to_postid', 'wp_kama_pre_attachment_url_to_postid_filter', 10, 2 ); /** * Function for `pre_attachment_url_to_postid` filter-hook. * * @param int|null $post_id The result of the post ID lookup. Null to indicate no lookup has been attempted. * @param string $url The URL being looked up. * * @return int|null */ function wp_kama_pre_attachment_url_to_postid_filter( $post_id, $url ){ // filter... return $post_id; }
- $post_id(int|null)
- The result of the post ID lookup. Null to indicate no lookup has been attempted.
По умолчанию: null - $url(строка)
- The URL being looked up.
Где вызывается хук
pre_attachment_url_to_postid
wp-includes/media.php 5474
$post_id = apply_filters( 'pre_attachment_url_to_postid', null, $url );