Your IP : 18.191.192.226


Current Path : /home/church/www/offwins.com/wp-content/plugins/adunblocker/admin/
Upload File :
Current File : /home/church/www/offwins.com/wp-content/plugins/adunblocker/admin/class-adunblocker-admin.php

<?php

/**
 * The admin-specific functionality of the plugin.
 *
 * @link       https://digitalapps.com
 * @since      1.0.0
 *
 * @package    AdUnblocker
 * @subpackage AdUnblocker/admin
 */

class AdUnblocker_Admin {

    /**
     * The ID of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $plugin_name    The ID of this plugin.
     */
    private $plugin_name;

    /**
     * The version of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $version    The current version of this plugin.
     */
    private $version;

    /**
     * The version of this plugin.
     *
     * @since    1.0.0
     * @access   private
     * @var      string    $version    The current version of this plugin.
     */
    private $error_log;
    private $license;

    /**
     * Initialize the class and set its properties.
     *
     * @since           1.0.0
     * @param           string      $plugin_name        The name of this plugin.
     * @param           string      $version            The version of this plugin.
     */
    public function __construct( $plugin_name, $version, $license ) {

        $this->plugin_name = $plugin_name;
        $this->version = $version;
        $this->options = $this->get_options();
        $this->license = $license;
        
    }

    /**
     * Register the stylesheets for the admin area.
     *
     * @since   1.0.0
     */
    public function enqueue_styles() {

        /**
         * This function is provided for demonstration purposes only.
         *
         * An instance of this class should be passed to the run() function
         * defined in AdUnblocker_Loader as all of the hooks are defined
         * in that particular class.
         *
         * The AdUnblocker_Loader will then create the relationship
         * between the defined hooks and the functions defined in this
         * class.
         */
        wp_enqueue_style( 'wp-color-picker' );
        wp_enqueue_style(
            'alpha-color-picker',
            plugin_dir_url( __FILE__ ) . 'css/alpha-color-picker.css', // Update to where you put the file.
            array( 'wp-color-picker' ) // You must include these here.
        );

        wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/adunblocker-admin.css', array(), $this->version, 'all' );
        wp_enqueue_style( $this->plugin_name . '-toggle-switch', plugin_dir_url( __FILE__ ) . 'css/toggle-switch.css', array(), $this->version, 'all' );
    }

    /**
     * Register the JavaScript for the admin area.
     *
     * @since   1.0.0
     */
    public function enqueue_scripts( $hook_suffix ) {
 
        /**
         * This function is provided for demonstration purposes only.
         *
         * An instance of this class should be passed to the run() function
         * defined in AdUnblocker_Loader as all of the hooks are defined
         * in that particular class.
         *
         * The AdUnblocker_Loader will then create the relationship
         * between the defined hooks and the functions defined in this
         * class.
         */
        
        if( $hook_suffix == 'toplevel_page_adunblocker-general-settings-page' ) {

            wp_enqueue_script( 'wp-color-picker' );
            
            wp_enqueue_script(
                'alpha-color-picker',
                plugin_dir_url( __FILE__ ) . 'js/alpha-color-picker.js', // Update to where you put the file.
                array( 'jquery', 'wp-color-picker' ), // You must include these here.
                null,
                true
            );

            wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/' . $this->plugin_name . '-admin.js', array( 'jquery', 'wp-color-picker', 'alpha-color-picker' ), $this->version, false );
            wp_enqueue_script( $this->plugin_name . "-license-settings", plugin_dir_url( __FILE__ ) . 'js/' . $this->plugin_name . '-admin-license.js', array( 'jquery' ), $this->version, false );

        }

        if( $hook_suffix == 'adunblocker_page_adunblocker-help' ) {

            wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/' . $this->plugin_name . '-admin-help.js', array( 'jquery' ), $this->version, false );

        }


    }

    public function localize_license_script() {

        $nonces = apply_filters( 'daau_nonces', array(
            'validate_license'      => wp_create_nonce( 'validate-license' )
        ) );

        $data = apply_filters( 'daau_data', array(
            'this_url'               => esc_html( addslashes( home_url() ) ),
            'nonces'                 => $nonces
        ) );

        // wp_localize_script( $handle, $name, $data );
        wp_localize_script(
            $this->plugin_name . "-license-settings",
            'daau_license_app',
            $data
        );

    }

    /**
     * Register the JavaScript for the public-facing side of the site.
     *
     * @since   1.0.0
     */
    public function localize_script() {

        $nonces = apply_filters( 'daau_nonces', array(
            'clear_log'             => wp_create_nonce( 'clear-log' ),
            'get_log'               => wp_create_nonce( 'get-log' ),
            'validate_license'      => wp_create_nonce( 'validate-license' )
        ) );

        $data = apply_filters( 'daau_data', array(
            'this_url'               => esc_html( addslashes( home_url() ) ),
            'nonces'                 => $nonces
        ) );

        // wp_localize_script( $handle, $name, $data );
        wp_localize_script(
            $this->plugin_name,
            'daau_app',
            $data
        );

    }

