Changeset 1801448
- Timestamp:
- 01/12/2018 01:42:37 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gravity-forms-stripe/trunk/includes/gf-utility-functions.php
r1368395 r1801448 3 3 if ( ! function_exists( 'rgget' ) ) { 4 4 /** 5 * @param $name 6 * @param null $array 5 * Helper function for getting values from query strings or arrays 7 6 * 8 * @return string 7 * @param string $name The key 8 * @param array $array The array to search through. If null, checks query strings. Defaults to null. 9 * 10 * @return string The value. If none found, empty string. 9 11 */ 10 function rgget ( $name, $array = null ) {12 function rgget( $name, $array = null ) { 11 13 if ( ! isset( $array ) ) { 12 14 $array = $_GET; 13 15 } 14 16 15 if ( isset( $array[$name]) ) {16 return $array[$name];17 if ( ! is_array( $array ) ) { 18 return ''; 17 19 } 18 20 19 return ""; 21 if ( isset( $array[ $name ] ) ) { 22 return $array[ $name ]; 23 } 24 25 return ''; 20 26 } 21 27 } 22 28 23 24 29 if ( ! function_exists( 'rgpost' ) ) { 25 30 /** 26 * @param $name 27 * @param bool $do_stripslashes 31 * Helper function to obtain POST values. 28 32 * 29 * @return mixed|string 33 * @param string $name The key 34 * @param bool $do_stripslashes Optional. Performs stripslashes_deep. Defaults to true. 35 * 36 * @return string The value. If none found, empty string. 30 37 */ 31 function rgpost ( $name, $do_stripslashes = true ) {32 if ( isset( $_POST[ $name] ) ) {33 return $do_stripslashes ? stripslashes_deep( $_POST[ $name] ) : $_POST[$name];38 function rgpost( $name, $do_stripslashes = true ) { 39 if ( isset( $_POST[ $name ] ) ) { 40 return $do_stripslashes ? stripslashes_deep( $_POST[ $name ] ) : $_POST[ $name ]; 34 41 } 35 42 … … 40 47 if ( ! function_exists( 'rgar' ) ) { 41 48 /** 42 * @param $array 43 * @param $name 49 * Get a specific property of an array without needing to check if that property exists. 44 50 * 45 * @return string 51 * Provide a default value if you want to return a specific value if the property is not set. 52 * 53 * @since Unknown 54 * @access public 55 * 56 * @param array $array Array from which the property's value should be retrieved. 57 * @param string $prop Name of the property to be retrieved. 58 * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null. 59 * 60 * @return null|string|mixed The value 46 61 */ 47 function rgar ( $array, $name ) { 48 if ( isset( $array[$name] ) ) { 49 return $array[$name]; 62 function rgar( $array, $prop, $default = null ) { 63 64 if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) { 65 return $default; 50 66 } 51 67 52 return ''; 68 if ( isset( $array[ $prop ] ) ) { 69 $value = $array[ $prop ]; 70 } else { 71 $value = ''; 72 } 73 74 return empty( $value ) && $default !== null ? $default : $value; 53 75 } 54 76 } … … 56 78 if ( ! function_exists( 'rgars' ) ) { 57 79 /** 58 * @param $array 59 * @param $name 80 * Gets a specific property within a multidimensional array. 60 81 * 61 * @return string 82 * @since Unknown 83 * @access public 84 * 85 * @param array $array The array to search in. 86 * @param string $name The name of the property to find. 87 * @param string $default Optional. Value that should be returned if the property is not set or empty. Defaults to null. 88 * 89 * @return null|string|mixed The value 62 90 */ 63 function rgars ( $array, $name ) { 91 function rgars( $array, $name, $default = null ) { 92 93 if ( ! is_array( $array ) && ! ( is_object( $array ) && $array instanceof ArrayAccess ) ) { 94 return $default; 95 } 96 64 97 $names = explode( '/', $name ); 65 98 $val = $array; 66 99 foreach ( $names as $current_name ) { 67 $val = rgar( $val, $current_name );100 $val = rgar( $val, $current_name, $default ); 68 101 } 69 102 … … 74 107 if ( ! function_exists( 'rgempty' ) ) { 75 108 /** 76 * @param $name 77 * @param null $array 109 * Determines if a value is empty. 78 110 * 79 * @return bool 111 * @since Unknown 112 * @access public 113 * 114 * @param string $name The property name to check. 115 * @param array $array Optional. An array to check through. Otherwise, checks for POST variables. 116 * 117 * @return bool True if empty. False otherwise. 80 118 */ 81 function rgempty ( $name, $array = null ) { 119 function rgempty( $name, $array = null ) { 120 121 if ( is_array( $name ) ) { 122 return empty( $name ); 123 } 124 82 125 if ( ! $array ) { 83 126 $array = $_POST; 84 127 } 85 128 86 $val = rg get( $name, $array);129 $val = rgar( $array, $name ); 87 130 88 131 return empty( $val ); … … 90 133 } 91 134 92 93 135 if ( ! function_exists( 'rgblank' ) ) { 94 136 /** 95 * @param $text137 * Checks if the string is empty 96 138 * 97 * @return bool 139 * @since Unknown 140 * @access public 141 * 142 * @param string $text The string to check. 143 * 144 * @return bool True if empty. False otherwise. 98 145 */ 99 function rgblank ( $text ) {100 return empty( $text ) && strval( $text ) != '0';146 function rgblank( $text ) { 147 return empty( $text ) && ! is_array( $text ) && strval( $text ) != '0'; 101 148 } 102 149 } 150 151 if ( ! function_exists( 'rgobj' ) ) { 152 /** 153 * Gets a property value from an object 154 * 155 * @since Unknown 156 * @access public 157 * 158 * @param object $obj The object to check 159 * @param string $name The property name to check for 160 * 161 * @return string The property value 162 */ 163 function rgobj( $obj, $name ) { 164 if ( isset( $obj->$name ) ) { 165 return $obj->$name; 166 } 167 168 return ''; 169 } 170 } 171 if ( ! function_exists( 'rgexplode' ) ) { 172 /** 173 * Converts a delimiter separated string to an array. 174 * 175 * @since Unknown 176 * @access public 177 * 178 * @param string $sep The delimiter between values 179 * @param string $string The string to convert 180 * @param int $count The expected number of items in the resulting array 181 * 182 * @return array $ary The exploded array 183 */ 184 function rgexplode( $sep, $string, $count ) { 185 $ary = explode( $sep, $string ); 186 while ( count( $ary ) < $count ) { 187 $ary[] = ''; 188 } 189 190 return $ary; 191 } 192 }
Note: See TracChangeset
for help on using the changeset viewer.