Automated Custom Post Type and ACF Options Pages registration
Define content once and let the theme do the rest. Custom Post Types and ACF Options Pages are registered automatically based on simple, convention‑driven configuration—no boilerplate or repetitive hooks. Editors get purpose‑built post types and centralized settings pages out of the box, while developers keep a clean codebase with predictable slugs, labels, capabilities, and fields. The result is faster setup, fewer mistakes, and a consistent editing experience that scales as your content model grows.
Overview
- CPTs are declared via a filter and registered on
initbyChisel\WP\CustomPostTypes(inc/WP/CustomPostTypes.php) usingChisel\Factory\RegisterCustomPostType(inc/Factory/RegisterCustomPostType.php). - Taxonomies are declared via a filter and registered on
initbyChisel\WP\CustomTaxonomies(inc/WP/CustomTaxonomies.php) usingChisel\Factory\RegisterCustomTaxonomy(inc/Factory/RegisterCustomTaxonomy.php). - ACF Options Pages are declared in arrays, filterable, and registered on
acf/initbyChisel\WP\Acf(inc/WP/Acf.php) usingChisel\Factory\RegisterAcfOptionsPage(inc/Factory/RegisterAcfOptionsPage.php).
Custom Post Types
- Where:
inc/WP/CustomPostTypes.php→register_post_types()- Reads
$this->post_types→set_post_types()→apply_filters('chisel_custom_post_types', $post_types) - Applies defaults, then calls
RegisterCustomPostType::register_post_type()
- Reads
- Defaults (set in
after_setup_themeviaset_properties()):supports→ filterchisel_default_post_type_supports(default:['title','page-attributes','revisions','author'])rewrite_args→ filterchisel_default_post_type_rewrite_args(default slug empty;with_front,feeds,pages,ep_mask)
- Registration (
inc/Factory/RegisterCustomPostType.php):- Labels auto-generated; can override via
labelsargs. rewrite.slugdefaults to the CPT name.show_in_restdefaults totrue(keeps block editor/REST enabled).- If
supportscontainsthumbnail, CPT is added to filterchisel_post_thumbnails_post_types.
- Labels auto-generated; can override via
- Additional supported args (opt-in if provided in your CPT array):
rest_base,rest_namespace,rest_controller_class,autosave_rest_controller_class,revisions_rest_controller_class,late_route_registration,map_meta_cap,register_meta_box_cb,taxonomies,template,template_lock
Add a CPT (example)
private function set_post_types() {
$this->post_types = array(
'book' => array(
'singular' => __('Book', 'chisel'),
'plural' => __('Books', 'chisel'),
'supports' => array( 'editor','thumbnail','excerpt' ), // merged with defaults
'menu_icon' => 'dashicons-book',
'public' => true,
'has_archive'=> true,
'rewrite' => array( 'slug' => 'library' ),
'show_in_rest' => true,
'labels' => array( 'add_new_item' => __('Add New Book', 'chisel') ),
)
);
}PHPPer-CPT default overrides (optional)
chisel_default_post_type_supports_{post_type}chisel_default_post_type_rewrite_args_{post_type}
Custom Taxonomies
- Where:
inc/WP/CustomTaxonomies.php→register_taxonomies()- Reads
$this->taxonomies→set_taxonomies()→apply_filters('chisel_custom_taxonomies', $taxonomies) - Applies defaults, then calls RegisterCustomTaxonomy::register_taxonomy()
- Reads
- Defaults (set in
after_setup_themeviaset_properties()):capabilities→ filterchisel_default_taxonomy_capabilities- Default: manage/edit/delete terms →
manage_categories, assign →edit_posts
- Default: manage/edit/delete terms →
rewrite_args→ filterchisel_default_taxonomy_rewrite_args- Default: slug empty,
with_front,hierarchical,ep_mask
- Default: slug empty,
- Registration (
inc/Factory/RegisterCustomTaxonomy.php):- Labels auto-generated; can override via
labelsargs. rewrite.slugdefaults to the taxonomy name.show_in_restdefaults totrue.
- Labels auto-generated; can override via
- Additional supported args (opt-in if provided in your taxonomy array):
rest_namespace,rest_controller_class,meta_box_cb,default_term,sort,args
Add a Taxonomy (example)
Attach to the CPT above:
private function set_taxonomies() {
$this->taxonomies = array(
'genre' => array(
'singular' => __('Genre', 'chisel'),
'plural' => __('Genres', 'chisel'),
'post_types' => array( 'book' ),
'public' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'genres' ),
'show_in_rest' => true,
)
);
}PHPPer-taxonomy default overrides (optional)
chisel_default_taxonomy_capabilities_{taxonomy}chisel_default_taxonomy_rewrite_args_{taxonomy}
ACF Options Pages
- Where:
inc/WP/Acf.php- Base pages set in
set_options_pages() - Subpages can be added via
set_options_sub_pages() - On
acf/init, arrays are filtered then registered viaRegisterAcfOptionsPage
- Base pages set in
- Filters:
- **
c**hisel_acf_options_pagesfor top-level pages chisel_acf_options_sub_page**s**for subpages
- **
- Registration details (
inc/Factory/RegisterAcfOptionsPage.php):- Supported keys:
page_title(required),menu_title,menu_slug(required),capability,position,redirect,icon_url,post_id,autoload,update_button,updated_message,parent_slug(for subpages) - Uses
acf_add_options_page()oracf_add_options_sub_page()based ontype
- Supported keys:
Add an ACF Options Page (example)
private function set_options_pages() {
$this->acf_options_pages = array(
array(
'menu_slug' => 'theme-settings',
'page_title' => __('Theme Settings', 'chisel'),
'menu_title' => __('Theme Settings', 'chisel'),
'icon_url' => 'dashicons-admin-generic',
'position' => 45,
'post_id' => 'theme_settings',
),
);
}
private function set_options_sub_pages() {
$this->acf_options_sub_pages = array(
array(
'menu_slug' => 'theme-header',
'page_title' => __('Header', 'chisel'),
'menu_title' => __('Header', 'chisel'),
'parent_slug'=> 'theme-settings',
),
);
}PHPPractical notes
- Init order: Defaults set on
after_setup_theme(priority 7). Registration runs oninit(CPT/Tax) andacf/init(options pages). - REST/Editor: Both CPTs and taxonomies default to
show_in_rest: true. Disable if needed. - Permalinks: Changing
rewrite.slugrequires visiting Settings → Permalinks to flush rewrite rules. - Thumbnails: If a CPT includes
thumbnailinsupports, it’s propagated tochisel_post_thumbnails_post_typesso theme thumbnail support attaches correctly.
Summary
- Declare CPTs by adding configuration to
set_post_types()orset_taxonomies()or via the filterschisel_custom_post_typesorchisel_custom_taxonomies; the theme handles consistent defaults and label generation. - Fine-tune behavior using per-type default filters and full argument arrays.
- Add ACF options pages by adding configuration to
set_options_pages()orset_options_sub_pages()or throughchisel_acf_options_pages/chisel_acf_options_sub_pagesfilters; the factory wrapsacf_add_options_page()safely.