%s', esc_url( admin_url( 'options-general.php?page=' . self::PAGE_SLUG ) ), esc_html__( 'Settings', 'insight-maps' ) ) ); return $links; } /** * Send the previous settings URL to the current screen. */ public function redirect_legacy_settings_page() { if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { return; } $page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( ! is_string( $page ) || 'dynamic-osm-maps' !== sanitize_key( $page ) ) { return; } $args = array( 'page' => self::PAGE_SLUG, ); $legacy_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( is_string( $legacy_tab ) && '' !== $legacy_tab ) { $args['tab'] = sanitize_key( $legacy_tab ); } wp_safe_redirect( add_query_arg( $args, admin_url( 'options-general.php' ) ) ); exit; } /** * Register the settings submenu. */ public function register_menu() { add_options_page( __( 'Insight Maps', 'insight-maps' ), __( 'Insight Maps', 'insight-maps' ), 'manage_options', self::PAGE_SLUG, array( $this, 'render_page' ) ); } /** * Enqueue admin styles. * * @param string $hook_suffix Current admin page hook. */ public function enqueue_assets( $hook_suffix ) { if ( 'settings_page_' . self::PAGE_SLUG !== $hook_suffix ) { return; } wp_enqueue_style( 'insight-maps-admin', INSIGHT_MAPS_URL . 'assets/admin.css', array(), INSIGHT_MAPS_VERSION ); } /** * Save settings tab form. */ public function handle_settings_save() { if ( ! isset( $_POST['insight_maps_settings_nonce'] ) ) { return; } if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['insight_maps_settings_nonce'] ) ), 'insight_maps_settings_save' ) ) { return; } if ( ! current_user_can( 'manage_options' ) ) { return; } $payload = array( 'render_in_editor' => ! empty( $_POST['insight_maps_render_in_editor'] ), 'marker_preset' => isset( $_POST['insight_maps_marker_preset'] ) ? sanitize_key( wp_unslash( $_POST['insight_maps_marker_preset'] ) ) : 'default', 'tile_url' => isset( $_POST['insight_maps_tile_url'] ) ? sanitize_text_field( wp_unslash( $_POST['insight_maps_tile_url'] ) ) : '', ); /** * Filter settings payload before save (Pro may add popup logo height). * * @param array $payload Settings payload. */ $payload = apply_filters( 'insight_maps_settings_save_payload', $payload ); if ( ! is_array( $payload ) ) { $payload = array(); } Insight_Maps_Plugin_Settings::update_settings( $payload ); add_settings_error( 'insight_maps', 'insight_maps_settings_saved', __( 'Settings saved.', 'insight-maps' ), 'success' ); } /** * Settings tabs (slug => label). * * @return array */ private function get_settings_tabs() { $tabs = array( 'guide' => __( 'Guide', 'insight-maps' ), 'settings' => __( 'Settings', 'insight-maps' ), ); /** * Filter Insight Maps settings tabs (Pro may add Licence & Support). * * @param array $tabs Tab slug => label. */ $tabs = apply_filters( 'insight_maps_settings_tabs', $tabs ); return is_array( $tabs ) ? $tabs : array(); } /** * Active tab slug. * * @return string */ private function get_active_tab() { $tabs = $this->get_settings_tabs(); $allowed = array_keys( $tabs ); $tab = 'settings'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Tab is display-only; no privileged action. if ( isset( $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tab = sanitize_key( wp_unslash( $_GET['tab'] ) ); } elseif ( isset( $_POST['insight_maps_active_tab'], $_POST['insight_maps_settings_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['insight_maps_settings_nonce'] ) ), 'insight_maps_settings_save' ) ) { $tab = sanitize_key( wp_unslash( $_POST['insight_maps_active_tab'] ) ); } if ( ! in_array( $tab, $allowed, true ) ) { $tab = isset( $tabs['settings'] ) ? 'settings' : (string) array_key_first( $tabs ); } return $tab; } /** * Build a tab URL. * * @param string $tab Tab slug. * @return string */ public function get_tab_url( $tab ) { return add_query_arg( array( 'page' => self::PAGE_SLUG, 'tab' => $tab, ), admin_url( 'options-general.php' ) ); } /** * Render the settings page. */ public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } settings_errors( 'insight_maps' ); /** * Extra settings errors (e.g. from the Pro add-on). */ do_action( 'insight_maps_settings_errors' ); $tabs = $this->get_settings_tabs(); $active_tab = $this->get_active_tab(); ?>

render_guide_tab(); } else { $this->render_settings_tab(); } } ?>

  • Insight Maps Pro.', 'insight-maps' ), esc_url( insight_maps_pro_url() ) ) ); ?>

' . esc_html( Insight_Maps_Tile_Provider::DEFAULT_URL_TEMPLATE ) . '' ) ); ?>