%1$s

%2$s %3$s', esc_html__( 'You are using a custom Google Maps API key.', 'the-events-calendar' ), esc_html__( 'Click here', 'the-events-calendar' ), esc_html__( 'to learn more about using it with The Events Calendar', 'the-events-calendar' ) ); if ( tribe_is_using_basic_gmaps_api() ) { $tooltip = $this->get_basic_embed_api_tooltip(); } $gmaps_api_fields = [ 'gmaps-js-api-start' => [ 'type' => 'html', 'html' => '

' . esc_html__( 'Google Maps API', 'the-events-calendar' ) . '

', ], 'gmaps-js-api-info-box' => [ 'type' => 'html', 'html' => '

' . sprintf( __( 'The Events Calendar comes with an API key for basic maps functionality. If you’d like to use more advanced features like custom map pins or dynamic map loads, you’ll need to get your own %1$s. %2$s.', 'the-events-calendar' ), '' . esc_html__( 'Google Maps API key', 'the-events-calendar' ) . '', '' . esc_html__( 'Read more', 'the-events-calendar' ) . '' ) . '

', ], self::$api_key_option_name => [ 'type' => 'text', 'label' => esc_html__( 'Google Maps API key', 'the-events-calendar' ), 'tooltip' => $tooltip, 'size' => 'medium', 'validation_type' => 'alpha_numeric_with_dashes_and_underscores', 'can_be_empty' => true, 'parent_option' => Tribe__Events__Main::OPTIONNAME, ], ]; return array_merge( (array) $addon_fields, $gmaps_api_fields ); } /** * Generates the tooltip text for when The Events Calendar's fallback API key is being used instead of a custom one. * * @since 4.6.24 * * @return string */ public function get_basic_embed_api_tooltip() { return sprintf( '

%1$s

%2$s %3$s.

%4$s %5$s

', esc_html__( 'You are using The Events Calendar\'s built-in Google Maps API key.', 'the-events-calendar' ), esc_html__( 'If you do not add your own API key, the built-in API key will always populate this field and some map-related functionality will be limited ', 'the-events-calendar' ), esc_html__( '(click here for details)', 'the-events-calendar' ), esc_html__( 'Click here', 'the-events-calendar' ), esc_html__( 'to create your own free Google Maps API key.', 'the-events-calendar' ) ); } /** * Adds the browser key api key to the Google Maps JavaScript API url if set by the user. * * @param string $js_maps_api_url * * @return string */ public function filter_tribe_events_google_maps_api( $js_maps_api_url ) { $key = tribe_get_option( self::$api_key_option_name, self::$default_api_key ); if ( ! empty( $key ) ) { $js_maps_api_url = add_query_arg( 'key', $key, $js_maps_api_url ); } return $js_maps_api_url; } public function filter_tribe_events_pro_google_maps_api( $js_maps_api_url ) { } /** * Ensures the Google Maps API Key field in Settings > APIs is always populated with TEC's * default API key if no user-supplied key is present. * * @since 4.6.24 * * @param string $value_string The original HTML string for the input's value attribute. * @param string $field_name The name of the field; usually the key of the option it's associated with. * @return string The default license key as the input's new value. */ public function populate_field_with_default_api_key( $value_string, $field_name ) { if ( ! isset( $field_name ) || self::$api_key_option_name !== $field_name ) { return $value_string; } if ( empty( $value_string ) ) { remove_filter( 'tribe_field_value', [ $this, 'populate_field_with_default_api_key' ], 10, 2 ); $value_string = self::$default_api_key; tribe_update_option( self::$api_key_option_name, self::$default_api_key ); add_filter( 'tribe_field_value', [ $this, 'populate_field_with_default_api_key' ], 10, 2 ); } return $value_string; } /** * Ensures the Google Maps API Key field in Settings > APIs shows the correct tooltip text, especially when * the auto-populating of the field is done via populate_field_with_default_api_key(). * * @since 4.6.24 * * @param string $tooltip_string The original HTML string for the input's tooltip attribute. * @param string $field_name The name of the field; usually the key of the option it's associated with. * @return string The default license key as the input's new value. */ public function populate_field_tooltip_with_helper_text( $tooltip_string, $field_name ) { if ( ! isset( $field_name ) || self::$api_key_option_name !== $field_name ) { return $tooltip_string; } $api_key = tribe_get_option( self::$api_key_option_name, self::$default_api_key ); if ( empty( $api_key ) || self::$default_api_key === $api_key ) { $tooltip_string = $this->get_basic_embed_api_tooltip(); } return $tooltip_string; } }