<?php

if (!defined('ABSPATH')) {
    exit;
}

/*----------------------------------------
カスタム投稿タイプ：メールフォーム
----------------------------------------*/
function immf_register_contact_form_post_type() {

    $labels = [
        'name'               => __(
            'Mail Forms',
            'im-mail-form'
        ),
        'singular_name'      => __(
            'Mail Form',
            'im-mail-form'
        ),
        'menu_name'          => __(
            'IM Mail Form',
            'im-mail-form'
        ),
        'add_new'            => __(
            'Add New',
            'im-mail-form'
        ),
        'add_new_item'       => __(
            'Add New Mail Form',
            'im-mail-form'
        ),
        'edit_item'          => __(
            'Edit Mail Form',
            'im-mail-form'
        ),
        'new_item'           => __(
            'New Mail Form',
            'im-mail-form'
        ),
        'search_items'       => __(
            'Search Mail Forms',
            'im-mail-form'
        ),
        'not_found'          => __(
            'No mail forms found.',
            'im-mail-form'
        ),
        'not_found_in_trash' => __(
            'No mail forms found in Trash.',
            'im-mail-form'
        ),
        'all_items'          => __(
            'All Mail Forms',
            'im-mail-form'
        ),

        'publish_item'       => __(
            'Save',
            'im-mail-form'
        ),
        'update_item'        => __(
            'Save',
            'im-mail-form'
        ),
    ];

    register_post_type('im_mail_form', [
        'labels'              => $labels,
        'public'              => false,
        'publicly_queryable'  => false,
        'exclude_from_search' => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_admin_bar'   => false,
        'show_in_nav_menus'   => false,
        'show_in_rest'        => false,
        'menu_position'       => 27,
        'menu_icon'           => 'dashicons-email-alt',
        'supports'            => ['title'],
        'capabilities'        => [
            'edit_post'              => 'manage_options',
            'read_post'              => 'manage_options',
            'delete_post'            => 'manage_options',
            'edit_posts'             => 'manage_options',
            'edit_others_posts'      => 'manage_options',
            'publish_posts'          => 'manage_options',
            'read_private_posts'     => 'manage_options',
            'delete_posts'           => 'manage_options',
            'delete_private_posts'   => 'manage_options',
            'delete_published_posts' => 'manage_options',
            'delete_others_posts'    => 'manage_options',
            'edit_private_posts'     => 'manage_options',
            'edit_published_posts'   => 'manage_options',
            'create_posts'           => 'manage_options',
        ],
        'has_archive'         => false,
        'rewrite'             => false,
        'query_var'           => false,
        'can_export'          => true,
        'delete_with_user'    => false,
    ]);
}

add_action(
    'init',
    'immf_register_contact_form_post_type'
);