| @@ -17,19 +17,14 @@ | ||
| 17 | 17 | * @return void |
| 18 | 18 | */ |
| 19 | 19 | public function __construct( $core ) { |
| 20 | 20 | parent::__construct( $core ); |
| 21 | - | |
| 22 | - if ( defined( 'PS_DISABLE_MENU' ) && PS_DISABLE_MENU ) { | |
| 23 | - return; | |
| 24 | - } | |
| 25 | - | |
| 26 | - add_action( 'admin_head', [ $this, 'add_meta_nonce' ] ); | |
| 27 | - add_action( 'admin_menu', [ $this, 'add_menu_pages' ] ); | |
| 28 | - add_action( 'network_admin_menu', [ $this, 'network_menu' ] ); | |
| 29 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] ); | |
| 30 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); | |
| 31 | - add_filter( 'plugin_action_links_' . $this->plugin->basename, [ $this, 'admin_settings' ] ); | |
| 21 | + add_action( 'admin_head', array( $this, 'add_meta_nonce' ) ); | |
| 22 | + add_action( 'admin_menu', array( $this, 'add_menu_pages' ) ); | |
| 23 | + add_action( 'network_admin_menu', array( $this, 'network_menu' ) ); | |
| 24 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); | |
| 25 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); | |
| 26 | + add_filter( 'plugin_action_links_' . $this->plugin->basename, array( $this, 'admin_settings' ) ); | |
| 32 | 27 | } |
| 33 | 28 | |
| 34 | 29 | /** |
| 35 | 30 | * Add Patchstack nonce as meta tag so we can access it in our JavaScript files. |
| @@ -37,9 +32,9 @@ | ||
| 37 | 32 | * @return void |
| 38 | 33 | */ |
| 39 | 34 | public function add_meta_nonce() { |
| 40 | 35 | $screen = get_current_screen(); |
| 41 | - if ( current_user_can( 'manage_options' ) && isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false ) { | |
| 36 | + if ( current_user_can( 'manage_options' ) && isset( $screen->base ) && ( $screen->base == 'dashboard' || stripos( $screen->base, 'patchstack' ) !== false ) ) { | |
| 42 | 37 | echo '<meta name="patchstack_nonce" value="' . wp_create_nonce( 'patchstack-nonce' ) . '">'; |
| 43 | 38 | } |
| 44 | 39 | } |
| 45 | 40 | |
| @@ -48,9 +43,9 @@ | ||
| 48 | 43 | * |
| 49 | 44 | * @return void |
| 50 | 45 | */ |
| 51 | 46 | public function add_menu_pages() { |
| 52 | - add_submenu_page( $this->plugin->name, 'Main', esc_attr__( 'Settings', 'patchstack' ), 'manage_options', $this->plugin->name, [ $this, 'render_settings_page' ] ); | |
| 47 | + add_submenu_page( $this->plugin->name, 'Main', __( 'Settings', 'patchstack' ), 'manage_options', $this->plugin->name, array( $this, 'render_settings_page' ) ); | |
| 53 | 48 | add_options_page( 'Security', 'Security', 'manage_options', $this->plugin->name ); |
| 54 | 49 | } |
| 55 | 50 | |
| 56 | 51 | /** |
| @@ -58,10 +53,12 @@ | ||
| 58 | 53 | * |
| 59 | 54 | * @return void |
| 60 | 55 | */ |
| 61 | 56 | public function network_menu() { |
| 62 | - add_menu_page( 'Patchstack', 'Patchstack', 'manage_options', 'patchstack-multisite', [ $this->plugin->multisite, 'sites_section_callback' ] ); | |
| 63 | - add_submenu_page( 'patchstack-multisite', 'Activate', 'Activate', 'manage_options', 'patchstack-multisite-settings', [ $this, 'render_settings_page' ] ); | |
| 57 | + add_menu_page( 'Patchstack', 'Patchstack', 'manage_options', 'patchstack-multisite', array( $this->plugin->multisite, 'sites_section_callback' ) ); | |
| 58 | + add_submenu_page( 'patchstack-multisite', 'Activate', 'Activate', 'manage_options', 'patchstack-multisite-settings&tab=multisite', array( $this->plugin->multisite, 'settings' ) ); | |
| 59 | + add_submenu_page( 'patchstack-multisite', 'Sites', 'Sites', 'manage_options', 'patchstack-multisite', array( $this->plugin->multisite, 'sites_section_callback' ) ); | |
| 60 | + add_submenu_page( 'patchstack-multisite', 'Settings', 'Settings', 'manage_options', 'patchstack-multisite-settings', array( $this, 'render_settings_page' ) ); | |
| 64 | 61 | } |
| 65 | 62 | |
| 66 | 63 | /** |
| 67 | 64 | * Render the settings page. |
| @@ -81,11 +78,20 @@ | ||
| 81 | 78 | $screen = get_current_screen(); |
| 82 | 79 | |
| 83 | 80 | // Load the Patchstack style on all Patchstack pages except site overview. |
| 84 | 81 | if ( isset( $screen->base, $_GET['page'] ) && stripos( $screen->base, 'patchstack' ) !== false && $_GET['page'] != 'patchstack-multisite' ) { |
| 85 | - wp_enqueue_style( 'patchstack', $this->plugin->url . 'assets/css/patchstack.min.css', [], $this->plugin->version ); | |
| 86 | - wp_enqueue_style( 'patchstack-hint', 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/3.0.0/hint.min.css', [], $this->plugin->version ); | |
| 82 | + wp_enqueue_style( 'patchstack', $this->plugin->url . 'assets/css/patchstack.css', array(), $this->plugin->version ); | |
| 87 | 83 | } |
| 84 | + | |
| 85 | + // Only load the selectize CSS file on the firewall settings page. | |
| 86 | + if ( isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false && isset( $_GET['tab'] ) && $_GET['tab'] == 'firewall' ) { | |
| 87 | + wp_enqueue_style( 'patchstack-selectize', $this->plugin->url . 'assets/css/selectize.min.css', array( ), $this->plugin->version ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + // Only load the dataTables CSS fileon the logs page. | |
| 91 | + if ( isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false && isset( $_GET['tab'] ) && $_GET['tab'] == 'logs' ) { | |
| 92 | + wp_enqueue_style( 'patchstack-logs', $this->plugin->url . 'assets/css/jquery.dataTables.min.css', array( ), $this->plugin->version ); | |
| 93 | + } | |
| 88 | 94 | } |
| 89 | 95 | |
| 90 | 96 | /** |
| 91 | 97 | * Register the JavaScript for the admin area. |
| @@ -94,20 +100,36 @@ | ||
| 94 | 100 | */ |
| 95 | 101 | public function enqueue_scripts() { |
| 96 | 102 | $screen = get_current_screen(); |
| 97 | 103 | if ( isset( $screen->base ) && ( stripos( $screen->base, 'patchstack' ) !== false ) && current_user_can( 'manage_options' ) ) { |
| 98 | - wp_enqueue_script( 'patchstack', $this->plugin->url . 'assets/js/patchstack.min.js', [ 'jquery' ], $this->plugin->version ); | |
| 104 | + wp_enqueue_script( 'patchstack', $this->plugin->url . 'assets/js/patchstack.js', array( 'jquery' ), $this->plugin->version ); | |
| 99 | 105 | wp_enqueue_script( 'google-jsapi', 'https://www.google.com/jsapi' ); |
| 100 | 106 | wp_localize_script( |
| 101 | 107 | 'patchstack', |
| 102 | 108 | 'PatchstackVars', |
| 103 | - [ | |
| 109 | + array( | |
| 104 | 110 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 105 | 111 | 'nonce' => wp_create_nonce( 'patchstack-nonce' ), |
| 106 | - 'error_message' => esc_attr__( 'Sorry, there was a problem processing your request.', 'patchstack' ), | |
| 107 | - ] | |
| 112 | + 'error_message' => __( 'Sorry, there was a problem processing your request.', 'patchstack' ), | |
| 113 | + ) | |
| 108 | 114 | ); |
| 109 | 115 | } |
| 116 | + | |
| 117 | + // Only load the colorpicker on the cookie notice settings page. | |
| 118 | + if ( isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false && isset( $_GET['tab'] ) && $_GET['tab'] == 'cookienotice' ) { | |
| 119 | + wp_enqueue_script( 'patchstack-jscolor', $this->plugin->url . 'assets/js/jscolor.js', array( ), $this->plugin->version ); | |
| 120 | + } | |
| 121 | + | |
| 122 | + // Only load the selectize library on the firewall settings page. | |
| 123 | + if ( isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false && isset( $_GET['tab'] ) && $_GET['tab'] == 'firewall' ) { | |
| 124 | + wp_enqueue_script( 'patchstack-selectize', $this->plugin->url . 'assets/js/selectize.min.js', array( ), $this->plugin->version ); | |
| 125 | + } | |
| 126 | + | |
| 127 | + // Only load the dataTables related libraries on the logs page. | |
| 128 | + if ( isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false && isset( $_GET['tab'] ) && $_GET['tab'] == 'logs' ) { | |
| 129 | + wp_enqueue_script( 'patchstack-bootstrap', $this->plugin->url . 'assets/js/bootstrap.min.js', array( 'jquery' ), $this->plugin->version ); | |
| 130 | + wp_enqueue_script( 'patchstack-logs', $this->plugin->url . 'assets/js/jquery.dataTables.min.js', array( ), $this->plugin->version ); | |
| 131 | + } | |
| 110 | 132 | } |
| 111 | 133 | |
| 112 | 134 | /** |
| 113 | 135 | * Add the "Settings" hyperlink to the Patchstack section on the plugins page of WordPress. |
| @@ -115,7 +137,7 @@ | ||
| 115 | 137 | * @param array $links |
| 116 | 138 | * @return array |
| 117 | 139 | */ |
| 118 | 140 | public function admin_settings( $links ) { |
| 119 | - return array_merge( [ '<a href="admin.php?page=patchstack&tab=license">' . esc_attr__( 'Settings', 'patchstack' ) . '</a>' ], $links ); | |
| 141 | + return array_merge( array( '<a href="admin.php?page=patchstack&tab=firewall">' . __( 'Settings', 'patchstack' ) . '</a>' ), $links ); | |
| 120 | 142 | } |
| 121 | 143 | } |