/** * 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; }
/** * Validates the post type component arguments that are related to the list table. * * @since 0.5.0 * @see WPPTD\Components\PostType::validate() * @param array $args the original arguments * @return array the validated arguments */ public static function validate_args($args) { // handle admin table columns if (!$args['show_ui'] || !is_array($args['table_columns'])) { $args['table_columns'] = array(); } $_table_columns = $args['table_columns']; $args['table_columns'] = array(); $core_column_slugs = array('title', 'author', 'comments', 'date'); foreach ($_table_columns as $column_slug => $column_args) { if (strpos($column_slug, 'meta-') === 0 || strpos($column_slug, 'taxonomy-') === 0 || strpos($column_slug, 'custom-') === 0 || in_array($column_slug, $core_column_slugs)) { if (false !== $column_args) { if (!is_array($column_args)) { $column_args = array(); } $column_args = wp_parse_args($column_args, array('title' => '', 'filterable' => false, 'sortable' => false)); if (strpos($column_slug, 'meta-') === 0) { if (!isset($column_args['meta_key']) || empty($column_args['meta_key'])) { $column_args['meta_key'] = substr($column_slug, strlen('meta-')); } } elseif (strpos($column_slug, 'taxonomy-') === 0) { if (!isset($column_args['taxonomy_slug']) || empty($column_args['taxonomy_slug'])) { $column_args['taxonomy_slug'] = substr($column_slug, strlen('taxonomy-')); } } elseif (strpos($column_slug, 'custom-') === 0) { if (!isset($column_args['custom_callback']) || empty($column_args['custom_callback'])) { $column_args['custom_callback'] = substr($column_slug, strlen('custom-')); } } } $args['table_columns'][$column_slug] = $column_args; } else { App::doing_it_wrong(__METHOD__, sprintf(__('The admin table column slug %s is invalid. It must be prefixed with either "meta-", "taxonomy-" or "custom-".', 'post-types-definitely'), $column_slug), '0.5.0'); } } $args = PostTypeActionHandler::validate_args($args); return $args; }
/** * Renders the term metabox. * * It displays the title and description (if available) for the metabox. * Then it shows the fields of this metabox or, if no fields are available, calls the callback function. * * @since 0.6.0 * @param WP_Term $term the term currently being shown */ public function render($term) { $parent_taxonomy = $this->get_parent(); if ('side' == $this->args['context']) { echo '<div class="wpdlib-narrow">'; } /** * This action can be used to display additional content on top of this term metabox. * * @since 0.6.0 * @param string the slug of the current metabox * @param array the arguments array for the current metabox * @param string the slug of the current taxonomy */ do_action('wpptd_term_metabox_before', $this->slug, $this->args, $parent_taxonomy->slug); if (!empty($this->args['description'])) { echo '<p class="description">' . $this->args['description'] . '</p>'; } if (count($this->get_children()) > 0) { $table_atts = array('class' => 'form-table wpdlib-form-table'); /** * This filter can be used to adjust the term editing form table attributes. * * @since 0.6.0 * @param array the associative array of form table attributes * @param WPPTD\Components\TermMetabox current metabox instance */ $table_atts = apply_filters('wpptd_term_table_atts', $table_atts, $this); echo '<table' . FieldManager::make_html_attributes($table_atts, false, false) . '>'; foreach ($this->get_children() as $field) { $field->render($term); } echo '</table>'; } elseif ($this->args['callback'] && is_callable($this->args['callback'])) { call_user_func($this->args['callback'], $term); } else { App::doing_it_wrong(__METHOD__, sprintf(__('There are no fields to display for metabox %s. Either add some or provide a valid callback function instead.', 'post-types-definitely'), $this->slug), '0.5.0'); } /** * This action can be used to display additional content at the bottom of this term metabox. * * @since 0.6.0 * @param string the slug of the current metabox * @param array the arguments array for the current metabox * @param string the slug of the current taxonomy */ do_action('wpptd_term_metabox_after', $this->slug, $this->args, $parent_taxonomy->slug); if ('side' == $this->args['context']) { echo '</div>'; } }