PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.37
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.37
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Simple_Form / WPDA_Simple_Form_Item.php

WPDA_Simple_Form_Item.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.37, at WPDataAccess/Simple_Form/WPDA_Simple_Form_Item.php

1,021 lines 21.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package WPDataAccess\Simple_Form
7 */
8
9 namespace WPDataAccess\Simple_Form {
10
11 use WPDataAccess\Utilities\WPDA_Message_Box;
12 use WPDataAccess\WPDA;
13
14 /**
15 * Class WPDA_Simple_Form_Item
16 *
17 * Simple forms consist of items. Items correspond with table columns. Basically an item is generated for every
18 * table column in the base table. Class WPDA_Simple_Form_Item handles a database column as a standard text item.
19 *
20 * It's possible to add dummy columns. Values for dummy columns however are lost when data is saved.
21 *
22 * Check out {@see WPDA_Simple_Form} to see how to use simple form items.
23 *
24 * @author Peter Schulz
25 * @since 1.0.0
26 */
27 class WPDA_Simple_Form_Item {
28
29 /**
30 * Database column name
31 *
32 * @var string
33 */
34 protected $item_name;
35
36 /**
37 * MySQL data type
38 *
39 * @var string
40 */
41 protected $data_type;
42
43 /**
44 * Item label
45 *
46 * @var string
47 */
48 protected $item_label;
49
50 /**
51 * Current column value in the database
52 *
53 * @var mixed
54 */
55 protected $item_value;
56
57 /**
58 * Default value
59 *
60 * @var mixed
61 */
62 protected $item_default_value;
63
64 /**
65 * Database column specific info
66 *
67 * Like auto_increment, on update, etc
68 *
69 * @var string
70 */
71 protected $item_extra;
72
73 /**
74 * Enum values for column or empty
75 *
76 * @var array
77 */
78 protected $item_enum;
79
80 /**
81 * Enum options for column or empty
82 *
83 * @var array
84 */
85 protected $item_enum_options;
86
87 /**
88 * Enum text for column or empty
89 *
90 * @var array
91 */
92 protected $item_enum_text;
93
94 /**
95 * Database column type
96 *
97 * Column type offers more info than data type, like column length or values for enum types.
98 *
99 * @var string
100 */
101 protected $column_type;
102
103 /**
104 * Icon type
105 *
106 * @var string
107 */
108 protected $item_icon_type;
109
110 /**
111 * Array of events
112 *
113 * Add event to item for example: ["onclick" => "check_item_value()"]
114 *
115 * @var array
116 */
117 protected $item_event;
118
119 /**
120 * Item specific Javascript code
121 *
122 * Code is added to the end of the form.
123 *
124 * @var string
125 */
126 protected $item_js;
127
128 /**
129 * Show item icon (data type)
130 *
131 * TRUE = icon is shown after item, FALSE = hide icon (default FALSE)
132 *
133 * @var boolean
134 */
135 protected $item_hide_icon;
136
137 /**
138 * Item CSS class
139 *
140 * @var string
141 */
142 protected $item_class;
143
144 /**
145 * TRUE = item not shown, FALSE = item shown
146 *
147 * @var boolean
148 */
149 protected $hide_item;
150
151 /**
152 * TRUE = item not shown on init, FALSE = item shown on init
153 *
154 * @var boolean
155 */
156 protected $hide_item_init = false;
157
158 /**
159 * TRUE = null values are allowed, FALSE = no null values allowed
160 *
161 * @var boolean
162 */
163 protected $is_nullable;
164
165 /**
166 * TRUE = is auto_increment column
167 *
168 * @var boolean
169 */
170 protected $is_auto_increment = false;
171
172 /**
173 * TRUE = column is part of primary key, FALSE = column is not part of primary key
174 *
175 * @var boolean
176 */
177 protected $is_key_column;
178
179 /**
180 * TRUE = column is part of foreign key, FALSE = column is not part of foreign key
181 *
182 * @var boolean
183 */
184 protected $is_foreign_key_column = false;
185
186 /**
187 * Set to true to make item readonly
188 *
189 * @var boolean
190 */
191 protected $is_readonly = false;
192
193 /**
194 * Context variable to keep logic for showing items maintainable
195 *
196 * @var string
197 */
198 protected $show_context_action;
199
200 /**
201 * Context variable to keep logic for showing items maintainable
202 *
203 * @var string
204 */
205 protected $show_context_update_keys_allowed;
206
207 /**
208 * Context variable to keep logic for showing items maintainable
209 *
210 * @var string
211 */
212 protected $show_context_column_value;
213
214 /**
215 * Context variable to keep logic for showing items maintainable
216 *
217 * @var string
218 */
219 protected $show_context_class_primary_key;
220
221 /**
222 * Context variable to keep logic for showing items maintainable
223 *
224 * @var string
225 */
226 protected $show_context_item_events;
227
228 /**
229 * Item placeholder
230 *
231 * @var string
232 */
233 protected $item_placeholder = '';
234
235 /**
236 * Max length text column
237 *
238 * @var int
239 */
240 protected $character_maximum_length;
241
242 /**
243 * NUmeric precision
244 *
245 * @var int
246 */
247 protected $numeric_precision;
248
249 /**
250 * Numeric scale
251 *
252 * @var int
253 */
254 protected $numeric_scale;
255
256 public $checkbox_value_on; // Needed for Data Publisher
257
258 /**
259 * WPDA_Simple_Form_Item constructor
260 *
261 * Declare item with all its properties.
262 *
263 * @param array $args [
264 *
265 * 'item_name' => item name
266 *
267 * 'data_type' => data type
268 *
269 * 'item_label' => label
270 *
271 * 'item_value' => value (in database)
272 *
273 * 'item_default_value' => default value
274 *
275 * 'item_extra' => check column extra in information_schema.columns
276 *
277 * 'item_enum' => enum (if applicable)
278 *
279 * 'item_enum_options' => enum options (if applicable)
280 *
281 * 'column_type' => type
282 *
283 * 'item_event' => JS event(s)
284 *
285 * 'item_js' => JS code (global)
286 *
287 * 'item_hide_icon' => icon (showing data type)
288 *
289 * 'item_class' => css class
290 *
291 * 'hide_item' => item visibility
292 *
293 * 'is_nullable' => allow null values?
294 *
295 * 'is_key_column' => is key column?
296 *
297 * 'character_maximum_length' => max width text column
298 *
299 * 'numeric_precision' => numeric precision numeric column
300 *
301 * 'numeric_scale' => numeric scale numeric column
302 *
303 * ].
304 *
305 * @since 1.0.0
306 */
307 public function __construct( $args = array() ) {
308 if ( is_array( $args ) ) {
309 $args = wp_parse_args(
310 $args,
311 array(
312 'item_name' => '',
313 'data_type' => '',
314 'item_label' => '',
315 'item_value' => null,
316 'item_default_value' => null,
317 'item_extra' => '',
318 'item_enum' => '',
319 'item_enum_options' => '',
320 'item_enum_text' => '',
321 'column_type' => '',
322 'item_event' => '',
323 'item_js' => '',
324 'item_hide_icon' => false,
325 'item_class' => '',
326 'hide_item' => false,
327 'is_nullable' => null,
328 'is_key_column' => null,
329 'character_maximum_length' => 0,
330 'numeric_precision' => 0,
331 'numeric_scale' => 0,
332 )
333 );
334
335 if ( '' === $args['item_name'] ) {
336 // Without an item name it makes no sense to continue
337 wp_die( __( 'ERROR: Wrong arguments [missing item name]', 'wp-data-access' ) );
338 }
339
340 if ( '' === $args['data_type'] ) {
341 // Without a data type it makes no sense to continue
342 wp_die( __( 'ERROR: Wrong arguments [missing data type]', 'wp-data-access' ) );
343 }
344
345 $this->item_name = $args['item_name'];
346 $this->data_type = WPDA::get_type( $args['data_type'] );
347 $this->item_icon_type = $this->data_type;
348 $this->item_label = (string) $args['item_label']; //phpcs:ignore - 8.1 proof
349 if ( null === $args['item_value'] ) {
350 $this->item_value = null;
351 } else {
352 $this->item_value = (string) $args['item_value']; //phpcs:ignore - 8.1 proof
353 }
354 if ( 'CURRENT_TIMESTAMP' !== $args['item_default_value'] ) {
355 $this->item_default_value = $args['item_default_value'];
356 }
357 $this->item_extra = $args['item_extra'];
358 if ( 'auto_increment' === $this->item_extra ) {
359 $this->is_auto_increment = true;
360 }
361 $this->item_enum = '';
362 $this->item_enum_options = '';
363 $this->item_enum_text = '';
364 if ( 'enum' === $this->data_type ) {
365 $this->item_enum = explode(
366 ',',
367 str_replace(
368 '\'',
369 '',
370 substr( substr( ( string ) $args['item_enum'], 5 ), 0, - 1 )
371 )
372 );//phpcs:ignore - 8.1 proof
373 }
374 if ( 'set' === $this->data_type ) {
375 $this->item_enum = explode(
376 ',',
377 str_replace(
378 '\'',
379 '',
380 substr( substr( ( string ) $args['item_enum'], 4 ), 0, - 1 )
381 )
382 );//phpcs:ignore - 8.1 proof
383 }
384 $this->column_type = $args['column_type'];
385 $this->item_event = $args['item_event'];
386 $this->item_js = $args['item_js'];
387 $this->item_hide_icon = $args['item_hide_icon'];
388 $this->item_class = $args['item_class'];
389 $this->hide_item = $args['hide_item'];
390 $this->is_nullable = $args['is_nullable'];
391 $this->is_key_column = $args['is_key_column'];
392
393 // Column length and numeric scale and precision
394 $this->character_maximum_length = $args['character_maximum_length'];
395 $this->numeric_precision = $args['numeric_precision'];
396 $this->numeric_scale = $args['numeric_scale'];
397
398 } elseif ( is_object( $args ) ) {
399 if ( 0 <= strpos( self::class, 'WPDA_Simple_Form_Item' ) ) {
400 foreach ( $args as $property => $value ) {
401 $this->$property = $value;
402 }
403 } else {
404 wp_die( __( 'Class must be of (sub)type WPDA_Simple_Form_Item', 'wp-data-access' ) );
405 }
406 } else {
407 wp_die( __( 'Could not create form item instance [argument must be array or object]', 'wp-data-access' ) );
408 }
409 }
410
411 /**
412 * Show item row
413 *
414 * @param string $action Requested action
415 * @param string $update_keys_allowed TRUE = allow key updates
416 */
417 public function show( $action, $update_keys_allowed ) {
418 if ( $this->hide_item && ! $this->is_auto_increment && ! $this->is_foreign_key_column ) {
419 if ( 'new' === $action && '' !== $this->get_item_default_value() && null !== $this->get_item_default_value() ) {
420 // Add hidden item to apply default value
421 } else {
422 // Do not show item, do not add hidden item to form, user is not allowed to view this item
423 return;
424 }
425 }
426
427 // Set context variables
428 $this->show_context_action = $action;
429 $this->show_context_update_keys_allowed = $update_keys_allowed;
430
431 if ( 'row' === substr( $this->item_class, 0, 3 ) ) {
432 // Process row level class
433 $row_class = $this->item_class;
434 $this->item_class = '';
435 } else {
436 $row_class = '';
437 }
438
439 if ( true === $this->hide_item_init || true === $this->hide_item ) {
440 ?>
441 <tr style='display:none'<?php echo '' === $row_class ? '' : ' class="' . esc_attr( $row_class ) . '"'; ?>>
442 <?php
443 } else {
444 ?>
445 <tr <?php echo '' === $row_class ? '' : ' class="' . esc_attr( $row_class ) . '"'; ?>>
446 <?php
447 }
448
449 $label = explode( '|', esc_attr( $this->item_label ) );//phpcs:ignore - 8.1 proof
450 $label_before = $label[0];
451 $label_after = '';
452 if ( isset( $label[1] ) ) {
453 $label_after = $label[1];
454 }
455
456 if ( 'view' === $action ) {
457 $label_title = ' ';
458 } else {
459 $label_title = $label_before . ' ';
460 $label_title .= 'NO' === $this->is_nullable ? __( 'must be entered', 'wp-data-access' ) : __( 'is optional', 'wp-data-access' );
461 }
462 ?>
463 <td class="label">
464 <label for="<?php echo esc_attr( $this->item_name ); ?>"
465 title="<?php echo esc_attr( $label_title ); ?>"
466 class="wpda_tooltip"
467 >
468 <?php echo 'NO' === $this->is_nullable ? '*' : ''; ?>
469 <?php echo esc_attr( $label_before ); ?>
470 </label>
471 </td>
472 <td class="data">
473 <?php
474 // Get column value
475 $this->show_context_column_value = esc_html( str_replace( '&', '&amp;', (string) $this->item_value ) );
476
477 // Set primary key class(es)
478 $this->show_context_class_primary_key = $this->is_key_column ? 'wpda_primary_key' : '';
479 if ( $this->is_auto_increment ) {
480 $this->show_context_class_primary_key .= ' auto_increment';
481 }
482
483 // Prepare events
484 $this->show_context_item_events = '';
485 if ( is_array( $this->item_event ) ) {
486 foreach ( $this->item_event as $event_name => $event_code ) {
487 $this->show_context_item_events .= "$event_name=$event_code ";
488 }
489 }
490
491 // Show item
492 $this->show_item();
493 ?>
494 <input type="hidden"
495 name="<?php echo esc_attr( $this->item_name ); ?>_old"
496 value="<?php echo $this->show_context_column_value; // phpcs:ignore WordPress.Security.EscapeOutput ?>"
497 />
498 <?php echo '' === $label_after ? '' : '<label>' . esc_attr( $label_after ) . '</label>'; ?>
499 </td>
500 <td class="icon">
501 <?php
502 // Add data type icon.
503 if ( ! $this->item_hide_icon ) {
504 $type_button = new WPDA_Simple_Form_Type_Icon( $this->item_name, $this->item_icon_type );
505 $type_button->show();
506 }
507 ?>
508 </td>
509 </tr>
510 <?php
511 }
512
513 /**
514 * Displays default text item
515 *
516 * Overwrite this method to define specific item processing like enum, set, image and so on.
517 */
518 protected function show_item() {
519 // Set column value.
520 if ( 'new' === $this->show_context_action ) {
521 // Check if there is a default value.
522 if ( $this->item_default_value !== null &&
523 strtolower( $this->item_default_value ) !== 'null' ) {
524 $this->show_context_column_value = $this->item_default_value;
525 }
526 }
527
528 // Add input box.
529 $data_type = $this->data_type;
530 if ( 'number' === $this->data_type ) {
531 if ( 0 < $this->numeric_scale ) {
532 $data_type = 'float';
533 }
534 }
535 ?>
536 <input name="<?php echo esc_attr( $this->item_name ); ?>"
537 id="<?php echo esc_attr( $this->item_name ); ?>"
538 type="text"
539 value="<?php echo $this->show_context_column_value; // phpcs:ignore WordPress.Security.EscapeOutput ?>"
540 data-db-is-null="<?php echo null === $this->item_value ? 'true' : 'false'; ?>"
541 class="wpda_data_type_<?php echo esc_attr( $data_type ); ?> <?php echo esc_attr( $this->show_context_class_primary_key ); ?> <?php echo esc_attr( $this->item_class ); ?> <?php
542 if ( 'NO' === $this->is_nullable && ! $this->is_auto_increment ) {
543 echo 'wpda_not_null';
544 }
545 ?>"
546 <?php
547 switch( $this->data_type ) {
548 case 'string':
549 echo 'maxlength="' . esc_attr( $this->character_maximum_length ) . '"';
550 break;
551 case 'number':
552 echo 'data-number-format="' . esc_attr( $this->numeric_precision ) . ',' . esc_attr( $this->numeric_scale ) . '"';
553 }
554 ?>
555 <?php echo $this->is_readonly ? ' readonly' : ''; ?>
556 <?php echo esc_attr( $this->show_context_item_events ); ?>
557 placeholder="<?php echo esc_attr( $this->item_placeholder ); ?>"
558 />
559 <?php
560 if ( 'string' === $this->data_type ) {
561 ?>
562 <input name="<?php echo esc_attr( $this->item_name ); ?>_db_is_null"
563 value="<?php echo null === $this->item_value ? 'true' : 'false'; ?>"
564 type="hidden"
565 />
566 <?php
567 }
568 }
569
570 /**
571 * Het item name
572 *
573 * @return string
574 * @since 1.0.0
575 */
576 public function get_item_name() {
577
578 return $this->item_name;
579
580 }
581
582 /**
583 * Get item data type
584 *
585 * @return string
586 * @since 1.0.0
587 */
588 public function get_data_type() {
589
590 return $this->data_type;
591
592 }
593
594 /**
595 * Get item label
596 *
597 * @return string
598 * @since 1.0.0
599 */
600 public function get_item_label() {
601
602 return $this->item_label;
603
604 }
605
606 /**
607 * Get item value
608 *
609 * @return mixed
610 * @since 1.0.0
611 */
612 public function get_item_value() {
613
614 return $this->item_value;
615
616 }
617
618 /**
619 * Get item default value
620 *
621 * @return mixed
622 * @since 1.0.0
623 */
624 public function get_item_default_value() {
625
626 return $this->item_default_value;
627
628 }
629
630 /**
631 * Get item 'extra' info
632 *
633 * @return mixed
634 * @see WPDA_Simple_Form_Item::$item_extra
635 *
636 * @since 1.0.0
637 */
638 public function get_item_extra() {
639
640 return $this->item_extra;
641
642 }
643
644 /**
645 * Get enum values or empty
646 *
647 * @return array
648 * @since 1.0.0
649 */
650 public function get_item_enum() {
651
652 return $this->item_enum;
653
654 }
655
656 /**
657 * Get enum options or empty
658 *
659 * @return array
660 * @since 1.6.9
661 */
662 public function get_item_enum_options() {
663
664 return $this->item_enum_options;
665
666 }
667
668 /**
669 * Get enum text or empty
670 *
671 * @return array
672 * @since 1.6.9
673 */
674 public function get_item_enum_text() {
675
676 return $this->item_enum_text;
677
678 }
679
680 /**
681 * Get column type
682 *
683 * @return string
684 * @since 1.0.0
685 */
686 public function get_column_type() {
687
688 return $this->column_type;
689
690 }
691
692 /**
693 * Get item event
694 *
695 * @return String
696 * @since 1.0.0
697 */
698 public function get_item_event() {
699
700 return $this->item_event;
701
702 }
703
704 /**
705 * Get item Javascript code
706 *
707 * @return mixed
708 * @since 1.0.0
709 */
710 public function get_item_js() {
711
712 return $this->item_js;
713
714 }
715
716 /**
717 * Hide icon?
718 *
719 * @return boolean
720 * @since 1.0.0
721 */
722 public function get_item_hide_icon() {
723
724 return $this->item_hide_icon;
725
726 }
727
728 /**
729 * Get item CSS class
730 *
731 * @return string
732 * @since 1.0.0
733 */
734 public function get_item_class() {
735
736 return $this->item_class;
737
738 }
739
740 /**
741 * Get item visibility
742 *
743 * @return boolean
744 * @since 1.6.9
745 */
746 public function get_hide_item() {
747
748 return $this->hide_item;
749
750 }
751
752 /**
753 * Null values allowed?
754 *
755 * @return boolean
756 * @since 2.0.0
757 */
758 public function is_nullable() {
759
760 return $this->is_nullable;
761
762 }
763
764 /**
765 * Is column part of the primary key?
766 *
767 * @return boolean
768 * @since 2.0.0
769 */
770 public function is_key_column() {
771
772 return $this->is_key_column;
773
774 }
775
776 /**
777 * Item value
778 *
779 * @param string $value Item value
780 */
781 public function set_item_value( $value ) {
782
783 $this->item_value = $value;
784
785 }
786
787 /**
788 * Item label
789 *
790 * @param string $label Item label
791 */
792 public function set_label( $label ) {
793
794 $this->item_label = $label;
795
796 }
797
798 /**
799 * Set item default value
800 *
801 * @param string $item_default_value Default value
802 *
803 * @since 1.6.2
804 */
805 public function set_item_default_value( $item_default_value ) {
806
807 $this->item_default_value = $item_default_value;
808
809 }
810
811 /**
812 * Set item CSS class
813 *
814 * @param string $item_class HTML class name
815 *
816 * @since 1.6.2
817 */
818 public function set_item_class( $item_class ) {
819
820 $this->item_class = $item_class;
821
822 }
823
824 /**
825 * Set item visibility
826 *
827 * @param boolean $hide_item TRUE = hide item
828 *
829 * @since 1.6.9
830 */
831 public function set_hide_item( $hide_item ) {
832
833 $this->hide_item = $hide_item;
834
835 }
836
837 /**
838 * Set item js code
839 *
840 * @param string $item_js Item specific javascript code
841 *
842 * @since 1.6.9
843 */
844 public function set_item_js( $item_js ) {
845
846 $this->item_js = $item_js;
847
848 }
849
850 /**
851 * Set item enum
852 *
853 * @param string $item_enum Item enum value list
854 *
855 * @since 1.6.9
856 */
857 public function set_enum( $item_enum ) {
858
859 $this->item_enum = $item_enum;
860
861 }
862
863 /**
864 * Set item enum options
865 *
866 * @param string $item_enum_options Item enum option list
867 *
868 * @since 1.6.9
869 */
870 public function set_enum_options( $item_enum_options ) {
871
872 $this->item_enum_options = $item_enum_options;
873
874 }
875
876 /**
877 * Set item enum text
878 *
879 * @param string $item_enum_text Item enum text list.
880 *
881 * @since 1.6.9
882 */
883 public function set_enum_text( $item_enum_text ) {
884
885 $this->item_enum_text = $item_enum_text;
886
887 }
888
889 /**
890 * Set item data_type
891 *
892 * @param string $data_type Item data type
893 *
894 * @since 1.6.9
895 */
896 public function set_data_type( $data_type ) {
897
898 $this->data_type = $data_type;
899
900 }
901
902 /**
903 * Set item visibility
904 *
905 * @param boolean $item_hide_icon TRUE = hide type icon behind text field
906 *
907 * @since 2.0.8
908 */
909 public function set_item_hide_icon( $item_hide_icon ) {
910
911 $this->item_hide_icon = $item_hide_icon;
912
913 }
914
915 /**
916 * Set item is key column
917 *
918 * @param boolean $is_key_column TRUE|FALSE
919 */
920 public function set_is_key_column( $is_key_column ) {
921
922 $this->is_key_column = $is_key_column;
923
924 }
925
926 /**
927 * Set item is foreign key column
928 *
929 * @param boolean $is_foreign_key_column TRUE|FALSE
930 */
931 public function set_foreign_key_column( $is_foreign_key_column ) {
932
933 $this->is_foreign_key_column = $is_foreign_key_column;
934
935 }
936
937 /**
938 * Change item readonly property
939 *
940 * @param boolean $is_readonly TRUE|FALSE
941 * @return void
942 */
943 public function set_readonly( $is_readonly ) {
944 $this->is_readonly = $is_readonly;
945 }
946
947 /**
948 * Set item visibility on initialization
949 *
950 * @param boolean $hide_item_init TRUE = hide item init
951 *
952 * @since 1.6.9
953 */
954 public function set_hide_item_init( $hide_item_init ) {
955
956 $this->hide_item_init = $hide_item_init;
957
958 }
959
960 /**
961 * Check if item is valid
962 *
963 * @param $pre_insert
964 *
965 * @return bool
966 */
967 public function is_valid( $pre_insert = false ) {
968 if ( $this->is_auto_increment && $pre_insert ) {
969 return true;
970 }
971
972 if ( 'NO' === $this->is_nullable ) {
973 // Empty values are not allowed for this column: check value.
974 if ( '' === $this->item_value ) {
975 if (
976 isset( $_REQUEST[ "{$this->item_name}_db_is_null" ] ) &&
977 'false' === strtolower( $_REQUEST[ "{$this->item_name}_db_is_null" ] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
978 ) {
979 // Allow update if original column already was an empty string
980 return true;
981 }
982
983 // No value: inform user and set validation to failed.
984 $msg = new WPDA_Message_Box(
985 array(
986 'message_text' => ucfirst( str_replace( '_', ' ', $this->item_name ) ) .
987 ' ' . __( 'must be entered', 'wp-data-access' ),
988 'message_type' => 'error',
989 'message_is_dismissible' => false,
990 )
991 );
992 $msg->box();
993
994 return false;
995 }
996 }
997
998 if ( 'number' === $this->data_type ) {
999 if ( '' !== $this->item_value && null !== $this->item_value && ! is_numeric( $this->item_value ) ) {
1000 // Value is not numeric: inform user and set validation to failed.
1001 $msg = new WPDA_Message_Box(
1002 array(
1003 'message_text' => ucfirst( str_replace( '_', ' ', $this->item_name ) ) .
1004 ' ' . __( 'must be numeric', 'wp-data-access' ),
1005 'message_type' => 'error',
1006 'message_is_dismissible' => false,
1007 )
1008 );
1009 $msg->box();
1010
1011 return false;
1012 }
1013 }
1014
1015 return true;
1016 }
1017
1018 }
1019
1020 }
1021