_save_settings' */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } define( 'ET_DASHBOARD_DIR', trailingslashit( dirname(__FILE__) ) ); define( 'ET_DASHBOARD_PLUGIN_URI', plugins_url( '', __FILE__ ) ); class ET_Dashboard { var $class_version = '1.2'; var $protocol; var $plugin_name; /** * @var ET_Core_Data_Utils */ protected static $_; function __construct( $args ) { //define filterable variables $this->_options_pagename = isset( $args['et_dashboard_options_pagename'] ) ? $args['et_dashboard_options_pagename'] : 'et_dashboard'; $this->plugin_class_name = isset( $args['et_dashboard_plugin_class_name'] ) ? $args['et_dashboard_plugin_class_name'] : ''; $this->save_button_text = isset( $args['et_dashboard_save_button_text'] ) ? $args['et_dashboard_save_button_text'] : esc_html__( 'Save Changes', 'et_dashboard' ); $this->plugin_name = isset( $args['et_dashboard_plugin_name'] ) ? $args['et_dashboard_plugin_name'] : 'et_dashboard'; $this->options_path = isset( $args['et_dashboard_options_path'] ) ? $args['et_dashboard_options_path'] : ET_DASHBOARD_DIR . 'includes/options.php'; $this->top_level_page = isset( $args['et_dashboard_options_page'] ) ? $args['et_dashboard_options_page'] : 'tools'; $this->protocol = is_ssl() ? 'https' : 'http'; $this->dashboard_options = $this->get_options_array(); //include options at the init hook, to make sure localization applied correctly $this->include_options(); add_action( 'plugins_loaded', array( $this, 'add_class_localization' ) ); add_action( 'wp_ajax_et_dashboard_generate_warning', array( $this, 'generate_modal_warning' ) ); add_action( 'wp_ajax_et_dashboard_execute_live_search', array( $this, 'execute_live_search' ) ); add_action( 'admin_init', array( $this, 'set_post_types' ), 99 ); add_action( 'admin_enqueue_scripts', array( $this, 'dashboard_scripts' ) ); add_action( 'admin_init', array( $this, 'process_settings_export' ) ); add_action( 'admin_init', array( $this, 'process_settings_import' ) ); self::$_ = ET_Core_Data_Utils::instance(); } /** * Adds class localization * Domain: et_dashboard * * @return void */ function add_class_localization() { load_plugin_textdomain( 'et_dashboard', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } function get_options_array() { return get_option( 'et_' . $this->plugin_name . '_options' ) ? get_option( 'et_' . $this->plugin_name . '_options' ) : array(); } public static function load_fonts_class() { if ( ! class_exists( 'ET_Dashboard_Fonts' ) ) { require_once( ET_DASHBOARD_DIR . 'includes/google_fonts.php' ); } $fonts_class = new ET_Dashboard_Fonts(); return $fonts_class; } function include_options() { require_once( $this->options_path ); $this->dashboard_sections = $all_sections; $this->assigned_options = $assigned_options; $this->provider_names = $email_providers; } function update_option( $update_array ) { if ( ! current_user_can( 'manage_options' ) ) { die( -1 ); } //we need to update current version of options, not cached version $dashboard_options = $this->get_options_array(); $updated_options = array_merge( $dashboard_options, $update_array ); update_option( 'et_' . $this->plugin_name . '_options', $updated_options ); } /** * Removes option from the database based on the $option_key * @return void */ function remove_option( $option_key ) { //we need to remove options from the current version of options, not cached version $dashboard_options = $this->get_options_array(); if ( isset( $dashboard_options[$option_key] ) ) { unset( $dashboard_options[$option_key] ); update_option( 'et_' . $this->plugin_name . '_options', $dashboard_options ); } } function dashboard_scripts( $hook ) { if ( "{$this->top_level_page}_{$this->_options_pagename}" !== $hook ) { return; } $DEBUG = defined( 'ET_DEBUG' ) && ET_DEBUG; $core_scripts = ET_CORE_URL . '/admin/js'; $bundle_url = ET_DASHBOARD_PLUGIN_URI . '/js/bloom-dashboard.bundle.min.js'; if ( $DEBUG ) { wp_enqueue_script( 'react', 'https://cdn.jsdelivr.net/npm/react@16.2/umd/react.development.js', array(), '16.2', true ); wp_enqueue_script( 'react-dom', 'https://cdn.jsdelivr.net/npm/react-dom@16.2/umd/react-dom.development.js', array( 'react' ), '16.2', true ); add_filter( 'script_loader_tag', 'et_core_add_crossorigin_attribute', 10, 3 ); } else { wp_enqueue_script( 'react', "{$core_scripts}/react.production.min.js", array(), '16.2', true ); wp_enqueue_script( 'react-dom', "{$core_scripts}/react-dom.production.min.js", array( 'react' ), '16.2', true ); } if ( $DEBUG ) { $site_url = wp_parse_url( get_site_url() ); $hot_bundle_url = "{$site_url['scheme']}://{$site_url['host']}:31495/bloom-dashboard.bundle.min.js"; wp_enqueue_script( 'et-bloom-dashboard-bundle', $hot_bundle_url, array( 'jquery', 'react', 'react-dom' ), $this->class_version, true ); // Add the bundle as fallback in case webpack-dev-server is not running wp_add_inline_script( 'et-bloom-dashboard-bundle', sprintf( 'window.et_bloom_custom_field_manager_init || document.write(\'