/** * Validates the arguments array. * * @since 0.5.0 * @param WPPTD\Components\PostType $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 (in_array($this->slug, array('post_format', 'link_category', 'nav_menu'))) { return new UtilError('no_valid_taxonomy', sprintf(__('The taxonomy slug %s is forbidden since it would interfere with WordPress Core functionality.', 'post-types-definitely'), $this->slug), '', ComponentManager::get_scope()); } // show notice if slug contains dashes if (strpos($this->slug, '-') !== false) { App::doing_it_wrong(__METHOD__, sprintf(__('The taxonomy slug %s contains dashes which is discouraged. It will still work for the most part, but we recommend to adjust the slug if possible.', 'post-types-definitely'), $this->slug), '0.5.0'); } // generate titles if not provided $this->args = Utility::validate_titles($this->args, $this->slug, 'taxonomy'); // generate taxonomy labels $this->args = Utility::validate_labels($this->args, 'labels', 'taxonomy'); // generate taxonomy updated messages $this->args = Utility::validate_labels($this->args, 'messages', 'taxonomy'); // set some defaults if (null === $this->args['rewrite']) { if ($this->args['public']) { $this->args['rewrite'] = array('slug' => str_replace('_', '-', $this->slug), 'with_front' => true, 'hierarchical' => $this->args['hierarchical'], 'ep_mask' => EP_NONE); } else { $this->args['rewrite'] = false; } } // handle REST API default if (null === $this->args['show_in_rest']) { if (null !== $this->args['public']) { $this->args['show_in_rest'] = $this->args['public']; } else { $this->args['show_in_rest'] = false; } } $this->args = Utility::validate_ui_args($this->args); $this->args = Utility::validate_position_args($this->args); // handle term table $this->args = TaxonomyTableHandler::validate_args($this->args); // handle help $this->args = Utility::validate_help_args($this->args, 'help'); // handle list help $this->args = Utility::validate_help_args($this->args, 'list_help'); } return $status; }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPWD\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 (!empty($this->args['class'])) { $this->args['class'] .= ' '; } $this->args['class'] .= 'widefat'; if (isset($this->args['options']) && !is_array($this->args['options'])) { $this->args['options'] = array(); } $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.', 'widgets-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; }
/** * 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) { if (in_array($this->slug, array('revision', 'nav_menu_item', 'action', 'author', 'order', 'plugin', 'theme'))) { return new UtilError('no_valid_post_type', sprintf(__('The post type slug %s is forbidden since it would interfere with WordPress Core functionality.', 'post-types-definitely'), $this->slug), '', ComponentManager::get_scope()); } // show notice if slug contains dashes if (strpos($this->slug, '-') !== false) { App::doing_it_wrong(__METHOD__, sprintf(__('The post type slug %s contains dashes which is discouraged. It will still work for the most part, but we recommend to adjust the slug if possible.', 'post-types-definitely'), $this->slug), '0.5.0'); } // generate titles if not provided $this->args = Utility::validate_titles($this->args, $this->slug, 'post_type'); // generate post type labels $this->args = Utility::validate_labels($this->args, 'labels', 'post_type'); // generate post type updated messages $this->args = Utility::validate_labels($this->args, 'messages', 'post_type'); // generate post type bulk action messages $this->args = Utility::validate_labels($this->args, 'bulk_messages', 'post_type'); // set some defaults if (null === $this->args['rewrite']) { if ($this->args['public']) { $this->args['rewrite'] = array('slug' => str_replace('_', '-', $this->slug), 'with_front' => false, 'ep_mask' => EP_PERMALINK); } else { $this->args['rewrite'] = false; } } // handle REST API default if (null === $this->args['show_in_rest']) { if (null !== $this->args['publicly_queryable']) { $this->args['show_in_rest'] = $this->args['publicly_queryable']; } elseif (null !== $this->args['public']) { $this->args['show_in_rest'] = $this->args['public']; } else { $this->args['show_in_rest'] = false; } } $this->args = Utility::validate_ui_args($this->args); $menu = $this->get_parent(); if ($this->args['show_in_menu'] && empty($menu->slug)) { $this->args['show_in_menu'] = true; } elseif ($this->args['show_in_menu']) { $this->args['show_in_menu'] = false; if (null === $this->args['show_in_admin_bar']) { $this->args['show_in_admin_bar'] = true; } $this->show_in_menu_manually = true; if (isset($this->args['menu_position'])) { App::doing_it_wrong(__METHOD__, sprintf(__('A menu position is unnecessarily provided for the post type %s - the menu position is already specified by its parent menu.', 'post-types-definitely'), $this->slug), '0.5.0'); unset($this->args['menu_position']); } if (isset($this->args['menu_icon'])) { App::doing_it_wrong(__METHOD__, sprintf(__('A menu icon is unnecessarily provided for the post type %s - the menu icon is already specified by its parent menu.', 'post-types-definitely'), $this->slug), '0.5.0'); unset($this->args['menu_icon']); } } $this->args = Utility::validate_position_args($this->args); // handle post table $this->args = PostTypeTableHandler::validate_args($this->args); // handle help $this->args = Utility::validate_help_args($this->args, 'help'); // handle list help $this->args = Utility::validate_help_args($this->args, 'list_help'); } return $status; }
/** * Validates the component. * * This method should be overwritten in the component class itself. * However it must call the original method from within. * * It will throw an error when trying to add an additional parent to a component that does not support multiple parents. * * @since 0.5.0 * @param WPDLib\Components\Base $parent the parent component of the 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) { if (null !== $parent) { if (count($this->parents) > 0 && !$this->supports_multiparents()) { return new UtilError('no_multiparent_component', sprintf(__('The component %1$s of class %2$s already has a parent assigned and is not a multiparent component.', 'wpdlib'), $this->slug, get_class($this)), '', ComponentManager::get_scope()); } $this->parents[$parent->slug] = $parent; } if (!$this->validated) { if (empty($this->slug)) { return new UtilError('empty_slug_component', __('A component with an empty slug is not allowed.', 'wpdlib'), '', ComponentManager::get_scope()); } $defaults = $this->get_defaults(); foreach ($defaults as $key => $default) { if (!isset($this->args[$key])) { $this->args[$key] = $default; } } $this->scope = ComponentManager::get_scope(); if (!empty($this->validate_filter)) { $this->args = apply_filters($this->validate_filter, $this->args, $this); } $this->validated = true; return true; } return false; }
/** * Validates the arguments array. * * @since 0.5.0 */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { if (null === $this->args['capability']) { $this->args['capability'] = $parent->capability; } if (isset($this->args['priority'])) { if (null === $this->args['position']) { $this->args['position'] = $this->args['priority']; } unset($this->args['priority']); } $this->args = Utility::validate_position_args($this->args); if (null === $this->args['mode']) { $this->args['mode'] = $parent->get_parent()->mode; } 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(); } if (in_array($this->args['type'], array('multiselect', 'multibox'), true)) { return new UtilError('multichoice_not_supported', sprintf(__('The multichoice field type assigned to the field component %s is not supported in the Customizer.', 'customizer-definitely'), $this->slug), '', ComponentManager::get_scope()); } if ('repeatable' == $this->args['type']) { return new UtilError('repeatable_not_supported', sprintf(__('The repeatable field type assigned to the field component %s is not supported in the Customizer.', 'customizer-definitely'), $this->slug), '', ComponentManager::get_scope()); } $this->_field = FieldManager::get_instance($this->args); if (null === $this->_field) { 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.', 'customizer-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope()); } if (null === $this->args['default']) { $this->args['default'] = $this->_field->validate(); } $this->args['preview_args'] = Customizer::instance()->validate_preview_args($this->args['preview_args'], $this->args['type'], $this->_field); if (null === $this->args['transport']) { if ($this->args['preview_args']['update_callback']) { $this->args['transport'] = 'postMessage'; } else { $this->args['transport'] = 'refresh'; } } } return $status; }