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:  * Convert a value to camel case.
  5:  *
  6:  * @param string $str
  7:  *
  8:  * @throws InvalidArgumentException if an argument is not of the expected type.
  9:  *
 10:  * @return string
 11:  */
 12: function xu_camel_case( $str ) {
 13:     if ( ! is_string( $str ) ) {
 14:         throw new InvalidArgumentException( 'Invalid argument. Must be string.' );
 15:     }
 16: 
 17:     return lcfirst( xu_studly_case( $str ) );
 18: }
 19: 
 20: /**
 21:  * Determine if a given string contains a given substring.
 22:  *
 23:  * @param string $haystack
 24:  * @param string|array $needles
 25:  *
 26:  * @throws InvalidArgumentException if an arguments is not of the expected types.
 27:  *
 28:  * @return bool
 29:  */
 30: function xu_contains( $haystack, $needles ) {
 31:     if ( ! is_string( $haystack ) ) {
 32:         throw new InvalidArgumentException( 'Invalid argument. `$haystack` must be string.' );
 33:     }
 34: 
 35:     if ( ! is_array( $needles ) && ! is_string( $needles ) ) {
 36:         throw new InvalidArgumentException( 'Invalid argument. `$needles` must be array or string.' );
 37:     }
 38: 
 39:     foreach ( (array) $needles as $needle ) {
 40:         if ( (string) $needle !== '' && strpos( $haystack, $needle ) !== false ) {
 41:             return true;
 42:         }
 43:     }
 44: 
 45:     return false;
 46: }
 47: 
 48: /**
 49:  * Try convert to string if is possible else return empty string.
 50:  *
 51:  * @param  mixed $obj
 52:  *
 53:  * @return string
 54:  */
 55: function xu_convert_to_string( $obj ) {
 56:     if ( $obj === true ) {
 57:         return 'true';
 58:     }
 59: 
 60:     if ( $obj === false ) {
 61:         return 'false';
 62:     }
 63: 
 64:     if ( ! is_array( $obj ) && ( ( ! is_object( $obj ) && settype( $obj, 'string' ) !== false ) || ( is_object( $obj ) && method_exists( $obj, '__toString' ) ) ) ) {
 65:         return (string) $obj;
 66:     }
 67: 
 68:     return '';
 69: }
 70: 
 71: /**
 72:  * Replacing whitespace and underscore with a dash.
 73:  *
 74:  * @param string $str
 75:  *
 76:  * @throws InvalidArgumentException if an argument is not of the expected type.
 77:  *
 78:  * @return string
 79:  */
 80: function xu_dashify( $str ) {
 81:     if ( ! is_string( $str ) ) {
 82:         throw new InvalidArgumentException( 'Invalid argument. Must be string.' );
 83:     }
 84: 
 85:     return xu_strip_spaces( strtolower( preg_replace( '/(.)(?=[A-Z])|\_|\s/', '$1-', $str ) ) );
 86: }
 87: 
 88: /**
 89:  * Determine if a given string ends with a given substring.
 90:  *
 91:  * @param string $haystack
 92:  * @param string|array $needles
 93:  *
 94:  * @throws InvalidArgumentException if an arguments is not of the expected types.
 95:  *
 96:  * @return bool
 97:  */
 98: function xu_ends_with( $haystack, $needles ) {
 99:     if ( ! is_string( $haystack ) ) {
100:         throw new InvalidArgumentException( 'Invalid argument. `$haystack` must be string.' );
101:     }
102: 
103:     if ( ! is_array( $needles ) && ! is_string( $needles ) ) {
104:         throw new InvalidArgumentException( 'Invalid argument. `$needles` must be array or string.' );
105:     }
106: 
107:     foreach ( (array) $needles as $needle ) {
108:         if ( (string) $needle === substr( $haystack, -strlen( $needle ) ) ) {
109:             return true;
110:         }
111:     }
112: 
113:     return false;
114: }
115: 
116: /**
117:  * Determine if a given string starts with a given substring.
118:  *
119:  * @param string $haystack
120:  * @param string|array $needles
121:  *
122:  * @throws InvalidArgumentException if an arguments is not of the expected types.
123:  *
124:  * @return bool
125:  */
126: function xu_starts_with( $haystack, $needles ) {
127:     if ( ! is_string( $haystack ) ) {
128:         throw new InvalidArgumentException( 'Invalid argument. `$haystack` must be string.' );
129:     }
130: 
131:     if ( ! is_array( $needles ) && ! is_string( $needles ) ) {
132:         throw new InvalidArgumentException( 'Invalid argument. `$needles` must be string.' );
133:     }
134: 
135:     foreach ( (array) $needles as $needle ) {
136:         if ( (string) $needle !== '' && strpos( $haystack, $needle ) === 0 ) {
137:             return true;
138:         }
139:     }
140: 
141:     return false;
142: }
143: 
144: /**
145:  * Convert a string to snake case.
146:  *
147:  * @param string $str
148:  * @param string $delimiter
149:  *
150:  * @throws InvalidArgumentException if an arguments is not of the expected types.
151:  *
152:  * @return string
153:  */
154: function xu_snake_case( $str, $delimiter = '_' ) {
155:     if ( ! is_string( $str ) ) {
156:         throw new InvalidArgumentException( 'Invalid argument. `$str` must be string.' );
157:     }
158: 
159:     if ( ! is_string( $delimiter ) ) {
160:         throw new InvalidArgumentException( 'Invalid argument. `$delimiter` must be string.' );
161:     }
162: 
163:     return xu_strip_spaces( strtolower( preg_replace( '/(.)(?=[A-Z])|\-|\s/', '$1' . $delimiter, $str ) ) );
164: }
165: 
166: 
167: /**
168:  * Convert a value to studly caps case.
169:  *
170:  * @param string $str
171:  *
172:  * @throws InvalidArgumentException if an argument is not of the expected type.
173:  *
174:  * @return string
175:  */
176: function xu_studly_case( $str ) {
177:     if ( ! is_string( $str ) ) {
178:         throw new InvalidArgumentException( 'Invalid argument. Must be string.' );
179:     }
180: 
181:     return str_replace( ' ', '', ucwords( str_replace( ['-', '_'], ' ', $str ) ) );
182: }
183: 
184: /**
185:  * Strip spaces from string.
186:  *
187:  * @param string $str
188:  *
189:  * @throws InvalidArgumentException if an argument is not of the expected type.
190:  *
191:  * @return string
192:  */
193: function xu_strip_spaces( $str ) {
194:     if ( ! is_string( $str ) ) {
195:         throw new InvalidArgumentException( 'Invalid argument. Must be string.' );
196:     }
197: 
198:     return  trim( preg_replace( '/\s+/', ' ', $str ) );
199: }
200: 
API documentation generated by ApiGen