<?php
if (!function_exists('is_plugin_active')) {
    include_once(ABSPATH.'wp-admin/includes/plugin.php');
}
/**
 * Checks if a WordPress plugin is active.
 *
 * @param string $plugin
 *
 * @return bool
 */
if (!function_exists('pac_drh_check_is_divi_theme')):
    function pac_drh_check_is_divi_theme()
    {
        $theme_info = wp_get_theme();
        $active_theme = is_child_theme() ? $theme_info->parent()->get('Name') : $theme_info->get('Name');
        if (!in_array(strtolower($active_theme), ['divi', 'extra'])) {
            deactivate_plugins(PAC_DRH_PLUGIN_BASENAME);
            wp_die(sprintf('<p>The Divi Responsive Helper plugin only works the Divi Theme or Extra Theme. Your current active theme is <b>%s</b>. The plugin is deactivated, and you may return to your WordPress dashboard.</p><a href="%s">Go Back</a>', esc_html($active_theme), esc_url(admin_url('index.php'))));
        }
    }

    add_action('after_switch_theme', 'pac_drh_check_is_divi_theme');
    register_activation_hook(PAC_DRH_PLUGIN_FILE, 'pac_drh_check_is_divi_theme');
endif;
/**
 * Adds custom action links to the plugin on the Plugins page.
 *
 * @param array $actions
 *
 * @return array
 */
if (!function_exists('pac_drh_plugin_action_links')):
    function pac_drh_plugin_action_links($actions)
    {
        $slug = is_plugin_active('divi-ghoster/divi-ghoster.php') ? 'et_'.get_option('agsdg_settings').'_options' : pac_drh_get_theme_option_name().'_options';
        $url = admin_url("admin.php?page=$slug#wrap-drh");
        $custom_actions = sprintf('<a href="%s">'.__('Settings', 'divi-responsive-helper').' </a>.', esc_url($url));
        array_unshift($actions, $custom_actions);

        return $actions;
    }

    add_filter('plugin_action_links_'.PAC_DRH_PLUGIN_BASENAME, 'pac_drh_plugin_action_links');
endif;
/**
 * Loads the translation files for the Divi Responsive Helper plugin.
 */
if (!function_exists('pac_drh_plugin_translation_ready')):
    function pac_drh_plugin_translation_ready()
    {
        load_plugin_textdomain('divi-responsive-helper', false, wp_basename(PAC_DRH_PLUGIN_DIR).'/languages/');
    }

    add_filter('plugins_loaded', 'pac_drh_plugin_translation_ready');
endif;
/**
 * Adds custom media queries to the list of media queries used by the Divi Builder.
 *
 * @param array $media_queries
 *
 * @return array
 */
if (!function_exists('pac_drh_maybe_custom_media_queries')):
    function pac_drh_maybe_custom_media_queries($media_queries)
    {
        $media_queries['pac_drh_min_768_max_980'] = '@media only screen and (min-width: 768px) and (max-width: 980px)';
        $media_queries['pac_drh_max_767'] = '@media only screen and (max-width: 767px)';
        $media_queries['pac_drh_max_980'] = '@media only screen and (max-width: 980px)';

        return $media_queries;
    }

    add_filter('et_builder_media_queries', 'pac_drh_maybe_custom_media_queries');
endif;
