/** * 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 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; }