PluginProbe
QuadMenu – Mega Menu / 3.3.7
QuadMenu – Mega Menu v3.3.7
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / jetpack_vendor / quadlayers / wp-plugin-suggestions / src / Page.php

Page.php in QuadMenu – Mega Menu 3.3.7, at jetpack_vendor/quadlayers/wp-plugin-suggestions/src/Page.php

156 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * QuadLayers WP Plugin Suggestions
4 *
5 * @package quadlayers/wp-plugin-suggestions
6 * @author QuadLayers
7 * @link https://github.com/quadlayers/wp-plugin-suggestions
8 * @copyright Copyright (c) 2023
9 * @license GPL-3.0
10 */
11
12 namespace QuadLayers\WP_Plugin_Suggestions;
13
14 use QuadLayers\WP_Plugin_Suggestions\Table;
15
16 /**
17 * Class Page
18 */
19 class Page {
20
21 /**
22 * Plugin data
23 *
24 * @var array
25 */
26 private $plugin_data;
27
28 /**
29 * Page constructor.
30 *
31 * @param array $plugin_data Plugin data.
32 */
33 public function __construct( array $plugin_data = array() ) {
34
35 $this->plugin_data = $plugin_data;
36
37 /**
38 * Don't load plugin menu if parent_menu_slug is set to false
39 */
40 if ( false === $this->get_parent_menu_slug() ) {
41 return;
42 }
43
44 /**
45 * Load menu after all plugins loaded to make sure that parent menu is exists
46 */
47 add_action(
48 'plugins_loaded',
49 function() {
50 add_action( 'admin_menu', array( $this, 'add_menu' ), 999 );
51 },
52 99
53 );
54
55 add_action( 'admin_init', array( $this, 'add_redirect' ) );
56 add_filter( 'network_admin_url', array( $this, 'network_admin_url' ), 10, 2 );
57 }
58
59 /**
60 * Create parent admin menu if is not exists
61 *
62 * @return void
63 */
64 public function add_menu() {
65 global $_parent_pages;
66
67 $parent_menu_slug = $this->get_parent_menu_slug();
68 $suggestions_menu_slug = $this->get_suggestions_menu_slug();
69
70 /**
71 * Don't load suggestions menu if parent_menu_slug is set to false
72 */
73 if ( ! $suggestions_menu_slug ) {
74 return;
75 }
76
77 if ( ! isset( $_parent_pages[ $parent_menu_slug ] ) ) {
78 $menu_name = esc_html__( 'Suggestions', 'wp-plugin-suggestions' );
79 if ( $menu_name ) {
80 add_menu_page(
81 $menu_name,
82 $menu_name,
83 'edit_posts',
84 $suggestions_menu_slug,
85 '__return_null',
86 'dashicons-cloud-upload'
87 );
88 }
89 }
90
91 add_submenu_page(
92 $parent_menu_slug,
93 esc_html__( 'Suggestions', 'wp-plugin-suggestions' ),
94 esc_html__( 'Suggestions', 'wp-plugin-suggestions' ),
95 'manage_options',
96 $suggestions_menu_slug,
97 function () {
98 $wp_list_table = new Table( $this->plugin_data );
99 include __DIR__ . '/view/suggestions.php';
100 },
101 99
102 );
103 }
104
105 /**
106 * Get parent menu slug
107 *
108 * @return string
109 */
110 public function get_parent_menu_slug() {
111 return $this->plugin_data['parent_menu_slug'];
112 }
113
114 /**
115 * Get suggestions menu slug
116 *
117 * @return string
118 */
119 public function get_suggestions_menu_slug() {
120 return $this->get_parent_menu_slug() . '_suggestions';
121 }
122
123 /**
124 * Fix network admin url for plugin installation
125 *
126 * @param [type] $url site url.
127 * @param [type] $path path.
128 * @return string
129 */
130 public function network_admin_url( $url, $path ) {
131 if ( wp_doing_ajax() && ! is_network_admin() ) {
132 if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'install-plugin' ) {
133 if ( strpos( $url, 'plugins.php' ) !== false ) {
134 $url = self_admin_url( $path );
135 }
136 }
137 }
138
139 return $url;
140 }
141
142 /**
143 * Redirect to the current page after activation
144 *
145 * @return void
146 */
147 public function add_redirect() {
148 if ( isset( $_REQUEST['activate'] ) && $_REQUEST['activate'] == 'true' ) {
149 if ( wp_get_referer() == admin_url( 'admin.php?page=' . $this->get_suggestions_menu_slug() ) ) {
150 wp_safe_redirect( admin_url( 'admin.php?page=' . $this->get_suggestions_menu_slug() ) );
151 exit();
152 }
153 }
154 }
155 }
156