1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10: function xu_attachment_url_to_postid( $url = '' ) {
11:
12: if ( parse_url( $url, PHP_URL_HOST ) !== parse_url( home_url(), PHP_URL_HOST ) ) {
13: return 0;
14: }
15:
16: return xu_cache_get( 'attachment_url_to_postid', [$url], __FUNCTION__ );
17: }
18:
19: 20: 21: 22: 23:
24: function xu_current_attachment_url_to_postid() {
25: return xu_attachment_url_to_postid( xu_current_url() );
26: }
27:
28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39:
40: function xu_wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
41: return xu_cache_get(
42: 'wp_get_attachment_image',
43: [$attachment_id, $size, $icon, $attr],
44: xu_cache_key( __FUNCTION__, $attachment_id )
45: );
46: }
47:
48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58:
59: function xu_wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
60: return xu_cache_get(
61: 'wp_get_attachment_image_sizes',
62: [$attachment_id, $size, $image_meta],
63: xu_cache_key( __FUNCTION__, $attachment_id )
64: );
65: }
66:
67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77:
78: function xu_wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
79: return xu_cache_get(
80: 'wp_get_attachment_image_src',
81: [$attachment_id, $size, $icon],
82: xu_cache_key( __FUNCTION__, $attachment_id )
83: );
84: }
85:
86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96:
97: function xu_wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
98: return xu_cache_get(
99: 'wp_get_attachment_image_srcset',
100: [$attachment_id, $size, $image_meta],
101: xu_cache_key( __FUNCTION__, $attachment_id )
102: );
103: }
104:
105: 106: 107: 108: 109: 110: 111:
112: function xu_wp_get_attachment_url( $post_id = 0 ) {
113: return xu_cache_get( 'wp_get_attachment_url', [$post_id], __FUNCTION__ );
114: }
115: