Index: branches/salvatoreingala/Gadgets/backend/Gadget.php |
— | — | @@ -134,22 +134,6 @@ |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | | - //$default must pass validation, too |
139 | | - $required = isset( $option['required'] ) ? $option['required'] : true; |
140 | | - $default = $option['default']; |
141 | | - |
142 | | - if ( $required === false && $default === '' ) { |
143 | | - return true; //empty string is good, skip other checks |
144 | | - } |
145 | | - |
146 | | - $len = strlen( $default ); |
147 | | - if ( isset( $option['minlength'] ) && $len < $option['minlength'] ) { |
148 | | - return false; |
149 | | - } |
150 | | - if ( isset( $option['maxlength'] ) && $len > $option['maxlength'] ) { |
151 | | - return false; |
152 | | - } |
153 | | - |
154 | 138 | return true; |
155 | 139 | } |
156 | 140 | |
— | — | @@ -163,17 +147,6 @@ |
164 | 148 | |
165 | 149 | //Further checks for 'number' options |
166 | 150 | private static function checkNumberOptionDefinition( $option ) { |
167 | | - |
168 | | - if ( $option['default'] === null ) { |
169 | | - if ( isset( $option['required'] ) && $option['required'] === false ) { |
170 | | - //Accept null default if "required" is false |
171 | | - return true; |
172 | | - } else { |
173 | | - //Reject null default if "required" is true |
174 | | - return false; |
175 | | - } |
176 | | - } |
177 | | - |
178 | 151 | if ( isset( $option['integer'] ) && $option['integer'] === true ) { |
179 | 152 | //Check if 'min', 'max' and 'default' are integers (if given) |
180 | 153 | if ( intval( $option['default'] ) != $option['default'] ) { |
— | — | @@ -186,16 +159,6 @@ |
187 | 160 | return false; |
188 | 161 | } |
189 | 162 | } |
190 | | - |
191 | | - //validate $option['default'] |
192 | | - $default = $option['default']; |
193 | | - |
194 | | - if ( isset( $option['min'] ) && $default < $option['min'] ) { |
195 | | - return false; |
196 | | - } |
197 | | - if ( isset( $option['max'] ) && $default > $option['max'] ) { |
198 | | - return false; |
199 | | - } |
200 | 163 | |
201 | 164 | return true; |
202 | 165 | } |
— | — | @@ -217,13 +180,6 @@ |
218 | 181 | |
219 | 182 | $values = array_values( $options ); |
220 | 183 | |
221 | | - $default = $option['default']; |
222 | | - |
223 | | - //Checks that $default is one of the option values |
224 | | - if ( !in_array( $default, $values, true ) ){ |
225 | | - return false; |
226 | | - } |
227 | | - |
228 | 184 | return true; |
229 | 185 | } |
230 | 186 | |
— | — | @@ -664,6 +620,16 @@ |
665 | 621 | return false; |
666 | 622 | } |
667 | 623 | } |
| 624 | + |
| 625 | + //Finally, check that the 'default' fields exists and is valid |
| 626 | + if ( !array_key_exists( 'default', $optionDefinition ) ) { |
| 627 | + return false; |
| 628 | + } |
| 629 | + |
| 630 | + $prefs = array( 'dummy' => $optionDefinition['default'] ); |
| 631 | + if ( !self::checkSinglePref( $optionDefinition, $prefs, 'dummy' ) ) { |
| 632 | + return false; |
| 633 | + } |
668 | 634 | } |
669 | 635 | |
670 | 636 | return true; |
— | — | @@ -783,7 +749,7 @@ |
784 | 750 | * Checks if $prefs is an array of preferences that passes validation |
785 | 751 | * |
786 | 752 | * @param $prefsDescription Array: the preferences description to use. |
787 | | - * @param &$prefs Array: reference of the array of preferences to check. |
| 753 | + * @param $prefs Array: reference of the array of preferences to check. |
788 | 754 | * |
789 | 755 | * @return boolean true if $prefs passes validation against $prefsDescription, false otherwise. |
790 | 756 | */ |