ExpressMaps page (Settings API). * * Options stored in wp_options: * - expressmaps_api_key (string) * - expressmaps_default_style (string, one of expressmaps_get_styles()) * * @package ExpressMaps */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Register options, section and fields. */ function expressmaps_register_settings() { register_setting( 'expressmaps_settings', 'expressmaps_api_key', array( 'type' => 'string', 'sanitize_callback' => 'expressmaps_sanitize_api_key', 'default' => '', 'show_in_rest' => false, ) ); register_setting( 'expressmaps_settings', 'expressmaps_default_style', array( 'type' => 'string', 'sanitize_callback' => 'expressmaps_sanitize_style', 'default' => 'standard', 'show_in_rest' => false, ) ); add_settings_section( 'expressmaps_main', __( 'API settings', 'expressmaps' ), 'expressmaps_settings_section_text', 'expressmaps' ); add_settings_field( 'expressmaps_api_key', __( 'API key', 'expressmaps' ), 'expressmaps_field_api_key', 'expressmaps', 'expressmaps_main', array( 'label_for' => 'expressmaps_api_key' ) ); add_settings_field( 'expressmaps_default_style', __( 'Default map style', 'expressmaps' ), 'expressmaps_field_default_style', 'expressmaps', 'expressmaps_main', array( 'label_for' => 'expressmaps_default_style' ) ); } add_action( 'admin_init', 'expressmaps_register_settings' ); /** * Add the Settings > ExpressMaps menu entry. */ function expressmaps_add_settings_page() { add_options_page( __( 'ExpressMaps', 'expressmaps' ), __( 'ExpressMaps', 'expressmaps' ), 'manage_options', 'expressmaps', 'expressmaps_render_settings_page' ); } add_action( 'admin_menu', 'expressmaps_add_settings_page' ); /** * Section intro text. */ function expressmaps_settings_section_text() { echo '

'; printf( wp_kses( /* translators: 1: ExpressMaps console URL, 2: ExpressMaps signup URL */ __( 'Create an API key in the ExpressMaps console and restrict it to this site\'s domain. No account yet? Sign up — the free plan includes 100,000 map loads a month, no card needed.', 'expressmaps' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ) ), esc_url( 'https://www.expressmaps.com/console/keys' ), esc_url( 'https://www.expressmaps.com/signup' ) ); echo '

'; } /** * API key field. */ function expressmaps_field_api_key() { $key = expressmaps_get_api_key(); printf( '', esc_attr( $key ) ); echo '

'; esc_html_e( 'The key is sent to visitors\' browsers as part of the map style URL, so restrict it to your domain in the console.', 'expressmaps' ); echo '

'; } /** * Default style field. */ function expressmaps_field_default_style() { $current = expressmaps_get_default_style(); echo ''; echo '

'; esc_html_e( 'Used when a shortcode or block does not specify a style.', 'expressmaps' ); echo '

'; } /** * Settings page markup. settings_fields() outputs the nonce and option_page fields. */ function expressmaps_render_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } ?>

[expressmaps lat="51.5" lng="-0.12" zoom="13" style="standard" height="400px" marker="true" popup="Our office"]