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:  * Check if WordPress is doing ajax or not.
  5:  *
  6:  * @return bool
  7:  */
  8: function xu_doing_ajax() {
  9:     return defined( 'DOING_AJAX' ) && DOING_AJAX;
 10: }
 11: 
 12: /**
 13:  * Check if the given object is empty or not.
 14:  * Values like "0", 0 and false should not return true.
 15:  *
 16:  * @param  mixed $obj
 17:  *
 18:  * @return bool
 19:  */
 20: function xu_is_empty( $obj ) {
 21:     if ( is_string( $obj ) ) {
 22:         return empty( $obj ) && ! is_numeric( $obj );
 23:     }
 24: 
 25:     if ( is_bool( $obj ) || is_numeric( $obj ) ) {
 26:         return false;
 27:     }
 28: 
 29:     return empty( $obj );
 30: }
 31: 
 32: /**
 33:  * Check if the request method is the same as the given method.
 34:  *
 35:  * @param  string $method
 36:  *
 37:  * @return bool
 38:  */
 39: function xu_is_http_method( $method ) {
 40:     if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) {
 41:         return false;
 42:     }
 43: 
 44:     if ( ! is_string( $method ) ) {
 45:         return false;
 46:     }
 47: 
 48:     return strtolower( $_SERVER ['REQUEST_METHOD'] ) === strtolower( $method );
 49: }
 50: 
 51: /**
 52:  * Check if the given string is a JSON string or not.
 53:  *
 54:  * @param  string $obj
 55:  *
 56:  * @return bool
 57:  */
 58: function xu_is_json( $obj ) {
 59:     return is_string( $obj )
 60:         && is_array( json_decode( $obj, true ) )
 61:         && json_last_error() === JSON_ERROR_NONE;
 62: }
 63: 
 64: /**
 65:  * Check if WordPress is the given version.
 66:  *
 67:  * @param  string $version
 68:  * @param  string $operator
 69:  *
 70:  * @return bool
 71:  */
 72: function xu_is_wp( $version, $operator = '==' ) {
 73:     if ( ! is_string( $version ) ) {
 74:         throw new InvalidArgumentException( 'Invalid argument. `$version` must be string.' );
 75:     }
 76: 
 77:     if ( ! is_string( $operator ) ) {
 78:         throw new InvalidArgumentException( 'Invalid argument. `$operator` must be string.' );
 79:     }
 80: 
 81:     return version_compare( get_bloginfo( 'version' ), $version, $operator );
 82: }
 83: 
 84: /**
 85:  * Check if the given string is XML or not.
 86:  *
 87:  * @param  string $str
 88:  *
 89:  * @return bool
 90:  */
 91: function xu_is_xml( $str ) {
 92:     if ( ! is_string( $str ) ) {
 93:         return false;
 94:     }
 95: 
 96:     libxml_use_internal_errors( true );
 97:     $doc = simplexml_load_string( $str );
 98:     $xml = explode( "\n", $str );
 99: 
100:     if ( $doc ) {
101:         $errors = libxml_get_errors();
102:         return empty( $errors );
103:     }
104: 
105:     return false;
106: }
107: 
108: /**
109:  * Validate Swedish personal identify numbers.
110:  *
111:  * @param  int|string $str
112:  *
113:  * @return bool
114:  */
115: function xu_valid_personnummer( $str ) {
116:     return \Frozzare\Personnummer\Personnummer::valid( $str );
117: }
118: 
API documentation generated by ApiGen