<?php

if (!class_exists('acf_third_party')) {
    class acf_third_party
    {
        function __construct()
        {
            if (class_exists('Tabify_Edit_Screen')) {
                add_filter('tabify_posttypes', array($this, 'tabify_posttypes'));
                add_action('tabify_add_meta_boxes', array($this, 'tabify_add_meta_boxes'));
            }
            if (class_exists('Post_Type_Switcher')) {
                add_filter('pts_allowed_pages', array($this, 'pts_allowed_pages'));
            }
            if (function_exists('espresso_version')) {
                add_filter('acf/get_post_types', array($this, 'ee_get_post_types'), 10, 2);
            }
            if (class_exists('Dark_Mode')) {
                add_action('doing_dark_mode', array($this, 'doing_dark_mode'));
            }
        }
        function ee_get_post_types($post_types, $args)
        {
            if (!empty($args['show_ui'])) {
                $ee_post_types = get_post_types(array('show_ee_ui' => 1));
                $ee_post_types = array_keys($ee_post_types);
                $post_types = array_merge($post_types, $ee_post_types);
                $post_types = array_unique($post_types);
            }
            return $post_types;
        }
        function tabify_posttypes($posttypes)
        {
            unset($posttypes['acf-field-group']);
            unset($posttypes['acf-field']);
            return $posttypes;
        }
        function tabify_add_meta_boxes($post_type)
        {
            $field_groups = acf_get_field_groups();
            if (!empty($field_groups)) {
                foreach ($field_groups as $field_group) {
                    $id = "acf-{$field_group['key']}";
                    $title = 'ACF: ' . $field_group['title'];
                    add_meta_box($id, acf_esc_html($title), '__return_true', $post_type);
                }
            }
        }
        function pts_allowed_pages($pages)
        {
            $post_type = '';
            if (!empty($_GET['post_type'])) {
                $post_type = $_GET['post_type'];
            } elseif (!empty($_GET['post'])) {
                $post_type = get_post_type($_GET['post']);
            }
            if ($post_type == 'acf-field-group') {
                $pages = array();
            }
            return $pages;
        }
        function doing_dark_mode()
        {
            wp_enqueue_style('acf-dark', acf_get_url('assets/css/acf-dark.css'), array(), ACF_VERSION);
        }
    }
    new acf_third_party();
}