[wp-trac] [WordPress Trac] #61383: Add new filter to attachment_url_to_postid() for short circuit

WordPress Trac noreply at wordpress.org
Fri Sep 20 05:12:17 UTC 2024


#61383: Add new filter to attachment_url_to_postid() for short circuit
-------------------------+-----------------------
 Reporter:  apermo       |       Owner:  antpb
     Type:  enhancement  |      Status:  assigned
 Priority:  normal       |   Milestone:  6.7
Component:  Media        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+-----------------------

Comment (by peterwilsoncc):

 I think the filter in the proposed patch is good but the docblock
 improvements:

 > 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 {@link
 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.
 >
 > @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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61383#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list