    /**
     * Adds a settings page link to a menu
     *
     * @link            https://codex.wordpress.org/Administration_Menus
     * @since           1.0.0
     * @return          void
     */
    public function add_menu() {

        // Top-level page
        // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
        // Submenu Page
        // add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
        // Add the menu item and page

        $page_title = 'AdUnblocker Settings';
        $menu_title = 'AdUnblocker';
        $capability = 'manage_options';
        $slug = $this->plugin_name . '-general-settings-page';
        $callback = array( $this, 'page_options' );
        $icon = 'dashicons-welcome-widgets-menus';
        $position = 100;

        add_menu_page( $page_title, $menu_title, $capability, $slug, $callback, $icon, $position );

        add_submenu_page(
            $slug,
            apply_filters( $this->plugin_name . '-settings-page-title', esc_html__( 'AdUnblocker Settings', 'adunblocker' ) ),
            apply_filters( $this->plugin_name . '-settings-menu-title', esc_html__( 'Settings', 'adunblocker' ) ),
            'manage_options',
            $slug,
            array( $this, 'page_options' )
        );

        add_submenu_page(
            $slug,
            apply_filters( $this->plugin_name . '-settings-page-title', esc_html__( 'AdUnblocker Help', 'adunblocker' ) ),
            apply_filters( $this->plugin_name . '-settings-menu-title', esc_html__( 'Help', 'adunblocker' ) ),
            'manage_options',
            $this->plugin_name . '-help',
            array( $this, 'page_help' )
        );

    } // add_menu()

    /**
     * Sets the class variable $options
     */
    private function get_options() {

        $options = array();
        $list = array();

        $options['general_options'] = get_option( $this->plugin_name . '-options' );
        $options['license_options'] = get_option( $this->plugin_name . '-license-options' );

        foreach( $options as $option ) {
            if( is_array( $option ) ) {
                $list = array_merge( $list, $option );
            }
        }

        return $list;

    } // get_options()

    /**
     * Creates the options page
     *
     * @since           1.0.0
     * @return          void
     */
    public function page_options() {
        
        include( plugin_dir_path( __FILE__ ) . 'partials/adunblocker-admin-page-settings.php' );

    } // page_options()

    /**
     * Creates the help page
     *
     * @since           1.0.0
     * @return          void
     */
    public function page_help() {

        include( plugin_dir_path( __FILE__ ) . 'partials/adunblocker-admin-page-help.php' );

    } // page_help()

    /**
     * Creates the options page
     *
     * @since           1.0.0
     * @return          void
     */
    public function page_sidebar() {

        include( plugin_dir_path( __FILE__ ) . 'partials/adunblocker-admin-page-sidebar.php' );

    } // page_options()

    /**
     * #1 Registers settings sections with WordPress
     */
    public function register_sections() {

        // add_settings_section( $id, $title, $callback, $menu_slug );

        add_settings_section(
            $this->plugin_name . '-section-license',
            apply_filters( $this->plugin_name . 'section-title', esc_html__( '', 'adunblocker' ) ),
            array( $this, 'section_options' ),
            $this->plugin_name . '-page-license-settings'
        );

        add_settings_section(
            $this->plugin_name . '-options',
            apply_filters( $this->plugin_name . 'section-title', esc_html__( '', 'adunblocker' ) ),
            array( $this, 'section_options' ),
            $this->plugin_name . '-general-settings-page'
        );

        add_settings_section(
            $this->plugin_name . '-content',
            apply_filters( $this->plugin_name . 'section-title', esc_html__( '', 'adunblocker' ) ),
            array( $this, 'section_content' ),
            $this->plugin_name . '-content-settings-page'
        );

        add_settings_section(
            $this->plugin_name . '-style',
            apply_filters( $this->plugin_name . 'section-title', esc_html__( '', 'adunblocker' ) ),
            array( $this, 'section_style' ),
            $this->plugin_name . '-style-settings-page'
        );

    } // register_sections()
    
