<?php
/**
 * Custom post type registrations.
 *
 * @package kadence-child
 */

defined( 'ABSPATH' ) || exit;

/**
 * Register the `lawyers` post type.
 *
 * Replaces the `staff` post type that the Total theme used to register. The 13
 * lawyer records were migrated onto this post type in place (their IDs and slugs
 * were never changed), so every /lawyers/<name>/ URL is preserved.
 *
 * Two things here are load-bearing and must not be "tidied":
 *
 * 1. The rewrite slug is HARDCODED to 'lawyers'. It used to come from the Total
 *    theme's `staff_slug` Customizer setting, and theme mods are stored per
 *    theme — so that value disappeared the moment Total was deactivated. The
 *    published URLs depend on this string.
 *
 * 2. `has_archive` MUST stay false. The page "Our Lawyers" (ID 14661) has the
 *    slug `lawyers`, which is the same string as the rewrite slug above. With an
 *    archive enabled the two collide and one of them stops resolving. This
 *    matched the old Total registration, which also set has_archive => false.
 */
function leaguelaw_register_lawyers_post_type() {
	$args = array(
		'labels'       => array(
			'name'               => __( 'Lawyers', 'kadence-child' ),
			'singular_name'      => __( 'Lawyer', 'kadence-child' ),
			'add_new_item'       => __( 'Add New Lawyer', 'kadence-child' ),
			'edit_item'          => __( 'Edit Lawyer', 'kadence-child' ),
			'new_item'           => __( 'New Lawyer', 'kadence-child' ),
			'view_item'          => __( 'View Lawyer', 'kadence-child' ),
			'search_items'       => __( 'Search Lawyers', 'kadence-child' ),
			'not_found'          => __( 'No lawyers found', 'kadence-child' ),
			'all_items'          => __( 'All Lawyers', 'kadence-child' ),
			'menu_name'          => __( 'Lawyers', 'kadence-child' ),
		),
		'public'       => true,
		'has_archive'  => false, // See note 2 above — do not change.
		'rewrite'      => array(
			'slug'       => 'lawyers', // See note 1 above — do not change.
			'with_front' => false,
		),
		'menu_icon'    => 'dashicons-groups',
		'menu_position' => 20,
		'supports'     => array( 'title', 'editor', 'thumbnail', 'excerpt', 'page-attributes', 'revisions' ),
		'show_in_rest' => true,
	);

	register_post_type( 'lawyers', $args );
}
add_action( 'init', 'leaguelaw_register_lawyers_post_type' );

/**
 * Register the `testimonials` post type.
 *
 * Also previously owned by the Total theme. The existing rows were never
 * deleted, so registering the post type under the same key brings all of them
 * back with their IDs, slugs and content intact — nothing needed re-importing.
 *
 * `has_archive` is false deliberately: testimonials are surfaced inside pages,
 * they are not a browsable section of the site.
 */
function leaguelaw_register_testimonials_post_type() {
	$args = array(
		'labels'        => array(
			'name'          => __( 'Testimonials', 'kadence-child' ),
			'singular_name' => __( 'Testimonial', 'kadence-child' ),
			'add_new_item'  => __( 'Add New Testimonial', 'kadence-child' ),
			'edit_item'     => __( 'Edit Testimonial', 'kadence-child' ),
			'all_items'     => __( 'All Testimonials', 'kadence-child' ),
			'menu_name'     => __( 'Testimonials', 'kadence-child' ),
		),
		'public'        => true,
		'has_archive'   => false,
		'rewrite'       => array(
			'slug'       => 'testimonials',
			'with_front' => false,
		),
		'menu_icon'     => 'dashicons-format-quote',
		'menu_position' => 21,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'page-attributes', 'revisions' ),
		'show_in_rest'  => true,
	);

	register_post_type( 'testimonials', $args );
}
add_action( 'init', 'leaguelaw_register_testimonials_post_type' );
