post_type, self::PREFIX ) !== 0 ) { return; } wp_enqueue_style( 'mapfield-spots-admin', MAPFIELD_SPOTS_URL . 'assets/admin.css', array( 'mapfield-spots-palette' ), MAPFIELD_SPOTS_VERSION ); wp_enqueue_script( 'mapfield-spots-admin', MAPFIELD_SPOTS_URL . 'assets/admin.js', array(), MAPFIELD_SPOTS_VERSION, true ); } // "All spots" / "{Singular} map settings" nav on a Spot's edit screen. // edit_form_top is the earliest hook available (still inside the form, // below H1); admin.js relocates this row above the H1 on page load. public function render_nav_buttons( \WP_Post $post ): void { $map_type = Map_Types::get_by_post_type( $post->post_type ); if ( ! $map_type ) { return; } ?>
base ) { return; } $map_type = Map_Types::get_by_post_type( $screen->post_type ); if ( ! $map_type ) { return; } ?> $config ) { $this->register_post_type( $slug, $config ); if ( ! empty( $config['fields']['category'] ) ) { $this->register_taxonomy( $slug, $config ); } } } private function register_post_type( string $slug, array $config ): void { $post_type = self::post_type_slug( $slug ); // 'editor' is deliberately excluded — see class docblock. $supports = array( 'title' ); if ( ! empty( $config['fields']['photo'] ) ) { $supports[] = 'thumbnail'; } $singular = $config['label_singular'] ?: $slug; $plural = $config['label_plural'] ?: $slug; register_post_type( $post_type, array( 'label' => $plural, 'labels' => array( 'name' => $plural, 'singular_name' => $singular, /* translators: %s: singular label of the map type, e.g. "Location" */ 'add_new_item' => sprintf( __( 'Add %s', 'mapfield-spots' ), $singular ), /* translators: %s: singular label of the map type */ 'edit_item' => sprintf( __( 'Edit %s', 'mapfield-spots' ), $singular ), /* translators: %s: plural label of the map type, e.g. "Restaurants" */ 'all_items' => sprintf( __( '%s spots', 'mapfield-spots' ), $plural ), ), 'public' => true, // Kept out of the admin menu to avoid sidebar clutter; reachable via // "Edit Spots" in "Your maps" (show_ui stays true via 'public'). 'show_in_menu' => false, 'show_in_rest' => true, // block editor + REST access for the front-end map 'supports' => $supports, 'has_archive' => false, 'rewrite' => array( 'slug' => $slug ), ) ); } private function register_taxonomy( string $slug, array $config ): void { $taxonomy = self::taxonomy_slug( $slug ); $post_type = self::post_type_slug( $slug ); register_taxonomy( $taxonomy, array( $post_type ), array( 'label' => __( 'Categories', 'mapfield-spots' ), 'hierarchical' => true, // checkbox list, not a free-text tag input 'public' => true, 'show_in_rest' => true, 'show_admin_column' => true, ) ); // Creates configured terms if missing (colour stored as term meta); // harmless to re-run every 'init' since term_exists() short-circuits. foreach ( $config['categories'] as $cat ) { if ( ! term_exists( $cat['slug'], $taxonomy ) ) { $inserted = wp_insert_term( $cat['label'], $taxonomy, array( 'slug' => $cat['slug'] ) ); if ( ! is_wp_error( $inserted ) ) { update_term_meta( $inserted['term_id'], 'mapfield_spots_color', $cat['color'] ); } } else { $term = get_term_by( 'slug', $cat['slug'], $taxonomy ); if ( $term ) { update_term_meta( $term->term_id, 'mapfield_spots_color', $cat['color'] ); } } } } }