    /**
     * #2 Registers settings fields with WordPress
     */
    public function register_fields() {

        // add_settings_field( $id, $title, $callback, $menu_slug, $section, $args );

        add_settings_field(
            $this->plugin_name . '-status',
            apply_filters( $this->plugin_name . 'label-status', esc_html__( 'Status:', $this->plugin_name ) ),
            array( $this, 'field_toggle' ),
            $this->plugin_name . '-general-settings-page',
            $this->plugin_name . '-options',
            array(
                'id'                => $this->plugin_name . '-status',
                'description'       => 'Toggle to activate',
                'value'             => 0
            )
        );

        add_settings_field(
            $this->plugin_name . '-scrollable-status',
            apply_filters( $this->plugin_name . 'label-status', esc_html__( 'Scrollable:', $this->plugin_name ) ),
            array( $this, 'field_toggle' ),
            $this->plugin_name . '-general-settings-page',
            $this->plugin_name . '-options',
            array(
                'id'                => $this->plugin_name . '-scrollable-status',
                'description'       => 'On: Page is scrollabe when popup is shown. Off: Page is not scrollable when popup is shown.',
                'value'             => 1
            )
        );

        if ( function_exists( 'pll_register_string' ) ) :
        
            add_settings_field(
                $this->plugin_name . '-polylang',
                apply_filters( $this->plugin_name . 'label-polylang', esc_html__( 'Polylang support:', $this->plugin_name ) ),
                array( $this, 'field_toggle' ),
                $this->plugin_name . '-general-settings-page',
                $this->plugin_name . '-options',
                array(
                    'id'                => $this->plugin_name . '-polylang',
                    'description'       => 'Toggle to enable Polylang support. You will be able to edit "String Translations". Content under String Translations will be shown to the user.',
                    'value'             => 0
                )
            );
            
        endif;

        add_settings_field(
            $this->plugin_name . '-type',
            apply_filters( $this->plugin_name . 'label-type', esc_html__( 'Type:', 'adunblocker' ) ),
            array( $this, 'field_select' ),
            $this->plugin_name . '-general-settings-page',
            $this->plugin_name . '-options',
            array(
                'description'       => 'Strict: popup cannot be dismissed, Temporary: popup disappears after timer runs out, Dismissible: popup can be dismissed with a click.',
                'id'                => $this->plugin_name . '-type',
                'selections'        => array(
                                            array(
                                                    'value'     => 'strict',
                                                    'label'     => 'Strict'
                                                ),
                                            array(
                                                    'value'     => 'temp',
                                                    'label'     => 'Temporary'
                                                ),
                                            array(
                                                    'value'     => 'dismissible',
                                                    'label'     => 'Dismissible'
                                                )
                                        )
            )
        );

        add_settings_field(
            $this->plugin_name . '-scope',
            apply_filters( $this->plugin_name . 'label-scope', esc_html__( 'Scope:', 'adunblocker' ) ),
            array( $this, 'field_select' ),
            $this->plugin_name . '-general-settings-page',
            $this->plugin_name . '-options',
            array(
                'description'       => 'Page: Show popup on each page load. Session: Show popup once.',
                'id'                => $this->plugin_name . '-scope',
                'selections'        => array(
                                            array(
                                                    'value'     => 'page',
                                                    'label'     => 'Page'
                                                ),
                                            array(
                                                    'value'     => 'session',
                                                    'label'     => 'Session'
                                                )
                                        )
            )
        );

        add_settings_field(
            $this->plugin_name . '-delay',
            apply_filters( $this->plugin_name . 'label-delay', esc_html__( 'Delay', 'adunblocker' ) ),
            array( $this, 'field_text' ),
            $this->plugin_name . '-general-settings-page',
            $this->plugin_name . '-options',
            array(
                'id'                => $this->plugin_name . '-delay',
                'description'       => 'Popup disappears after timer runs out in (ms)'
            )
        );

        if( array_key_exists( $this->plugin_name . '-title', $this->options ) ) {
            if( $this->options[$this->plugin_name . '-title'] ) {
                add_settings_field(
                    $this->plugin_name . '-title',
                    apply_filters( $this->plugin_name . 'label-title', esc_html__( 'Title', 'adunblocker' ) ),
                    array( $this, 'field_text' ),
                    $this->plugin_name . '-content-settings-page',
                    $this->plugin_name . '-content',
                    array(
                        'id'                => $this->plugin_name . '-title',
                        'description'       => 'This field will be deprecated in the future release! Please use Content area to create a title!',
                        'value'             => ''
                    )
                );
            }
        }

        add_settings_field(
            $this->plugin_name . '-content',
            apply_filters( $this->plugin_name . 'label-content', esc_html__( 'Content', 'adunblocker' ) ),
            array( $this, 'field_editor' ),
            $this->plugin_name . '-content-settings-page',
            $this->plugin_name . '-content',
            array(
                'id'                => $this->plugin_name . '-content',
                'description'       => 'The content for the popup.',
                'value'             => 'Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.'
            )
        );

        add_settings_field(
            $this->plugin_name . '-overlay-color',
            apply_filters( $this->plugin_name . '-label-overlay-color', esc_html__( 'Overlay', 'adunblocker' ) ),
            array( $this, 'alpha_color_picker' ),
            $this->plugin_name . '-style-settings-page',
            $this->plugin_name . '-style',
            array(
                'id'                => $this->plugin_name . '-overlay-color',
                'class'             => $this->plugin_name . '-alpha-color-picker',
            )
        );

        add_settings_field(
            $this->plugin_name . '-bg-color',
            apply_filters( $this->plugin_name . 'label-bg-color', esc_html__( 'Background', 'adunblocker' ) ),
            array( $this, 'color_picker' ),
            $this->plugin_name . '-style-settings-page',
            $this->plugin_name . '-style',
            array(
                'id'                => $this->plugin_name . '-bg-color',
                'class'             => $this->plugin_name . '-color-picker',
                'value'             => '#FFFFFF'
            )
        );

        // Deprecate
        if( array_key_exists( $this->plugin_name . '-title', $this->options ) ) {
            if( $this->options[$this->plugin_name . '-title'] ) {
                add_settings_field(
                    $this->plugin_name . '-title-color',
                    apply_filters( $this->plugin_name . 'label-title-color', esc_html__( 'Title', 'adunblocker' ) ),
                    array( $this, 'color_picker' ),
                    $this->plugin_name . '-style-settings-page',
                    $this->plugin_name . '-style',
                    array(
                        'id'                => $this->plugin_name . '-title-color',
                        'class'             => $this->plugin_name . '-color-picker'
                    )
                );
            }
        }

        add_settings_field(
            $this->plugin_name . '-text-color',
            apply_filters( $this->plugin_name . 'label-text-color', esc_html__( 'Text', 'adunblocker' ) ),
            array( $this, 'color_picker' ),
            $this->plugin_name . '-style-settings-page',
            $this->plugin_name . '-style',
            array(
                'id'                => $this->plugin_name . '-text-color',
                'class'             => $this->plugin_name . '-color-picker'
            )
        );

        add_settings_field(
            $this->plugin_name . '-file-name',
            '',
            array( $this, 'field_text' ),
            $this->plugin_name . '-settings',
            $this->plugin_name . '-options',
            array(
                'id'                => $this->plugin_name . '-file-name',
                'type'              => 'hidden',
                'class'             => 'hidden'
            )
        );

        add_settings_field(
            $this->plugin_name . '-license-email',
            apply_filters( $this->plugin_name . 'label-type', esc_html__( 'License email:', 'adunblocker' ) ),
            array( $this, 'field_text' ),
            $this->plugin_name . '-page-license-settings',
            $this->plugin_name . '-section-license',
            array(
                'id'                => $this->plugin_name . '-license-email',
                'name'              => $this->plugin_name . '-license-options[' . $this->plugin_name . '-license-email]',
                'value'             => ''
            )
        );

        add_settings_field(
            $this->plugin_name . '-license-key',
            apply_filters( $this->plugin_name . 'label-type', esc_html__( 'License key:', 'adunblocker' ) ),
            array( $this, 'field_text' ),
            $this->plugin_name . '-page-license-settings',
            $this->plugin_name . '-section-license',
            array(
                'id'                => $this->plugin_name . '-license-key',
                'name'              => $this->plugin_name . '-license-options[' . $this->plugin_name . '-license-key]',
                'value'             => ''
            )
        );

    } // register_fields()

