'Business Listings', 'singular_name' => 'Business Listing', 'add_new' => 'Add New Listing', 'add_new_item' => 'Add New Business Listing', 'edit_item' => 'Edit Business Listing', 'new_item' => 'New Business Listing', 'view_item' => 'View Business Listing', 'search_items' => 'Search Listings', 'not_found' => 'No listings found', 'not_found_in_trash' => 'No listings found in trash', 'menu_name' => 'Business Directory', ]; register_post_type( 'abddir_listing', [ 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => false, // We handle our own menu 'query_var' => true, 'rewrite' => [ 'slug' => 'listing', 'with_front' => false ], 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, 'supports' => [ 'title', 'thumbnail' ], 'show_in_rest' => false, ] ); } add_action( 'init', 'abddir_register_cpt' ); /** * Dynamically relabel the abddir_listing CPT based on the directory type * of the listing being edited. Runs on admin_init so labels are set * before WordPress uses them to render the H1, buttons, etc. */ function abddir_dynamic_listing_labels() { if ( ! is_admin() ) return; $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only, used only to look up post type for label customization if ( ! $post_id ) return; if ( get_post_type( $post_id ) !== 'abddir_listing' ) return; $dir_id = intval( get_post_meta( $post_id, 'abddir_directory_id', true ) ); $dir_s = abddir_get_directory_settings( $dir_id ); $dir_type = $dir_s['type'] ?? 'business'; if ( $dir_type === 'business' ) return; // Already correct global $wp_post_types; $l = $wp_post_types['abddir_listing']->labels; if ( $dir_type === 'member' ) { $l->name = 'Member Listings'; $l->singular_name = 'Member Listing'; $l->add_new_item = 'Add New Member Listing'; $l->edit_item = 'Edit Member Listing'; $l->new_item = 'New Member Listing'; $l->view_item = 'View Member Listing'; } elseif ( $dir_type === 'employee' ) { $l->name = 'Employee Listings'; $l->singular_name = 'Employee Listing'; $l->add_new_item = 'Add New Employee Listing'; $l->edit_item = 'Edit Employee Listing'; $l->new_item = 'New Employee Listing'; $l->view_item = 'View Employee Listing'; } } add_action( 'admin_init', 'abddir_dynamic_listing_labels' );