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:  * Delete value from cache.
  5:  *
  6:  * @param  mixed  $key   The cache key, can be anything if `$md5` is set to true.
  7:  * @param  string $group The cache group. Optional.
  8:  *
  9:  * @return bool
 10:  */
 11: function xu_cache_delete( $key, $group = '' ) {
 12:     // Check for empty key.
 13:     if ( empty( $key ) ) {
 14:         return false;
 15:     }
 16: 
 17:     if ( is_array( $key ) || is_object( $key ) ) {
 18:         $key = md5( serialize( $key ) );
 19:     }
 20: 
 21:     if ( ! is_string( $key ) ) {
 22:         return false;
 23:     }
 24: 
 25:     return wp_cache_delete( $key, $group );
 26: }
 27: 
 28: /**
 29:  * Removes cache contents for a given group.
 30:  *
 31:  * @codeCoverageIgnore
 32:  *
 33:  * @param  string $group  The cache group.
 34:  * @param  string $suffix The suffix. Optional.
 35:  *
 36:  * @return bool
 37:  */
 38: function xu_cache_delete_group( $group, $suffix = '' ) {
 39:     if ( ! function_exists( 'wp_cache_delete_group' ) ) {
 40:         return false;
 41:     }
 42: 
 43:     return wp_cache_delete_group( xu_cache_key( $group, $suffix ) );
 44: }
 45: 
 46: /**
 47:  * Get value from given functions cache or from function
 48:  * if function cache don't exists.
 49:  *
 50:  * @param  string $key   The cache key, will be serialized if array or object.
 51:  * @param  string $fn    The function.
 52:  * @param  array  $args  The function arguments.
 53:  * @param  string $group The cache group. Optional.
 54:  *
 55:  * @return mixed Cached value, function return value or false.
 56:  */
 57: function xu_cache_get( $key, $fn = '', $args = [], $group = '' ) {
 58:     if ( ! empty( $fn ) && ! empty( $args ) && empty( $group ) ) {
 59:         if ( is_string( $args ) ) {
 60:             $group = $args;
 61:         }
 62: 
 63:         $args = $fn;
 64:         $fn   = $key;
 65:         $key  = $args;
 66:     }
 67: 
 68:     if ( is_array( $key ) && count( $key ) === 1 ) {
 69:         $key = $key[0];
 70:     }
 71: 
 72:     if ( is_array( $key ) || is_object( $key ) ) {
 73:         $key = md5( serialize( $key ) );
 74:     }
 75: 
 76:     if ( $value = wp_cache_get( $key, $group ) ) {
 77:         return $value;
 78:     }
 79: 
 80:     if ( ! is_callable( $fn ) ) {
 81:         return false;
 82:     }
 83: 
 84:     $value = call_user_func_array( $fn, $args );
 85: 
 86:     if ( empty( $value ) ) {
 87:         return $value;
 88:     }
 89: 
 90:     wp_cache_set( $key, $value, $group );
 91: 
 92:     return $value;
 93: }
 94: 
 95: /**
 96:  * Get xu cache key.
 97:  *
 98:  * @param  string $key
 99:  * @param  mixed  $suffix
100:  *
101:  * @return null|string
102:  */
103: function xu_cache_key( $key, $suffix = '' ) {
104:     if ( ! is_string( $key ) ) {
105:         return;
106:     }
107: 
108:     $key = sanitize_title_with_dashes( $key );
109:     $key = str_replace( '-', '_', $key );
110: 
111:     if ( is_array( $suffix )||is_object( $suffix ) ) {
112:         $suffix = md5( serialize( $suffix ) );
113:     }
114: 
115:     if ( $suffix === false ) {
116:         $suffix = '0';
117:     }
118: 
119:     if ( $suffix === '' || $suffix === null ) {
120:         return $key;
121:     }
122: 
123:     return sprintf( '%s:%s', $key, $suffix );
124: }
125: 
API documentation generated by ApiGen