    /**
     * Registers plugin settings
     *
     * @since           1.0.0
     * @return          void
     */
    public function register_settings() {

        // register_setting( $option_group, $option_name, $sanitize_callback );

        register_setting(
            $this->plugin_name . '-group-license-key',
            $this->plugin_name . '-license-options',
            array( $this , 'validate_license_options')
        );

        register_setting(
            $this->plugin_name . '-general-settings-group',
            $this->plugin_name . '-options',
            array( $this , 'validate_general_options')
        );

        register_setting(
            $this->plugin_name . '-content-settings-group',
            $this->plugin_name . '-options',
            array( $this , 'validate_general_options')
        );

        register_setting(
            $this->plugin_name . '-style-settings-group',
            $this->plugin_name . '-options',
            array( $this , 'validate_general_options')
        );

    } // register_settings()

    /**
     * Creates a checkbox field
     *
     * @param           array       $args       The arguments for the field
     * @return          string                  The HTML field
     */
    public function field_checkbox( $args ) {

        $defaults['class']          = '';
        $defaults['description']    = '';
        $defaults['label']          = '';
        $defaults['name']           = $this->plugin_name . '-options[' . $args['id'] . ']';
        $defaults['default_value']  = 'y';
        apply_filters( $this->plugin_name . '-field-checkbox-options-defaults', $defaults );
        $atts = wp_parse_args( $args, $defaults );

        if ( ! empty( $this->options[$atts['id']] ) ) {

            $atts['value'] = $this->options[$atts['id']];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-field-checkbox.php' );

    } // field_checkbox()

    /**
     * Creates a text field
     *
     * @param           array       $args       The arguments for the field
     * @return          string                  The HTML field
     */
    public function field_text( $args ) {

        $defaults['class']          = 'text widefat';
        $defaults['description']    = '';
        $defaults['label']          = '';
        $defaults['name']           = $this->plugin_name . '-options[' . $args['id'] . ']';
        $defaults['placeholder']    = '';
        $defaults['type']           = 'text';
        $defaults['value']          = '';

        apply_filters( $this->plugin_name . '-field-text-options-defaults', $defaults );
        $atts = wp_parse_args( $args, $defaults );

        if ( ! empty( $this->options[$atts['id']] ) ) {

            $atts['value'] = $this->options[$atts['id']];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-field-text.php' );

    } // field_text()

    public function alpha_color_picker( $args ) {

        $defaults['class']          = '';
        $defaults['description']    = '';
        $defaults['label']          = '';
        $defaults['name']           = $this->plugin_name . '-options[' . $args['id'] . ']';
        $defaults['placeholder']    = '';
        $defaults['type']           = 'text';
        $defaults['value']          = '';

        apply_filters( $this->plugin_name . '-alpha-color-picker-options-defaults', $defaults );
        
        $atts = wp_parse_args( $args, $defaults );

        if ( ! empty( $this->options[$atts['id']] ) ) {

            $atts['value'] = $this->options[$atts['id']];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-alpha-color-picker.php' );
         
    }

    /**
     * Creates a text field
     *
     * @param           array       $args       The arguments for the field
     * @return          string                  The HTML field
     */
    public function color_picker( $args ) {

        $defaults['class']          = 'text widefat';
        $defaults['description']    = '';
        $defaults['label']          = '';
        $defaults['name']           = $this->plugin_name . '-options[' . $args['id'] . ']';
        $defaults['placeholder']    = '';
        $defaults['type']           = 'text';
        $defaults['value']          = '';

        apply_filters( $this->plugin_name . '-color-picker-options-defaults', $defaults );
        $atts = wp_parse_args( $args, $defaults );

        if ( ! empty( $this->options[$atts['id']] ) ) {

            $atts['value'] = $this->options[$atts['id']];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-color-picker.php' );

    } // field_text()

    /**
     * Creates a select field
     *
     * Note: label is blank since its created in the Settings API
     *
     * @param           array       $args       The arguments for the field
     * @return          string                  The HTML field
     */
    public function field_select( $args ) {

        $defaults['aria']           = '';
        $defaults['blank']          = '';
        $defaults['class']          = 'widefat';
        $defaults['context']        = '';
        $defaults['description']    = '';
        $defaults['label']          = '';
        $defaults['name']           = $this->plugin_name . '-options[' . $args['id'] . ']';
        $defaults['selections']     = array();
        $defaults['value']          = '';

        apply_filters( $this->plugin_name . '-field-select-options-defaults', $defaults );
        $atts = wp_parse_args( $args, $defaults );

        if ( ! empty( $this->options[$atts['id']] ) ) {

            $atts['value'] = $this->options[$atts['id']];

        }

        if ( empty( $atts['aria'] ) && ! empty( $atts['description'] ) ) {

            $atts['aria'] = $atts['description'];

        } elseif ( empty( $atts['aria'] ) && ! empty( $atts['label'] ) ) {

            $atts['aria'] = $atts['label'];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-field-select.php' );

    } // field_select()

    /**
     * Creates an editor field
     *
     * NOTE: ID must only be lowercase letter, no spaces, dashes, or underscores.
     *
     * @param           array       $args       The arguments for the field
     * @return          string                  The HTML field
     */
    public function field_editor( $args ) {

        $defaults['description']    = '';
        $defaults['settings']       = array( 'textarea_name' => $this->plugin_name . '-options[' . $args['id'] . ']' );
        $defaults['value']          = '';
        apply_filters( $this->plugin_name . '-field-editor-options-defaults', $defaults );
        $atts = wp_parse_args( $args, $defaults );

        if ( ! empty( $this->options[$atts['id']] ) ) {

            $atts['value'] = $this->options[$atts['id']];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-field-editor.php' );

    } // field_editor()

    /**
     * Creates a select field
     *
     * Note: label is blank since its created in the Settings API
     *
     * @param           array       $args       The arguments for the field
     * @return          string                  The HTML field
     */
    public function field_toggle( $args ) {

        $args[ 'id' ] = isset( $args[ 'id' ] ) ? $args[ 'id' ] : '';

        $defaults['aria']           = '';
        $defaults['blank']          = '';
        $defaults['class']          = 'widefat';
        $defaults['context']        = '';
        $defaults['description']    = '';
        $defaults['label']          = '';
        $defaults['name']           = $this->plugin_name . '-options[' . $args[ 'id' ] . ']';
        $defaults['selections']     = array();
        $defaults['value']          = 0;

        apply_filters( $this->plugin_name . '-field-toggle-options-defaults', $defaults );
        
        $atts = wp_parse_args( $args, $defaults );

        if ( array_key_exists( $atts['id'], $this->options ) && $this->options[ $atts['id'] ] !== '' ) {

            $atts['value'] = $this->options[ $atts['id'] ];

        }

        if ( empty( $atts['aria'] ) && ! empty( $atts['description'] ) ) {

            $atts['aria'] = $atts['description'];

        } elseif ( empty( $atts['aria'] ) && ! empty( $atts['label'] ) ) {

            $atts['aria'] = $atts['label'];

        }

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-field-toggle.php' );

    }

    /**
     * Creates a settings section
     *
     * @since           1.0.0
     * @param           array       $params     Array of parameters for the section
     * @return          mixed                   The settings section
     */
    public function section_options( $params ) {

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-section-options.php' );

    } // section_options()

    /**
     * Creates a settings section
     *
     * @since           1.0.0
     * @param           array       $params     Array of parameters for the section
     * @return          mixed                   The settings section
     */
    public function section_content( $params ) {

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-section-content.php' );

    } // section_content()

    /**
     * Creates a settings section
     *
     * @since           1.0.0
     * @param           array       $params     Array of parameters for the section
     * @return          mixed                   The settings section
     */
    public function section_style( $params ) {

        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->plugin_name . '-admin-section-style.php' );

    } // section_content()

    private function sanitizer( $type, $data ) {

        if ( empty( $type ) ) { return; }
        // if ( empty( $data ) ) { return; }

        $return = '';

        $sanitizer = new AdUnblocker_Sanitize( $this->plugin_name );
        $sanitizer->set_data( $data );
        $sanitizer->set_type( $type );
        $return = $sanitizer->clean();

        unset( $sanitizer );

        return $return;

    } // sanitizer()

    /**
     * Returns an array of options names, fields types, and default values
     *
     * @return          array             An array of options
     */
    public function get_general_options_list() {

        $options = array();
        $options[] = array( $this->plugin_name . '-status', 'checkbox' );
        $options[] = array( $this->plugin_name . '-scrollable-status', 'checkbox' );
        $options[] = array( $this->plugin_name . '-polylang', 'checkbox' );
        $options[] = array( $this->plugin_name . '-type', 'text' );
        $options[] = array( $this->plugin_name . '-delay', 'text' );
        
        // Deprecate
        if( $this->options[$this->plugin_name . '-title'] ) {
            $options[] = array( $this->plugin_name . '-title', 'text' );
            $options[] = array( $this->plugin_name . '-title-color', 'color' );
        }

        $options[] = array( $this->plugin_name . '-content', 'editor' );
        $options[] = array( $this->plugin_name . '-overlay-color', 'text' );
        $options[] = array( $this->plugin_name . '-bg-color', 'color' );
        $options[] = array( $this->plugin_name . '-text-color', 'color' );
        $options[] = array( $this->plugin_name . '-file-name', 'file' );
        $options[] = array( $this->plugin_name . '-scope', 'text' );

        return $options;

    } // get_options_list()

    public function validate_general_options( $input ) {

        $db_options = $this->get_options();
        $options = $this->get_general_options_list();
        return $this->validate_options( $input, $options, $db_options );

    }

    /**
     * Returns an array of options names, fields types, and default values
     *
     * @return          array             An array of options
     */
    public function get_license_options_list() {

        $options = array();

        $options[] = array( $this->plugin_name . '-license-key', 'text', '' );
        $options[] = array( $this->plugin_name . '-license-email', 'text', '' );

        return $options;

    }

    public function validate_license_options( $input ) {

        $db_options     = $this->get_options();
        $options        = $this->get_license_options_list();
        $valid          = $this->validate_options( $input, $options, $db_options );

        return $valid;

    }

    public function validate_license_nonotice() {

        $this->validate_license( $show_notice = false );

    }

    /**
     * Validates saved options
     *
     * @since           1.0.0
     * @param           array           $input          array of submitted plugin options
     * @return          array                           array of validated plugin options
     */
     public function validate_options( $input, $options, $db_options ) {

         if ( null == $input ) {
             add_settings_error(
                 'requiredTextFieldEmpty',
                 'empty',
                 __('Cannot be empty'),
                 'error'
             );
         }

         $valid  = array();

         foreach ( $options as $option ) {

             $name   = $option[0]; // adunblocker-status
             $type   = $option[1]; // text
             $value  = $option[2];

             if ( array_key_exists( $name, $input ) ) {
                 $valid[$name] = $this->sanitizer( $type, $input[$name] );
             } else {
                 $valid[$name] = $db_options[$name];
             }

         }

         return $valid;

     } // validate_options()

    /**
     * @param mixed $return Value to be returned as response.
     *
     * @return null
     */
    function end_ajax( $return = false ) {
        $return = apply_filters( 'daau_before_response', $return );

        if ( defined( 'DOING_daau_TESTS' ) || $this->doing_cli_migration ) {
            // This function should signal the end of the PHP process, but for CLI it carries on so we need to reset our own usage
            // of the daau_before_response filter before another respond_to_* function adds it again.
            remove_filter( 'daau_before_response', array( $this, 'scramble' ) );

            return ( false === $return ) ? null : $return;
        }

        echo ( false === $return ) ? '' : $return;
        exit;
    }

    function check_ajax_referer( $action ) {

        $result = check_ajax_referer( $action, 'nonce', false );

        if ( false === $result ) {
            $return = array( 'daau_error' => 1, 'body' => sprintf( __( 'Invalid nonce for: %s', 'adunblocker' ), $action ) );
            $this->end_ajax( json_encode( $return ) );
        }

        $cap = ( is_multisite() ) ? 'manage_network_options' : 'export';
        $cap = apply_filters( 'daau_ajax_cap', $cap );

        if ( ! current_user_can( $cap ) ) {
            $return = array( 'daau_error' => 1, 'body' => sprintf( __( 'Access denied for: %s', 'adunblocker' ), $action ) );
            $this->end_ajax( json_encode( $return ) );
        }
    }

    /**
     * Loads the error log into the error log class property.
     */
    function load_error_log() {
        if ( ! is_null( $this->error_log ) ) {
            return;
        }

        $this->error_log = get_site_option( 'daau_error_log' );

        /*
         * The error log was previously stored and retrieved using get_option and update_option respectively.
         * Here we update the subsite option to a network wide option if applicable.
         */
        if ( false === $this->error_log && is_multisite() && is_network_admin() ) {
            $this->error_log = get_option( $this->plugin_name . '_error_log' );
            if ( false !== $this->error_log ) {
                update_site_option( $this->plugin_name . '_error_log', $this->error_log );
                delete_option( $this->plugin_name . '_error_log' );
            }
        }
    }

    function ajax_verify_token() {

        $this->check_ajax_referer( 'validate-license' );

        $return = '';

        $return = $this->license->verify_token();

        $result = $this->end_ajax( json_encode( $return ) );
        
    }

    function ajax_validate_license() {

        $this->check_ajax_referer( 'validate-license' );

        $email = '';
        $key = '';
        $return = '';

        $email = sanitize_email( $_POST['license']['email'] );
        $key =  sanitize_text_field( $_POST['license']['key'] );

        if( empty( $email ) || empty( $key ) ) {

            $return = array( 'status' => 'error', 'message' => 'Invalid License Details' );

        } else {
            
            update_option( 
                $this->plugin_name . '-license-options', 
                array( 
                    $this->plugin_name . '-license-email'   => $email, 
                    $this->plugin_name . '-license-key'     => $key 
                ) 
            );

            $return = $this->license->get_token();

        }

        $result = $this->end_ajax( json_encode( $return ) );
    
    }
    
    function ajax_get_log() {

        $this->check_ajax_referer( 'get-log' );
        ob_start();
        $this->output_diagnostic_info();
        // $this->output_log_file();
        $return = ob_get_clean();
        $result = $this->end_ajax( $return );

    }

    function output_log_file() {
        $this->load_error_log();
        if ( isset( $this->error_log ) ) {
            echo $this->error_log;
        }
    }

    /**
     * Outputs diagnostic info for debugging.
     *
     * Outputs useful diagnostic info text at the Diagnostic Info & Error Log
     * section under the Help tab so the information can be viewed or
     * downloaded and shared for debugging.
     *
     * If you would like to add additional diagnostic information use the
     * `daau_diagnostic_info` action hook (see {@link https://developer.wordpress.org/reference/functions/add_action/}).
     *
     * <code>
     * add_action( 'daau_diagnostic_info', 'my_diagnostic_info' ) {
     *     echo "Additional Diagnostic Info: \r\n";
     *     echo "...\r\n";
     * }
     * </code>
     *
     * @return void
     */
    function output_diagnostic_info() {
        global $wpdb;
        $table_prefix = $wpdb->base_prefix;

        echo 'site_url(): ';
        echo esc_html( site_url() );
        echo "\r\n";

        echo 'home_url(): ';
        echo esc_html( home_url() );
        echo "\r\n";

        echo 'Database Name: ';
        echo esc_html( $wpdb->dbname );
        echo "\r\n";

        echo 'Table Prefix: ';
        echo esc_html( $table_prefix );
        echo "\r\n";

        echo 'WordPress: ';
        echo bloginfo( 'version' );
        if ( is_multisite() ) {
            $multisite_type = defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ? 'Sub-domain' : 'Sub-directory';
            echo ' Multisite (' . $multisite_type . ')';
            echo "\r\n";

            if ( defined( 'DOMAIN_CURRENT_SITE' ) ) {
                echo 'Domain Current Site: ';
                echo DOMAIN_CURRENT_SITE;
                echo "\r\n";
            }

            if ( defined( 'PATH_CURRENT_SITE' ) ) {
                echo 'Path Current Site: ';
                echo PATH_CURRENT_SITE;
                echo "\r\n";
            }

            if ( defined( 'SITE_ID_CURRENT_SITE' ) ) {
                echo 'Site ID Current Site: ';
                echo SITE_ID_CURRENT_SITE;
                echo "\r\n";
            }

            if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
                echo 'Blog ID Current Site: ';
                echo BLOG_ID_CURRENT_SITE;
            }
        }
        echo "\r\n";

        echo 'Web Server: ';
        echo esc_html( ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '' );
        echo "\r\n";

        echo 'PHP: ';
        if ( function_exists( 'phpversion' ) ) {
            echo esc_html( phpversion() );
        }
        echo "\r\n";

        echo 'MySQL: ';
        echo esc_html( empty( $wpdb->use_mysqli ) ? mysql_get_server_info() : mysqli_get_server_info( $wpdb->dbh ) );
        echo "\r\n";

        echo 'ext/mysqli: ';
        echo empty( $wpdb->use_mysqli ) ? 'no' : 'yes';
        echo "\r\n";

        echo 'WP Memory Limit: ';
        echo esc_html( WP_MEMORY_LIMIT );
        echo "\r\n";

        echo 'Blocked External HTTP Requests: ';
        if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) {
            echo 'None';
        } else {
            $accessible_hosts = ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) ? WP_ACCESSIBLE_HOSTS : '';

            if ( empty( $accessible_hosts ) ) {
                echo 'ALL';
            } else {
                echo 'Partially (Accessible Hosts: ' . esc_html( $accessible_hosts ) . ')';
            }
        }
        echo "\r\n";

        echo 'WP Locale: ';
        echo esc_html( get_locale() );
        echo "\r\n";

        echo 'DB Charset: ';
        echo esc_html( DB_CHARSET );
        echo "\r\n";

        if ( function_exists( 'ini_get' ) && $suhosin_limit = ini_get( 'suhosin.post.max_value_length' ) ) {
            echo 'Suhosin Post Max Value Length: ';
            echo esc_html( is_numeric( $suhosin_limit ) ? size_format( $suhosin_limit ) : $suhosin_limit );
            echo "\r\n";
        }

        if ( function_exists( 'ini_get' ) && $suhosin_limit = ini_get( 'suhosin.request.max_value_length' ) ) {
            echo 'Suhosin Request Max Value Length: ';
            echo esc_html( is_numeric( $suhosin_limit ) ? size_format( $suhosin_limit ) : $suhosin_limit );
            echo "\r\n";
        }

        echo 'Debug Mode: ';
        echo esc_html( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? 'Yes' : 'No' );
        echo "\r\n";

        echo 'WP Max Upload Size: ';
        echo esc_html( size_format( wp_max_upload_size() ) );
        echo "\r\n";

        echo 'PHP Post Max Size: ';
        echo esc_html( size_format( $this->get_post_max_size() ) );
        echo "\r\n";

        echo 'PHP Time Limit: ';
        if ( function_exists( 'ini_get' ) ) {
            echo esc_html( ini_get( 'max_execution_time' ) );
        }
        echo "\r\n";

        echo 'PHP Error Log: ';
        if ( function_exists( 'ini_get' ) ) {
            echo esc_html( ini_get( 'error_log' ) );
        }
        echo "\r\n";

        echo 'fsockopen: ';
        if ( function_exists( 'fsockopen' ) ) {
            echo 'Enabled';
        } else {
            echo 'Disabled';
        }
        echo "\r\n";

        echo 'OpenSSL: ';
        if ( $this->open_ssl_enabled() ) {
            echo esc_html( OPENSSL_VERSION_TEXT );
        } else {
            echo 'Disabled';
        }
        echo "\r\n";

        echo 'cURL: ';
        if ( function_exists( 'curl_init' ) ) {
            echo 'Enabled';
        } else {
            echo 'Disabled';
        }
        echo "\r\n";


        do_action( 'daau_diagnostic_info' );
        if ( has_action( 'daau_diagnostic_info' ) ) {
            echo "\r\n";
        }

        $theme_info = wp_get_theme();
        echo "Active Theme Name: " . esc_html( $theme_info->Name ) . "\r\n";
        echo "Active Theme Folder: " . esc_html( basename( $theme_info->get_stylesheet_directory() ) ) . "\r\n";
        if ( $theme_info->get( 'Template' ) ) {
            echo "Parent Theme Folder: " . esc_html( $theme_info->get( 'Template' ) ) . "\r\n";
        }
        if ( ! file_exists( $theme_info->get_stylesheet_directory() ) ) {
            echo "WARNING: Active Theme Folder Not Found\r\n";
        }

        echo "\r\n";

        echo "Active Plugins:\r\n";

        $active_plugins = (array) get_option( 'active_plugins', array() );

        if ( is_multisite() ) {
            $network_active_plugins = wp_get_active_network_plugins();
            $active_plugins         = array_map( array( $this, 'remove_wp_plugin_dir' ), $network_active_plugins );
        }

        foreach ( $active_plugins as $plugin ) {
            $suffix = ( isset( $blacklist[ $plugin ] ) ) ? '*' : '';
            $this->print_plugin_details( WP_PLUGIN_DIR . '/' . $plugin, $suffix );
        }

        $mu_plugins = wp_get_mu_plugins();
        if ( $mu_plugins ) {
            echo "\r\n";

            echo "Must-use Plugins:\r\n";

            foreach ( $mu_plugins as $mu_plugin ) {
                $this->print_plugin_details( $mu_plugin );
            }

            echo "\r\n";
        }
    }

    function open_ssl_enabled() {
        if ( defined( 'OPENSSL_VERSION_TEXT' ) ) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Returns the php ini value for post_max_size in bytes
     *
     * @return int
     */
    function get_post_max_size() {
        $bytes = max( wp_convert_hr_to_bytes( trim( ini_get( 'post_max_size' ) ) ), wp_convert_hr_to_bytes( trim( ini_get( 'hhvm.server.max_post_size' ) ) ) );

        return $bytes;
    }

    function print_plugin_details( $plugin_path, $suffix = '' ) {
        $plugin_data = get_plugin_data( $plugin_path );
        if ( empty( $plugin_data['Name'] ) ) {
            return;
        }

        printf( "%s%s (v%s) by %s\r\n", $plugin_data['Name'], $suffix, $plugin_data['Version'], $plugin_data['AuthorName'] );
    }

    /**
     * Check for daabd-download-log and related nonce
     * if found begin diagnostic logging
     *
     * @return void
     */
    function http_prepare_download_log() {
        if ( isset( $_GET['daabd-download-log'] ) && wp_verify_nonce( $_GET['nonce'], 'daabd-download-log' ) ) {
            ob_start();
            $this->output_diagnostic_info();
            $this->output_log_file();
            $log      = ob_get_clean();
            $url      = $this->parse_url( home_url() );
            $host     = sanitize_file_name( $url['host'] );
            $filename = sprintf( '%s-diagnostic-log-%s.txt', $host, date( 'YmdHis' ) );
            header( 'Content-Description: File Transfer' );
            header( 'Content-Type: application/octet-stream' );
            header( 'Content-Length: ' . strlen( $log ) );
            header( 'Content-Disposition: attachment; filename=' . $filename );
            echo $log;
            exit;
        }
    }

    /**
     * Parses a url into its components. Compatible with PHP < 5.4.7.
     *
     * @param $url string The url to parse.
     *
     * @return array|false The parsed components or false on error.
     */
    function parse_url( $url ) {
        $url = trim( $url );
        if ( 0 === strpos( $url, '//' ) ) {
            $url       = 'http:' . $url;
            $no_scheme = true;
        } else {
            $no_scheme = false;
        }

        $parts = parse_url( $url );
        if ( $no_scheme ) {
            unset( $parts['scheme'] );
        }

        return $parts;
    }

    /**
     * Displays admin notices
     *
     * @return  string          Admin notices
     */
    public function display_admin_notices() {
        settings_errors();
    } // display_admin_notices()

    public function get_current_tab() {
        $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general_settings';
        
        if ( ! $this->license->isValid() ) {
            $active_tab = 'license_settings';
        }

        return $active_tab;
    }

    /**
     * Polylang
     */
    function content_pll_register_string() {

        if ( function_exists( 'pll_register_string' ) ) :

            $option = get_option( $this->plugin_name . '-options' );
            
            // Deprecate
            if( ! empty( $this->options[$this->plugin_name . '-title'] ) ) {
                $title = $option[$this->plugin_name . '-title'];
            }

            $content = wpautop( $option[$this->plugin_name . '-content'] );

            // Deprecate
            if( ! empty( $this->options[$this->plugin_name . '-title'] ) ) {
                pll_register_string( 'AdUnblocker Title', $title, 'adunblocker', true );
            }

            pll_register_string( 'AdUnblocker Content', $content, 'adunblocker', true );

        endif;

    }

    /**
     * Adds extra info for the plugin update message
     *
     * @since           1.1.1
     * @return          void
     */
    function update_message_cb( $plugin_data, $r ) {
        if( ! $this->license->isValid() ) {
            echo ' <b>Valid License Required for Updates.</b>';
        }
    }
}