| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The file of the Darkify class. |
| 5 |
* |
| 6 |
* @link https://themeatelier.net |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Darkify |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace ThemeAtelier\Darkify; |
| 13 |
|
| 14 |
use ThemeAtelier\Darkify\Admin\Admin; |
| 15 |
use ThemeAtelier\Darkify\Frontend\Frontend; |
| 16 |
use ThemeAtelier\Darkify\Helpers\ReviewNotice; |
| 17 |
|
| 18 |
// don't call the file directly. |
| 19 |
if (!defined('ABSPATH')) { |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* The main class of the plugin. |
| 25 |
* |
| 26 |
* Handle all the class and methods of the plugin. |
| 27 |
* |
| 28 |
* @author ThemeAtelier <themeatelierbd@gmail.com> |
| 29 |
*/ |
| 30 |
class Darkify |
| 31 |
{ |
| 32 |
/** |
| 33 |
* Plugin version |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
* @access protected |
| 37 |
* @var string |
| 38 |
*/ |
| 39 |
protected $version; |
| 40 |
|
| 41 |
/** |
| 42 |
* Plugin slug |
| 43 |
* |
| 44 |
* @since 1.0.0 |
| 45 |
* @access protected |
| 46 |
* @var string |
| 47 |
*/ |
| 48 |
protected $plugin_slug; |
| 49 |
|
| 50 |
/** |
| 51 |
* Main Loader. |
| 52 |
* |
| 53 |
* The loader that's responsible for maintaining and registering all hooks that empowers |
| 54 |
* the plugin. |
| 55 |
* |
| 56 |
* @since 1.0.0 |
| 57 |
* @access protected |
| 58 |
* @var object |
| 59 |
*/ |
| 60 |
protected $loader; |
| 61 |
/** |
| 62 |
* Constructor for the Darkify class. |
| 63 |
* |
| 64 |
* Sets up all the appropriate hooks and actions within the plugin. |
| 65 |
*/ |
| 66 |
public function __construct() |
| 67 |
{ |
| 68 |
$this->version = DARKIFY_VERSION; |
| 69 |
$this->plugin_slug = 'darkify'; |
| 70 |
$this->load_dependencies(); |
| 71 |
$this->define_constants(); |
| 72 |
$this->define_admin_hooks(); |
| 73 |
$this->define_public_hooks(); |
| 74 |
add_action('plugin_loaded', array($this, 'init_plugin')); |
| 75 |
add_action('activated_plugin', array($this, 'redirect_to')); |
| 76 |
$active_plugins = get_option('active_plugins'); |
| 77 |
foreach ($active_plugins as $active_plugin) { |
| 78 |
$_temp = strpos($active_plugin, 'darkify.php'); |
| 79 |
if (false != $_temp) { |
| 80 |
add_filter('plugin_action_links_' . $active_plugin, array($this, 'darkify_plugin_action_links')); |
| 81 |
} |
| 82 |
} |
| 83 |
new ReviewNotice(); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Run the loader to execute all of the hooks with WordPress. |
| 88 |
* |
| 89 |
* @since 1.0.0 |
| 90 |
*/ |
| 91 |
public function run() |
| 92 |
{ |
| 93 |
$this->loader->run(); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* The slug of the plugin used to uniquely identify it within the context of |
| 98 |
* WordPress and to define internationalization functionality. |
| 99 |
* |
| 100 |
* @since 1.0.0 |
| 101 |
* @return string The name of the plugin. |
| 102 |
*/ |
| 103 |
public function get_plugin_name() |
| 104 |
{ |
| 105 |
return $this->plugin_slug; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Retrieve the version number of the plugin. |
| 110 |
* |
| 111 |
* @since 1.0.0 |
| 112 |
* @return string The version number of the plugin. |
| 113 |
*/ |
| 114 |
public function get_version() |
| 115 |
{ |
| 116 |
return $this->version; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Define the constants |
| 121 |
* |
| 122 |
* @return void |
| 123 |
*/ |
| 124 |
public function define_constants() |
| 125 |
{ |
| 126 |
define('DARKIFY_URL', plugins_url('', DARKIFY_FILE)); |
| 127 |
define('DARKIFY_ASSETS', DARKIFY_URL . '/src/assets/'); |
| 128 |
define('DARKIFY_ADMIN', DARKIFY_URL . '/src/Admin'); |
| 129 |
} |
| 130 |
|
| 131 |
public function redirect_to($plugin) |
| 132 |
{ |
| 133 |
if (DARKIFY_BASENAME === $plugin) { |
| 134 |
$redirect_url = esc_url(admin_url('admin.php?page=darkify')); |
| 135 |
exit(wp_kses_post(wp_safe_redirect($redirect_url))); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Load the plugin after all plugins are loaded. |
| 141 |
* |
| 142 |
* @return void |
| 143 |
*/ |
| 144 |
public function init_plugin() |
| 145 |
{ |
| 146 |
do_action('darkify_loaded'); |
| 147 |
load_plugin_textdomain('darkify', false, DARKIFY_DIR_NAME . "/languages"); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Load the required dependencies for this plugin. |
| 152 |
* |
| 153 |
* Include the following files that make up the plugin: |
| 154 |
* |
| 155 |
* - Loader. Orchestrates the hooks of the plugin. |
| 156 |
* - Teamproi18n. Defines internationalization functionality. |
| 157 |
* - Admin. Defines all hooks for the admin area. |
| 158 |
* - Frontend. Defines all hooks for the public side of the site. |
| 159 |
* |
| 160 |
* Create an instance of the loader which will be used to register the hooks |
| 161 |
* with WordPress. |
| 162 |
* |
| 163 |
* @since 1.0.0 |
| 164 |
* @access private |
| 165 |
*/ |
| 166 |
private function load_dependencies() |
| 167 |
{ |
| 168 |
/** |
| 169 |
* The class responsible for orchestrating the actions and filters of the |
| 170 |
* core plugin. |
| 171 |
*/ |
| 172 |
$this->loader = new Loader(); |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* Register all of the hooks related to the admin dashboard functionality |
| 177 |
* of the plugin. |
| 178 |
* |
| 179 |
* @since 1.0.0 |
| 180 |
* @access private |
| 181 |
*/ |
| 182 |
private function define_admin_hooks() |
| 183 |
{ |
| 184 |
$plugin_admin = new Admin($this->get_plugin_name(), $this->get_version()); |
| 185 |
|
| 186 |
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
| 187 |
$this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Register all of the hooks related to the public-facing functionality |
| 192 |
* of the plugin. |
| 193 |
* |
| 194 |
* @since 1.0.0 |
| 195 |
* @access private |
| 196 |
*/ |
| 197 |
private function define_public_hooks() |
| 198 |
{ |
| 199 |
$plugin_public = new Frontend($this->get_plugin_name(), $this->get_version()); |
| 200 |
} |
| 201 |
|
| 202 |
// Plugin settings in plugin list |
| 203 |
public function darkify_plugin_action_links(array $links) |
| 204 |
{ |
| 205 |
$new_links = array( |
| 206 |
sprintf('<a href="' . esc_url(admin_url('admin.php?page=darkify#tab=general')) . '">' . esc_html__('Settings', 'darkify') . '</a>'), |
| 207 |
sprintf('<a target="_blank" href="https://themeatelier.net/contact">' . esc_html__('Support', 'darkify') . '</a>'), |
| 208 |
sprintf('<a style="font-weight: bold;color:#171717" target="_blank" href="https://themeatelier.net/downloads/darkify">' . esc_html__('Go Pro', 'darkify') . '</a>'), |
| 209 |
); |
| 210 |
return array_merge($new_links, $links); |
| 211 |
} |
| 212 |
} |
| 213 |
|