plugin_name),
esc_html($this->plugin_name),
$this->capability,
'wpgmapembed',
array(
$this,
'srm_gmap_main',
),
'dashicons-location',
11
);
add_submenu_page(
'wpgmapembed',
esc_html__('All Maps', 'gmap-embed'),
esc_html__('All Maps', 'gmap-embed'),
$this->capability,
'wpgmapembed',
array(
$this,
'srm_gmap_main',
),
0
);
// to create sub menu
if (_wgm_can_add_new_map()) {
add_submenu_page(
'wpgmapembed',
esc_html__('Add new Map', 'gmap-embed'),
esc_html__('Add New', 'gmap-embed'),
$this->capability,
'wpgmapembed-new',
array(
$this,
'srm_gmap_new',
),
1
);
} else {
if (
isset($_GET['page']) &&
sanitize_key(wp_unslash($_GET['page'])) === 'wpgmapembed-new'
) {
// If a nonce is present, verify it. If invalid, block the request.
// If no nonce is present, this is a simple redirect and no further check is required.
if ( ! empty( $_REQUEST['_wpnonce'] ) ) {
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
if ( ! wp_verify_nonce( $nonce, 'wgm_add_new_map' ) ) {
wp_die( esc_html__( 'Security check failed.', 'gmap-embed' ) );
}
}
// If the user tries to access the "Add New" page without permission, redirect them to the main page
$redirect_url = esc_url_raw(
add_query_arg(
array( 'page' => 'wpgmapembed' ),
admin_url( 'admin.php' )
)
);
wp_safe_redirect( $redirect_url );
exit;
}
}
add_submenu_page(
'wpgmapembed',
esc_html__('Categories', 'gmap-embed'),
esc_html__('Categories', 'gmap-embed'),
$this->capability,
'wpgmapembed-categories',
array(
$this,
'wgm_categories_page',
),
2
);
// setup wizard menu
add_submenu_page(
'wpgmapembed',
esc_html__('Quick Setup', 'gmap-embed'),
esc_html__('Quick Setup', 'gmap-embed'),
$this->capability,
'wgm_setup_wizard',
array(
$this,
'wpgmap_setup_wizard',
),
3
);
add_submenu_page(
'wpgmapembed',
esc_html__('Support', 'gmap-embed'),
esc_html__('Support', 'gmap-embed'),
$this->capability,
'wpgmapembed-support',
array(
$this,
'wgm_support',
),
3
);
add_submenu_page(
'wpgmapembed',
esc_html__('Settings', 'gmap-embed'),
esc_html__('Settings', 'gmap-embed'),
$this->capability,
'wpgmapembed-settings',
array(
$this,
'wgm_settings',
),
4
);
if (!_wgm_is_premium()) {
add_submenu_page(
'wpgmapembed',
// Escape HTML and URLs for security
// phpscs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
' ' . esc_html__('Upgrade to Pro', 'gmap-embed'),
// phpscs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage
'
' . esc_html__('Upgrade to Pro', 'gmap-embed') . '',
$this->capability,
esc_url('https://wpgooglemap.com/pricing?utm_source=gmap-embed&utm_medium=wordpress-plugin&utm_campaign=upgrade-to-pro&utm_content=admin-menu-link'),
false,
5
);
}
}
public function wgm_support()
{
require WGM_PLUGIN_PATH . 'admin/includes/wpgmap_support.php';
}
/**
* Google Map Embed Mail Page
*/
public function srm_gmap_main()
{
if (
isset($_GET['tag']) &&
sanitize_text_field(wp_unslash($_GET['tag'])) === 'edit'
) {
if (
isset($_GET['wgm_map_create_nonce']) &&
wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['wgm_map_create_nonce'])), 'wgm_create_map')
) {
require WGM_PLUGIN_PATH . 'admin/includes/wpgmap_edit.php';
} else {
// Nonce missing or invalid for map edit action
$wgm_redirect_url = esc_url_raw(
add_query_arg(
array('page' => 'wpgmapembed'),
admin_url('admin.php')
)
);
wp_safe_redirect($wgm_redirect_url);
exit;
}
} else {
$this->render('admin/map-list', [], true);
}
}
/**
* Google Map Embed Mail Page
*/
public function srm_gmap_new()
{
// Check if the user has the required capability to access this page
if (!current_user_can($this->capability)) {
wp_die(esc_html__('Unauthorized access. You do not have permission to view this page.', 'gmap-embed'));
}
// Check if the user can add a new map
if (!_wgm_can_add_new_map()) {
echo '