<?php

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

/*----------------------------------------
メールフォーム：管理画面タブ表示
----------------------------------------*/
function immf_render_admin_tabs($post) {

    if (
        !$post instanceof WP_Post ||
        $post->post_type !== 'im_mail_form'
    ) {
        return;
    }

    ?>

    <nav
        class="im-mail-form-tabs"
        aria-label="<?php esc_attr_e(
            'Form settings',
            'im-mail-form'
        ); ?>"
        data-contact-form-tabs
    >

        <button
            type="button"
            class="im-mail-form-tabs__button"
            data-contact-form-tab="fields"
        >
            <?php esc_html_e(
                'Form Settings',
                'im-mail-form'
            ); ?>
        </button>

        <button
            type="button"
            class="im-mail-form-tabs__button"
            data-contact-form-tab="mail"
        >
            <?php esc_html_e(
                'Mail Settings',
                'im-mail-form'
            ); ?>
        </button>

        <button
            type="button"
            class="im-mail-form-tabs__button"
            data-contact-form-tab="complete"
        >
            <?php esc_html_e(
                'Completion Screen',
                'im-mail-form'
            ); ?>
        </button>

    </nav>

    <?php
}

add_action(
    'edit_form_after_title',
    'immf_render_admin_tabs'
);

/*----------------------------------------
WPFormsの編集画面向け案内を非表示
----------------------------------------*/
function immf_remove_wpforms_edit_post_notice() {

    $screen = get_current_screen();

    if (
        !$screen instanceof WP_Screen ||
        $screen->post_type !== 'im_mail_form'
    ) {
        return;
    }

    global $wp_filter;

    if (
        empty(
            $wp_filter['edit_form_after_title']
                ->callbacks
        )
    ) {
        return;
    }

    foreach (
        $wp_filter['edit_form_after_title']
            ->callbacks
        as $priority => $callbacks
    ) {

        foreach ($callbacks as $callback) {

            $function = $callback['function'];

            if (
                !is_array($function) ||
                !isset(
                    $function[0],
                    $function[1]
                ) ||
                !is_object($function[0]) ||
                $function[1] !==
                    'classic_editor_notice' ||
                !is_a(
                    $function[0],
                    'WPForms\Admin\Education\Admin\EditPost'
                )
            ) {
                continue;
            }

            remove_action(
                'edit_form_after_title',
                $function,
                $priority
            );
        }
    }
}

add_action(
    'admin_head',
    'immf_remove_wpforms_edit_post_notice',
    1
);