PluginProbe
Patchstack – WordPress & Plugins Security / 2.3.0
Patchstack – WordPress & Plugins Security v2.3.0
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
patchstack / includes / admin / menu.php

menu.php in Patchstack – WordPress & Plugins Security 2.3.0, at includes/admin/menu.php

118 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Do not allow the file to be called directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * This class used for the admin menu and to enqueue styles and/or scripts.
10 */
11 class P_Admin_Menu extends P_Core {
12
13 /**
14 * Add the actions required for the admin menu.
15 *
16 * @param Patchstack $core
17 * @return void
18 */
19 public function __construct( $core ) {
20 parent::__construct( $core );
21 add_action( 'admin_head', [ $this, 'add_meta_nonce' ] );
22 add_action( 'admin_menu', [ $this, 'add_menu_pages' ] );
23 add_action( 'network_admin_menu', [ $this, 'network_menu' ] );
24 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] );
25 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
26 add_filter( 'plugin_action_links_' . $this->plugin->basename, [ $this, 'admin_settings' ] );
27 }
28
29 /**
30 * Add Patchstack nonce as meta tag so we can access it in our JavaScript files.
31 *
32 * @return void
33 */
34 public function add_meta_nonce() {
35 $screen = get_current_screen();
36 if ( current_user_can( 'manage_options' ) && isset( $screen->base ) && stripos( $screen->base, 'patchstack' ) !== false ) {
37 echo '<meta name="patchstack_nonce" value="' . wp_create_nonce( 'patchstack-nonce' ) . '">';
38 }
39 }
40
41 /**
42 * Register the wp-admin menu items.
43 *
44 * @return void
45 */
46 public function add_menu_pages() {
47 add_submenu_page( $this->plugin->name, 'Main', esc_attr__( 'Settings', 'patchstack' ), 'manage_options', $this->plugin->name, [ $this, 'render_settings_page' ] );
48 add_options_page( 'Security', 'Security', 'manage_options', $this->plugin->name );
49 }
50
51 /**
52 * Register the menu pages for multisite/networks.
53 *
54 * @return void
55 */
56 public function network_menu() {
57 add_menu_page( 'Patchstack', 'Patchstack', 'manage_options', 'patchstack-multisite', [ $this->plugin->multisite, 'sites_section_callback' ] );
58 add_submenu_page( 'patchstack-multisite', 'Activate', 'Activate', 'manage_options', 'patchstack-multisite-settings', [ $this, 'render_settings_page' ] );
59 add_submenu_page( 'patchstack-multisite', 'Sites', 'Sites', 'manage_options', 'patchstack-multisite', [ $this->plugin->multisite, 'sites_section_callback' ] );
60 }
61
62 /**
63 * Render the settings page.
64 *
65 * @return void
66 */
67 public function render_settings_page() {
68 require dirname( __FILE__ ) . '/../views/pages/settings.php';
69 }
70
71 /**
72 * Register the stylesheets for the backend.
73 *
74 * @return void
75 */
76 public function enqueue_styles() {
77 $screen = get_current_screen();
78
79 // Load the Patchstack style on all Patchstack pages except site overview.
80 if ( isset( $screen->base, $_GET['page'] ) && stripos( $screen->base, 'patchstack' ) !== false && $_GET['page'] != 'patchstack-multisite' ) {
81 wp_enqueue_style( 'patchstack', $this->plugin->url . 'assets/css/patchstack.min.css', [], $this->plugin->version );
82 wp_enqueue_style( 'patchstack-hint', 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/3.0.0/hint.min.css', [], $this->plugin->version );
83 }
84 }
85
86 /**
87 * Register the JavaScript for the admin area.
88 *
89 * @return void
90 */
91 public function enqueue_scripts() {
92 $screen = get_current_screen();
93 if ( isset( $screen->base ) && ( stripos( $screen->base, 'patchstack' ) !== false ) && current_user_can( 'manage_options' ) ) {
94 wp_enqueue_script( 'patchstack', $this->plugin->url . 'assets/js/patchstack.min.js', [ 'jquery' ], $this->plugin->version );
95 wp_enqueue_script( 'google-jsapi', 'https://www.google.com/jsapi' );
96 wp_localize_script(
97 'patchstack',
98 'PatchstackVars',
99 [
100 'ajaxurl' => admin_url( 'admin-ajax.php' ),
101 'nonce' => wp_create_nonce( 'patchstack-nonce' ),
102 'error_message' => esc_attr__( 'Sorry, there was a problem processing your request.', 'patchstack' ),
103 ]
104 );
105 }
106 }
107
108 /**
109 * Add the "Settings" hyperlink to the Patchstack section on the plugins page of WordPress.
110 *
111 * @param array $links
112 * @return array
113 */
114 public function admin_settings( $links ) {
115 return array_merge( [ '<a href="admin.php?page=patchstack&tab=license">' . esc_attr__( 'Settings', 'patchstack' ) . '</a>' ], $links );
116 }
117 }
118