'value' ) ). * If false, no features will be added. * Default is an array containing 'title' and 'editor'. * @var false|array|string[] */ public false|array $supports = ['title', 'author', 'thumbnail', 'editor', 'revisions', 'custom-fields', 'excerpt', 'content']; /** * Provide a callback function that sets up the meta boxes for the edit form. * Do remove_meta_box() and add_meta_box() calls in the callback. Default null. * @var mixed|null */ public mixed $register_meta_box_cb = null; /** * An array of taxonomy identifiers that will be registered for the post type. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type() . * @var array */ public array $taxonomies; /** * Whether there should be post type archives, or if a string, the archive slug to use. * Will generate the proper rewrite rules if $rewrite is enabled. Default false. * @var bool|string */ public bool|string $has_archive = true; /** * Triggers the handling of rewrites for this post type. To prevent rewrite, set to false. * Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be passed with any of these keys: * slug {string} - Customize the permastruct slug. Defaults to $post_type key. * with_front {bool} - Whether the permastruct should be prepended with WP_Rewrite::$front. * Default true. * feeds {bool} - Whether the feed permastruct should be built for this post type. Default is value of $has_archive. * pages {bool} - Whether the permastruct should provide for pagination. Default true. * ep_mask {int} - Endpoint mask to assign. If not specified and permalink_epmask is set, inherits from $permalink_epmask. If not specified and permalink_epmask is not set, defaults to EP_PERMALINK. * @var bool|array */ public bool|array $rewrite; /** * Sets the query_var key for this post type. * Defaults to $post_type key. * If false, a post type cannot be loaded at ?{query_var}={post_slug}. * If specified as a string, the query ?{query_var_string}={post_slug} will be valid. * @var string|bool */ public string|bool $query_var; /** * Whether to allow this post type to be exported. Default true. * @var bool */ public bool $can_export = true; /** * Whether to delete posts of this type when deleting a user. * If true, posts of this type belonging to the user will be moved to Trash when the user is deleted. * If false, posts of this type belonging to the user will *not* be trashed or deleted. * If not set (the default), posts are trashed if post type supports the 'author' feature. Otherwise posts are not trashed or deleted. * Default null. * @var bool */ public bool $delete_with_user; /** * Array of blocks to use as the default initial state for an editor session. Each item should be an array containing block name and optional attributes. * @var array */ public array $template; /** * Whether the block template should be locked if $template is set. * If set to 'all', the user is unable to insert new blocks, move existing blocks and delete blocks. * If set to 'insert', the user is able to move existing blocks but is unable to insert new blocks and delete blocks. * Default false. * @var string|false */ public string|false $template_lock; public function __construct(string $postType, string $singular, string $plural) { $this->postType = jvbCheckBase($postType); $this->labels = $this->buildLabels($singular, $plural); } public function register():void { $args = array_filter(get_object_vars($this)); // error_log('Got Object Vars: '.print_r($args, true)); // error_log('Filtered: '.print_r(array_filter($args), true)); // $args = [ // 'labels' => $this->labels, // 'public' => $this->public, // 'hierarchical' => $this->hierarchical, // 'has_archive' => $this->has_archive, // 'can_export' => $this->can_export, // ]; // if (isset($this->exclude_from_search)) { // $args['exclude_from_search'] = $this->exclude_from_search; // } // if (isset($this->publicly_queryable)) { // $args['publicly_queryable'] = $this->publicly_queryable; // } // if (isset($this->show_ui)) { // $args['show_ui'] = $this->show_ui; // } // if (isset($this->show_in_menu)) { // $args['show_in_menu'] = $this->show_in_menu; // } // if (isset($this->show_in_nav_menus)) { // $args['show_in_nav_menus'] = $this->show_in_nav_menus; // } // if (isset($this->show_in_admin_bar)) { // $args['show_in_admin_bar'] = $this->show_in_admin_bar; // } // if (isset($this->show_in_rest)) { // $args['show_in_rest'] = $this->show_in_rest; // } // if (isset($this->rest_base)) { // $args['rest_base'] = $this->rest_base; // } // if (isset($this->rest_namespace)) { // $args['rest_namespace'] = $this->rest_namespace; // } // if (isset($this->rest_controller_class)) { // $args['rest_controller_class'] = $this->rest_controller_class; // } // if (isset($this->autosave_rest_controller_class)) { // $args['autosave_rest_controller_class'] = $this->autosave_rest_controller_class; // } // if (isset($this->revisions_rest_controller_class)) { // $args['revisions_rest_controller_class'] = $this->revisions_rest_controller_class; // } // if (isset($this->late_route_registration)) { // $args['late_route_registration'] = $this->late_route_registration; // } // if (isset($this->menu_position)) { // $args['menu_position'] = $this->menu_position; // } // if (isset($this->menu_icon)) { // $args['menu_icon'] = $this->menu_icon; // } // if (isset($this->capability_type)) { // $args['capability_type'] = $this->capability_type; // } // if (isset($this->capabilities)) { // $args['capabilities'] = $this->capabilities; // } // if (isset($this->map_meta_cap)) { // $args['map_meta_cap'] = $this->map_meta_cap; // } // if (isset($this->supports)) { // if ($this->supports) { // $allowed = ['title','editor', 'comments', 'revisions','trackbacks','author','excerpt','page-attributes','thumbnail','custom-fields','post-formats']; // $this->supports = array_intersect($allowed, $this->supports); // } // $args['supports'] = $this->supports; // } // if (isset($this->register_meta_box_cb)) { // $args['register_meta_box_cb'] = $this->register_meta_box_cb; // } // if (isset($this->taxonomies)) { // $args['taxonomies'] = $this->taxonomies; // } // if (isset($this->rewrite)) { // $args['rewrite'] = $this->rewrite; // } // if (isset($this->query_var)) { // $args['query_var'] = $this->query_var; // } // if (isset($this->delete_with_user)) { // $args['delete_with_user'] = $this->delete_with_user; // } // if (isset($this->template)) { // $args['template'] = $this->template; // } // if (isset($this->template_lock)) { // $args['template_lock'] = $this->template_lock; // } unset ($args['postType']); // error_log('Registering PostType '.$this->postType.', with args: '.print_r($args, true)); $registered = register_post_type($this->postType, $args); if (is_wp_error($registered)) { JVB()->error()->log('JVBase\registrar\Posts', 'Could not register post type', $registered->get_error_messages()); } } private function buildLabels(string $singular, string $plural): array { return [ 'name' => $plural, 'singular_name' => $singular, 'menu_name' => $plural, 'name_admin_bar' => $singular, 'add_new' => "Add New", 'add_new_item' => "Add New {$singular}", 'new_item' => "New {$singular}", 'edit_item' => "Edit {$singular}", 'view_item' => "View {$singular}", 'all_items' => "All {$plural}", 'search_items' => "Search {$plural}", 'parent_item_colon' => "Parent {$plural}:", 'not_found' => "No {$plural} found.", 'not_found_in_trash' => "No {$plural} found in Trash.", ]; } }