*/ class Darkify { /** * Plugin version * * @since 1.0.0 * @access protected * @var string */ protected $version; /** * Plugin slug * * @since 1.0.0 * @access protected * @var string */ protected $plugin_slug; /** * Main Loader. * * The loader that's responsible for maintaining and registering all hooks that empowers * the plugin. * * @since 1.0.0 * @access protected * @var object */ protected $loader; /** * Constructor for the Darkify class. * * Sets up all the appropriate hooks and actions within the plugin. */ public function __construct() { $this->version = DARKIFY_VERSION; $this->plugin_slug = 'darkify'; $this->load_dependencies(); $this->define_constants(); $this->define_admin_hooks(); $this->define_public_hooks(); $this->init_action(); add_action('plugin_loaded', array($this, 'init_plugin')); add_action('elementor/controls/register', [$this, 'register_controls']); add_action('elementor/widgets/register', array($this, 'register_darkify_widget')); add_action('init', [$this, 'create_darkify_block_init']); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } public function darkify_redirect_to($plugin) { if (DARKIFY_BASENAME === $plugin) { $redirect_url = esc_url(admin_url('admin.php?page=darkify')); exit(wp_kses_post(wp_safe_redirect($redirect_url))); } } /** * The slug of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_slug; } /** * Retrieve the version number of the plugin. * * @since 1.0.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } public function register_controls($controls_manager) { require_once DARKIFY_PATH . 'src/Admin/elementor/controls/class-elementor-control-switch.php'; $controls_manager->register_control( 'darkify_switch', new \Elementor_Darkify_Switcher() ); } public function register_darkify_widget($widgets_manager) { require_once DARKIFY_PATH . 'src/Admin/elementor/widgets/elementor-widget.php'; $widgets_manager->register(new \Elementor_Darkify()); } /** * Define the constants * * @return void */ public function define_constants() { define('DARKIFY_URL', plugins_url('', DARKIFY_FILE)); define('DARKIFY_ASSETS', DARKIFY_URL . '/src/assets/'); define('DARKIFY_ADMIN', DARKIFY_URL . '/src/Admin'); } /** * Load the plugin after all plugins are loaded. * * @return void */ public function init_plugin() { do_action('darkify_loaded'); load_plugin_textdomain('darkify', false, DARKIFY_DIR_NAME . "/languages"); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Loader. Orchestrates the hooks of the plugin. * - Teamproi18n. Defines internationalization functionality. * - Admin. Defines all hooks for the admin area. * - Frontend. Defines all hooks for the public side of the site. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ $this->loader = new Loader(); } /** * Register all of the hooks related to the admin dashboard functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new Admin($this->get_plugin_name(), $this->get_version()); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'admin_dequeue_for_specefic_pages', 999); // The React admin: its menu page, its bundle, and the REST endpoints it // talks to. The controllers hook themselves onto `rest_api_init`, so they // must be constructed on every request, not only in wp-admin. new Menu(); new Assets(); new SettingsRest(); // Backs the Get Help page's Recommended tab (ThemeAtelier plugin // directory with one-click install/activate). new HelpRest(); // Constructed unconditionally (not admin-only): its `init` hook also has // to fire on the frontend iframe request to swap in the preview values. new PreviewRest(); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new Frontend($this->get_plugin_name(), $this->get_version()); } public static function switcher($variant, $unique_id) { if ('classic' == $variant) { return ''; } else if ('expand' == $variant) { return ''; } else if ('inner-moon' === $variant) { return ''; } else if ('within' === $variant) { return ''; } elseif ('orbit' === $variant) { return ''; } } public static function switcher_wrapper($type, $unique_id, $variant, $switch_size, $position_class = '', $floating_switch_position = '', $tooltip_classes = '', $hide_dark_mode_on_mobile_screen = '', $floating_switch_width = '', $tooltip_on_floating_switch = '') { // A single `style` attribute: this used to be emitted TWICE (once with // just the scale variable, then — for `shortcode` — a second `style="..."` // appended after `class`). HTML only honors the FIRST of two duplicate // attributes, so that second one (the only place `position: relative` was // set) was silently dropped by every browser. Without it, an absolutely- // positioned inner element (e.g. a pill variant's sliding thumb) has no // guarantee of being positioned relative to THIS wrapper — it falls back // to whatever positioned ancestor happens to exist (or none), which is // exactly the kind of thing a page's content wrapper (often already // `position: relative`) can accidentally paper over while a theme's nav // `