Home › Forums › Legacy Support › Support queries › Other issues › Avoid use of extract (PHP function) in meta_box.php of vibe-customtypes plugin
- This topic has 2 replies, 2 voices, and was last updated 8 years, 1 month ago by eclipsedev.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
April 2, 2016 at 12:16 am #40387eclipsedevSpectatorHello, Wanted to file a Bug Report. Within the meta_box_callback function of the meta_box.php file in the vibe-customtypes plugin the extract function is used to take the $field attributes and convert them to individual php fields;
// get data for this field extract( $field );
This should be avoided and direct param references should be used instead (like $field['param']) as it introduces the following type of issue. If you have one meta_field that has the 'std' attribute and the next meta_field doesn't have this then the $std variable will still exist from the previous iteration of the loop. For instance the following is a snippet from the Course Metabox in custom_meta_boxes.php;array( // Text Input 'label' => __('Auto Evaluation','vibe-customtypes'), // <label> 'desc' => __('Evalute Courses based on Quizes scores available in Course (* Requires atleast 1 Quiz in course)','vibe-customtypes'), // description 'id' => $prefix.'course_auto_eval', // field id and name 'type' => 'yesno', // type of field 'options' => array( array('value' => 'H', 'label' =>'Hide'), array('value' => 'S', 'label' =>'Show'), ), 'std' => 'H' ), array( // Text Input 'label' => __('Course Start Date','vibe-customtypes'), // <label> 'desc' => __('Date from which Course Begins','vibe-customtypes'), // description 'id' => $prefix.'start_date', // field id and name 'type' => 'date', // type of field ), array( // Text Input 'label' => __('Maximum Students in Course','vibe-customtypes'), // <label> 'desc' => __('Maximum number of students who can pursue the course at a time.','vibe-customtypes'), // description 'id' => $prefix.'max_students', // field id and name 'type' => 'number', // type of field ),
As seen above the Auto Evaluation field has std defined but the following fields (Course Start Date and Maximum Students in Course) do not. This causes both of these following fields to have the $std variable defined and populated with the information from the Auto Evaluation field causing them to have a default value of 'H' when a course is first created. This alone is problematic... With any number fields like Maximum Students in Course having their default set to 'H' introduces the following error/warning in the console on page load as 'H' isn't a value number;The specified value "H" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?
You may only get this warning in Chrome, but irregardless it's an issue on all browsers. To resolve; completely avoid the use of extract (it's bad practice anyway) and directly reference $field values such as $field['std']. This will require extensive updating throughout the meta_box.php script. Thank youApril 2, 2016 at 9:14 am #40504Anshuman SahuKeymasterNice catch . But to resolve this we will be merging a default array to set the value for each element in array for each field with the help of wp_parse_args() function that we are using in various wplms and vibe widgets . Adding to issue log . Thanks for reporting .April 4, 2016 at 5:58 pm #40954eclipsedevSpectatorThanks Alex, Appreciated. -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- The topic ‘Avoid use of extract (PHP function) in meta_box.php of vibe-customtypes plugin’ is closed to new replies.