css
7 years ago
js
7 years ago
partials
7 years ago
class-wpvivid-admin.php
7 years ago
index.php
7 years ago
class-wpvivid-admin.php
266 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The admin-specific functionality of the plugin. |
| 5 | * |
| 6 | * @link https://wpvivid.com |
| 7 | * @since 0.9.1 |
| 8 | * |
| 9 | * @package WPvivid |
| 10 | * @subpackage WPvivid/admin |
| 11 | */ |
| 12 | |
| 13 | /** |
| 14 | * The admin-specific functionality of the plugin. |
| 15 | * |
| 16 | * Defines the plugin name, version, and two examples hooks for how to |
| 17 | * enqueue the admin-specific stylesheet and JavaScript. |
| 18 | * |
| 19 | * @package WPvivid |
| 20 | * @subpackage WPvivid/admin |
| 21 | * @author wpvivid team |
| 22 | */ |
| 23 | if (!defined('WPVIVID_PLUGIN_DIR')){ |
| 24 | die; |
| 25 | } |
| 26 | class WPvivid_Admin { |
| 27 | |
| 28 | /** |
| 29 | * The ID of this plugin. |
| 30 | * |
| 31 | * |
| 32 | * @access private |
| 33 | * @var string $plugin_name The ID of this plugin. |
| 34 | */ |
| 35 | private $plugin_name; |
| 36 | |
| 37 | /** |
| 38 | * The version of this plugin. |
| 39 | * |
| 40 | * |
| 41 | * @access private |
| 42 | * @var string $version The current version of this plugin. |
| 43 | */ |
| 44 | private $version; |
| 45 | |
| 46 | /** |
| 47 | * Initialize the class and set its properties. |
| 48 | * |
| 49 | * |
| 50 | * @param string $plugin_name The name of this plugin. |
| 51 | * @param string $version The version of this plugin. |
| 52 | */ |
| 53 | public function __construct($plugin_name, $version) { |
| 54 | |
| 55 | $this->plugin_name = $plugin_name; |
| 56 | $this->version = $version; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Register the stylesheets for the admin area. |
| 61 | * |
| 62 | * |
| 63 | */ |
| 64 | public function enqueue_styles() { |
| 65 | |
| 66 | /** |
| 67 | * This function is provided for demonstration purposes only. |
| 68 | * |
| 69 | * An instance of this class should be passed to the run() function |
| 70 | * defined in WPvivid_Loader as all of the hooks are defined |
| 71 | * in that particular class. |
| 72 | * |
| 73 | * The WPvivid_Loader will then create the relationship |
| 74 | * between the defined hooks and the functions defined in this |
| 75 | * class. |
| 76 | */ |
| 77 | if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id || |
| 78 | 'wpvivid_page_wpvivid-setting' == get_current_screen()->id || |
| 79 | 'wpvivid_page_wpvivid-remote' == get_current_screen()->id || |
| 80 | 'wpvivid_page_wpvivid-website' == get_current_screen()->id || |
| 81 | 'wpvivid_page_wpvivid-log' == get_current_screen()->id) { |
| 82 | wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvivid-admin.css', array(), $this->version, 'all'); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Register the JavaScript for the admin area. |
| 88 | * |
| 89 | * |
| 90 | */ |
| 91 | public function enqueue_scripts() { |
| 92 | |
| 93 | /** |
| 94 | * This function is provided for demonstration purposes only. |
| 95 | * |
| 96 | * An instance of this class should be passed to the run() function |
| 97 | * defined in WPvivid_Loader as all of the hooks are defined |
| 98 | * in that particular class. |
| 99 | * |
| 100 | * The WPvivid_Loader will then create the relationship |
| 101 | * between the defined hooks and the functions defined in this |
| 102 | * class. |
| 103 | */ |
| 104 | if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id || |
| 105 | 'wpvivid_page_wpvivid-setting' == get_current_screen()->id || |
| 106 | 'wpvivid_page_wpvivid-remote' == get_current_screen()->id || |
| 107 | 'wpvivid_page_wpvivid-website' == get_current_screen()->id || |
| 108 | 'wpvivid_page_wpvivid-log' == get_current_screen()->id) { |
| 109 | wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpvivid-admin.js', array('jquery'), $this->version, false); |
| 110 | wp_enqueue_script($this->plugin_name.'jquerymin', includes_url() . 'js/jquery/jquery.js', array('jquery'), $this->version, false); |
| 111 | wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php'))); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Register the administration menu for this plugin into the WordPress Dashboard menu. |
| 117 | * |
| 118 | * |
| 119 | */ |
| 120 | public function add_plugin_admin_menu() { |
| 121 | |
| 122 | /* |
| 123 | * Add a settings page for this plugin to the Settings menu. |
| 124 | * |
| 125 | * NOTE: Alternative menu locations are available via WordPress administration menu functions. |
| 126 | * |
| 127 | * Administration Menus: http://codex.wordpress.org/Administration_Menus |
| 128 | * |
| 129 | */ |
| 130 | add_menu_page(__('WPvivid'), __('WPvivid'), 'administrator', $this->plugin_name, array($this, 'display_plugin_backup_page'), false, 100); |
| 131 | add_submenu_page($this->plugin_name, __('WPvivid'), __('Backup / Restore', 'wpvivid'), 'administrator', $this->plugin_name, array($this, 'display_plugin_backup_page'), false, 100); |
| 132 | add_submenu_page($this->plugin_name, __('WPvivid'), __('Settings', 'wpvivid'), 'administrator', 'wpvivid-setting', array($this, 'display_plugin_setting_page'), false, 100); |
| 133 | add_submenu_page($this->plugin_name, __('WPvivid'), __('Remote Storage', 'wpvivid'), 'administrator', 'wpvivid-remote', array($this, 'display_plugin_remote_page'), false, 100); |
| 134 | add_submenu_page($this->plugin_name, __('WPvivid'), __('Website Info', 'wpvivid'), 'administrator', 'wpvivid-website', array($this, 'display_plugin_website_page'), false, 100); |
| 135 | add_submenu_page($this->plugin_name, __('WPvivid'), __('Logs', 'wpvivid'), 'administrator', 'wpvivid-log', array($this, 'display_plugin_log_page'), false, 100); |
| 136 | } |
| 137 | |
| 138 | function add_toolbar_items($wp_admin_bar){ |
| 139 | global $wpvivid_pulgin; |
| 140 | $show_admin_bar = $wpvivid_pulgin->get_admin_bar_setting(); |
| 141 | if($show_admin_bar === true){ |
| 142 | $admin_url = admin_url(); |
| 143 | $wp_admin_bar->add_menu(array( |
| 144 | 'id' => 'wpvivid_admin_menu', |
| 145 | 'title' => 'WPvivid' |
| 146 | )); |
| 147 | $wp_admin_bar->add_menu(array( |
| 148 | 'id' => 'wpvivid_admin_menu_backup', |
| 149 | 'parent' => 'wpvivid_admin_menu', |
| 150 | 'title' => 'Backup / Restore', |
| 151 | 'href' => $admin_url . 'admin.php?page=WPvivid&tab-backup' |
| 152 | )); |
| 153 | $wp_admin_bar->add_menu(array( |
| 154 | 'id' => 'wpvivid_admin_menu_settings', |
| 155 | 'parent' => 'wpvivid_admin_menu', |
| 156 | 'title' => 'Settings', |
| 157 | 'href' => $admin_url . 'admin.php?page=WPvivid&tab-settings' |
| 158 | )); |
| 159 | $wp_admin_bar->add_menu(array( |
| 160 | 'id' => 'wpvivid_admin_menu_addons', |
| 161 | 'parent' => 'wpvivid_admin_menu', |
| 162 | 'title' => 'Remote Storage', |
| 163 | 'href' => $admin_url . 'admin.php?page=WPvivid&tab-remote-storage' |
| 164 | )); |
| 165 | $wp_admin_bar->add_menu(array( |
| 166 | 'id' => 'wpvivid_admin_menu_debug', |
| 167 | 'parent' => 'wpvivid_admin_menu', |
| 168 | 'title' => 'Website Info', |
| 169 | 'href' => $admin_url . 'admin.php?page=WPvivid&tab-website-info' |
| 170 | )); |
| 171 | $wp_admin_bar->add_menu(array( |
| 172 | 'id' => 'wpvivid_admin_menu_logs', |
| 173 | 'parent' => 'wpvivid_admin_menu', |
| 174 | 'title' => 'Logs', |
| 175 | 'href' => $admin_url . 'admin.php?page=WPvivid&tab-logs' |
| 176 | )); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | public function add_action_links( $links ) { |
| 181 | $settings_link = array( |
| 182 | '<a href="' . admin_url( 'admin.php?page=' . $this->plugin_name ) . '">' . __('Settings', $this->plugin_name) . '</a>', |
| 183 | ); |
| 184 | return array_merge( $settings_link, $links ); |
| 185 | } |
| 186 | |
| 187 | public function wpvivid_get_siteurl(){ |
| 188 | $wpvivid_siteurl = array(); |
| 189 | $wpvivid_siteurl['home_url'] = home_url(); |
| 190 | $wpvivid_siteurl['plug_url'] = plugins_url(); |
| 191 | return $wpvivid_siteurl; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Render the settings page for this plugin. |
| 196 | * |
| 197 | * |
| 198 | */ |
| 199 | public function display_plugin_setup_page() |
| 200 | { |
| 201 | if(isset($_REQUEST['tab-backup'])){ |
| 202 | self::wpvivid_set_page_request('backup'); |
| 203 | } |
| 204 | else if(isset($_REQUEST['tab-settings'])){ |
| 205 | self::wpvivid_set_page_request('settings'); |
| 206 | } |
| 207 | else if(isset($_REQUEST['tab-remote-storage'])){ |
| 208 | self::wpvivid_set_page_request('remote'); |
| 209 | } |
| 210 | else if(isset($_REQUEST['tab-website-info'])){ |
| 211 | self::wpvivid_set_page_request('website'); |
| 212 | } |
| 213 | else if(isset($_REQUEST['tab-logs'])){ |
| 214 | self::wpvivid_set_page_request('log'); |
| 215 | } |
| 216 | global $wpvivid_pulgin; |
| 217 | $wpvivid_pulgin->clean_cache(); |
| 218 | |
| 219 | $restore = new WPvivid_restore_data(); |
| 220 | if ($restore->has_restore()) { |
| 221 | $restore_status = $restore->get_restore_status(); |
| 222 | if ($restore_status === WPVIVID_RESTORE_COMPLETED) { |
| 223 | $restore->clean_restore_data(); |
| 224 | _e('<div class="notice notice-success is-dismissible"><p>Restore completed successfully.</p></div>'); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | include_once('partials/wpvivid-admin-display.php'); |
| 229 | } |
| 230 | |
| 231 | public function display_plugin_backup_page(){ |
| 232 | self::wpvivid_set_page_request('backup'); |
| 233 | $this->display_plugin_setup_page(); |
| 234 | } |
| 235 | |
| 236 | public function display_plugin_setting_page(){ |
| 237 | self::wpvivid_set_page_request('settings'); |
| 238 | $this->display_plugin_setup_page(); |
| 239 | } |
| 240 | |
| 241 | public function display_plugin_remote_page(){ |
| 242 | self::wpvivid_set_page_request('remote'); |
| 243 | $this->display_plugin_setup_page(); |
| 244 | } |
| 245 | |
| 246 | public function display_plugin_website_page(){ |
| 247 | self::wpvivid_set_page_request('website'); |
| 248 | $this->display_plugin_setup_page(); |
| 249 | } |
| 250 | |
| 251 | public function display_plugin_log_page(){ |
| 252 | self::wpvivid_set_page_request('log'); |
| 253 | $this->display_plugin_setup_page(); |
| 254 | } |
| 255 | |
| 256 | public function wpvivid_set_page_request($page){ |
| 257 | global $request_page; |
| 258 | $request_page=$page; |
| 259 | } |
| 260 | |
| 261 | public static function wpvivid_get_page_request(){ |
| 262 | global $request_page; |
| 263 | return $request_page; |
| 264 | } |
| 265 | |
| 266 | } |