PluginProbe
Maps Plugin using Google Maps for WordPress – WP Google Map / trunk
Maps Plugin using Google Maps for WordPress – WP Google Map vtrunk
1.9.7 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 All 96 releases
gmap-embed / includes / traits / Menu.php

Menu.php in Maps Plugin using Google Maps for WordPress – WP Google Map trunk, at includes/traits/Menu.php

261 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WGMSRM\Traits;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 /**
10 * Trait Menu
11 */
12 trait Menu
13 {
14
15 /**
16 * To create menu in admin panel
17 */
18 public function gmap_create_menu()
19 {
20 // create new top-level menu
21 add_menu_page(
22 esc_html($this->plugin_name),
23 esc_html($this->plugin_name),
24 $this->capability,
25 'wpgmapembed',
26 array(
27 $this,
28 'srm_gmap_main',
29 ),
30 'dashicons-location',
31 11
32 );
33
34 add_submenu_page(
35 'wpgmapembed',
36 esc_html__('All Maps', 'gmap-embed'),
37 esc_html__('All Maps', 'gmap-embed'),
38 $this->capability,
39 'wpgmapembed',
40 array(
41 $this,
42 'srm_gmap_main',
43 ),
44 0
45 );
46
47 // to create sub menu
48 if (_wgm_can_add_new_map()) {
49 add_submenu_page(
50 'wpgmapembed',
51 esc_html__('Add new Map', 'gmap-embed'),
52 esc_html__('Add New', 'gmap-embed'),
53 $this->capability,
54 'wpgmapembed-new',
55 array(
56 $this,
57 'srm_gmap_new',
58 ),
59 1
60 );
61 } else {
62 if (
63 isset($_GET['page']) &&
64 sanitize_key(wp_unslash($_GET['page'])) === 'wpgmapembed-new'
65 ) {
66 // If a nonce is present, verify it. If invalid, block the request.
67 // If no nonce is present, this is a simple redirect and no further check is required.
68 if ( ! empty( $_REQUEST['_wpnonce'] ) ) {
69 $nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
70 if ( ! wp_verify_nonce( $nonce, 'wgm_add_new_map' ) ) {
71 wp_die( esc_html__( 'Security check failed.', 'gmap-embed' ) );
72 }
73 }
74
75 // If the user tries to access the "Add New" page without permission, redirect them to the main page
76 $redirect_url = esc_url_raw(
77 add_query_arg(
78 array( 'page' => 'wpgmapembed' ),
79 admin_url( 'admin.php' )
80 )
81 );
82 wp_safe_redirect( $redirect_url );
83 exit;
84 }
85 }
86
87 add_submenu_page(
88 'wpgmapembed',
89 esc_html__('Categories', 'gmap-embed'),
90 esc_html__('Categories', 'gmap-embed'),
91 $this->capability,
92 'wpgmapembed-categories',
93 array(
94 $this,
95 'wgm_categories_page',
96 ),
97 2
98 );
99
100 // setup wizard menu
101 add_submenu_page(
102 'wpgmapembed',
103 esc_html__('Quick Setup', 'gmap-embed'),
104 esc_html__('Quick Setup', 'gmap-embed'),
105 $this->capability,
106 'wgm_setup_wizard',
107 array(
108 $this,
109 'wpgmap_setup_wizard',
110 ),
111 3
112 );
113
114
115 add_submenu_page(
116 'wpgmapembed',
117 esc_html__('Support', 'gmap-embed'),
118 esc_html__('Support', 'gmap-embed'),
119 $this->capability,
120 'wpgmapembed-support',
121 array(
122 $this,
123 'wgm_support',
124 ),
125 3
126 );
127
128 add_submenu_page(
129 'wpgmapembed',
130 esc_html__('Settings', 'gmap-embed'),
131 esc_html__('Settings', 'gmap-embed'),
132 $this->capability,
133 'wpgmapembed-settings',
134 array(
135 $this,
136 'wgm_settings',
137 ),
138 4
139 );
140 if (!_wgm_is_premium()) {
141 add_submenu_page(
142 'wpgmapembed',
143 // Escape HTML and URLs for security
144 // phpscs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
145 '<img draggable="false" role="img" class="emoji" alt="⭐" src="' . esc_url('https://s.w.org/images/core/emoji/13.0.1/svg/2b50.svg') . '"> ' . esc_html__('Upgrade to Pro', 'gmap-embed'),
146 // phpscs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
147 '<span style="color:yellow"><img draggable="false" role="img" class="emoji" alt="⭐" src="' . esc_url('https://s.w.org/images/core/emoji/13.0.1/svg/2b50.svg') . '"> ' . esc_html__('Upgrade to Pro', 'gmap-embed') . '</span>',
148 $this->capability,
149 esc_url('https://wpgooglemap.com/pricing?utm_source=gmap-embed&utm_medium=wordpress-plugin&utm_campaign=upgrade-to-pro&utm_content=admin-menu-link'),
150 false,
151 5
152 );
153 }
154 }
155
156 public function wgm_support()
157 {
158 require WGM_PLUGIN_PATH . 'admin/includes/wpgmap_support.php';
159 }
160
161
162 /**
163 * Google Map Embed Mail Page
164 */
165 public function srm_gmap_main()
166 {
167 if (
168 isset($_GET['tag']) &&
169 sanitize_text_field(wp_unslash($_GET['tag'])) === 'edit'
170 ) {
171 if (
172 isset($_GET['wgm_map_create_nonce']) &&
173 wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['wgm_map_create_nonce'])), 'wgm_create_map')
174 ) {
175 require WGM_PLUGIN_PATH . 'admin/includes/wpgmap_edit.php';
176 } else {
177 // Nonce missing or invalid for map edit action
178 $wgm_redirect_url = esc_url_raw(
179 add_query_arg(
180 array('page' => 'wpgmapembed'),
181 admin_url('admin.php')
182 )
183 );
184 wp_safe_redirect($wgm_redirect_url);
185 exit;
186 }
187 } else {
188 $this->render('admin/map-list', [], true);
189 }
190 }
191
192 /**
193 * Google Map Embed Mail Page
194 */
195 public function srm_gmap_new()
196 {
197 // Check if the user has the required capability to access this page
198 if (!current_user_can($this->capability)) {
199 wp_die(esc_html__('Unauthorized access. You do not have permission to view this page.', 'gmap-embed'));
200 }
201
202 // Check if the user can add a new map
203 if (!_wgm_can_add_new_map()) {
204 echo '<div class="message" style="margin-top:40px;">
205 <div id="setting-error-settings_updated" class="settings-error notice is-dismissible" style="border-left-color:red;">
206 <p style="font-size:15px;">
207 <strong>';
208 echo wp_kses(
209 sprintf(
210 /* translators: %s: premium version link */
211 __('You need to upgrade to the <a target="_blank" href="%s">Premium</a> Version to <b>Create Unlimited Maps</b>.', 'gmap-embed'),
212 esc_url('https://wpgooglemap.com/pricing?utm_source=gmap-embed&utm_medium=wordpress-plugin&utm_campaign=upgrade-to-pro&utm_content=admin-menu-add-new-map')
213 ),
214 array(
215 'a' => array(
216 'href' => array(),
217 'target' => array(),
218 'rel' => array(),
219 ),
220 'b' => array(),
221 'strong' => array(),
222 )
223 );
224 echo ' <a href="' . esc_url(admin_url('admin.php?page=wpgmapembed')) . '" style="margin-left:15px;">' . esc_html__('Back to Plugin Home', 'gmap-embed') . '</a>';
225 echo '</strong></p></div></div>';
226 exit;
227 }
228
229 // Initialize new map
230 $map_id = $this->initiate_new_map();
231
232 if (!is_numeric($map_id)) {
233 wp_die(esc_html__('Invalid map ID.', 'gmap-embed'));
234 }
235
236 $nonce = wp_create_nonce('wgm_create_map');
237 $redirect_url = add_query_arg(
238 array(
239 'page' => 'wpgmapembed',
240 'tag' => 'edit',
241 'id' => intval($map_id),
242 'wgm_map_create_nonce' => esc_attr($nonce),
243 ),
244 admin_url('admin.php')
245 );
246
247 echo '<script>window.location = ' . wp_json_encode($redirect_url) . ';</script>';
248 exit;
249 }
250
251 public function wgm_settings()
252 {
253 require WGM_PLUGIN_PATH . 'admin/includes/wpgmap_settings.php';
254 }
255
256 public function wgm_categories_page()
257 {
258 require_once WGM_PLUGIN_PATH . 'admin/includes/categories.php';
259 }
260 }
261