1: <?php
2:
3: 4: 5: 6: 7:
8: function xu_doing_ajax() {
9: return defined( 'DOING_AJAX' ) && DOING_AJAX;
10: }
11:
12: 13: 14: 15: 16: 17: 18: 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: 34: 35: 36: 37: 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: 53: 54: 55: 56: 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: 66: 67: 68: 69: 70: 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: 86: 87: 88: 89: 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: 110: 111: 112: 113: 114:
115: function xu_valid_personnummer( $str ) {
116: return \Frozzare\Personnummer\Personnummer::valid( $str );
117: }
118: