Overview

Classes

  • xu
  • Xu\Foundation\Foundation
  • Xu\Foundation\Jsonable
  • Xu\Model\Collection
  • Xu\Model\Model

Functions

  • xu
  • xu_add_option
  • xu_attachment_url_to_postid
  • xu_cache_delete
  • xu_cache_delete_group
  • xu_cache_get
  • xu_cache_key
  • xu_camel_case
  • xu_clean_attachment_cache
  • xu_clean_nav_menu_cache
  • xu_clean_post_cache
  • xu_contains
  • xu_convert_to_string
  • xu_current_attachment_url_to_postid
  • xu_current_url
  • xu_current_url_to_postid
  • xu_dashify
  • xu_delete_option
  • xu_delete_site_transient
  • xu_delete_transient
  • xu_doing_ajax
  • xu_ends_with
  • xu_get_class_name
  • xu_get_model
  • xu_get_option
  • xu_get_option_name
  • xu_get_option_post_id
  • xu_get_posts
  • xu_get_site_transient
  • xu_get_top_parent_post
  • xu_get_top_parent_post_type
  • xu_get_top_parent_post_type_object
  • xu_get_transient
  • xu_is_empty
  • xu_is_http_method
  • xu_is_json
  • xu_is_post_type
  • xu_is_wp
  • xu_is_xml
  • xu_post_exists
  • xu_register_large_option_post_type
  • xu_snake_case
  • xu_starts_with
  • xu_strip_spaces
  • xu_studly_case
  • xu_update_option
  • xu_url_to_postid
  • xu_valid_personnummer
  • xu_wp_get_attachment_image
  • xu_wp_get_attachment_image_sizes
  • xu_wp_get_attachment_image_src
  • xu_wp_get_attachment_image_srcset
  • xu_wp_get_attachment_url
  • xu_wp_nav_menu
  • Overview
  • Class
  1: <?php
  2: 
  3: /**
  4:  * Cached version of `attachment_url_to_postid`.
  5:  *
  6:  * @param  string $url
  7:  *
  8:  * @return int
  9:  */
 10: function xu_attachment_url_to_postid( $url = '' ) {
 11:     // Only valid urls.
 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:  * Get attachment post id from current url.
 21:  *
 22:  * @return string
 23:  */
 24: function xu_current_attachment_url_to_postid() {
 25:     return xu_attachment_url_to_postid( xu_current_url() );
 26: }
 27: 
 28: /**
 29:  * Cached version of `wp_get_attachment_image`.
 30:  *
 31:  * @see https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
 32:  *
 33:  * @param  int          $attachment_id
 34:  * @param  array|string $size
 35:  * @param  bool         $icon
 36:  * @param  string       $attr
 37:  *
 38:  * @return string
 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:  * Cached version of `wp_get_attachment_image_sizes`.
 50:  *
 51:  * @see https://developer.wordpress.org/reference/functions/wp_get_attachment_image_sizes/
 52:  *
 53:  * @param  int          $attachment_id
 54:  * @param  array|string $size
 55:  * @param  array        $image_meta
 56:  *
 57:  * @return string
 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:  * Cached version of `wp_get_attachment_image_src`.
 69:  *
 70:  * @see https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/
 71:  *
 72:  * @param  int          $attachment_id
 73:  * @param  array|string $size
 74:  * @param  bool         $icon
 75:  *
 76:  * @return string
 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:  * Cached version of `wp_get_attachment_image_srcset`.
 88:  *
 89:  * @see https://developer.wordpress.org/reference/functions/wp_get_attachment_image_srcset/
 90:  *
 91:  * @param  int          $attachment_id
 92:  * @param  array|string $size
 93:  * @param  array        $image_meta
 94:  *
 95:  * @return string
 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:  * Cached version of `wp_get_attachment_url`.
107:  *
108:  * @param  int $post_id
109:  *
110:  * @return string
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: 
API documentation generated by ApiGen