/** * Returns a single specified option of a tab. * * This function uses the WordPress core function `get_option()` to get the options array for the tab. * If the required field option is not available, this function will automatically return its default value. * * @since 0.5.0 * @param string $tab_slug the tab slug to get the option for * @param string $field_slug the field slug to get the option for * @param boolean $formatted whether to return an automatically formatted value, ready for output (default is false) * @return mixed the option */ function wpod_get_option($tab_slug, $field_slug, $formatted = false) { $_options = get_option($tab_slug, array()); if (doing_action('wpod') || !did_action('wpod')) { if (isset($_options[$field_slug])) { return $_options[$field_slug]; } return null; } $option = null; $field = \WPDLib\Components\Manager::get('*.*.' . $tab_slug . '.*.' . $field_slug, 'WPDLib\\Components\\Menu.WPOD\\Components\\Screen', true); if ($field) { $option = \WPOD\Utility::parse_option(isset($_options[$field->slug]) ? $_options[$field->slug] : null, $field, $formatted); } return $option; }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPDLib\Components\Menu $parent the parent component * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { $this->args = Utility::validate_position_args($this->args); $this->args = Utility::validate_help_args($this->args, 'help'); } return $status; }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPOD\Components\Section $parent the parent component * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { if (is_array($this->args['class'])) { $this->args['class'] = implode(' ', $this->args['class']); } if (isset($this->args['options']) && !is_array($this->args['options'])) { $this->args['options'] = array(); } $parent_section = $this->get_parent(); $parent_tab = $parent_section->get_parent(); $this->args['id'] = $parent_tab->slug . '-' . $this->slug; $this->args['name'] = $parent_tab->slug . '[' . $this->slug . ']'; $this->_field = FieldManager::get_instance($this->args); if ($this->_field === null) { return new UtilError('no_valid_field_type', sprintf(__('The field type %1$s assigned to the field component %2$s is not a valid field type.', 'options-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope()); } if (null === $this->args['default']) { $this->args['default'] = $this->_field->validate(); } $this->args = Utility::validate_position_args($this->args); } return $status; }