coordinates = $coordinates; } /** * Hooks the source up. */ public function register(): void { add_filter( 'mapsemble_location_sources', static function ( array $sources ): array { $sources[ MapConfig::SOURCE_META_KEYS ] = __( 'Custom fields (latitude/longitude meta keys)', 'mapsemble' ); return $sources; } ); add_action( 'mapsemble_map_form_location_fields', array( $this, 'render_key_fields' ) ); // Priority 20, mirroring the ACF hook: after whatever wrote the // source meta for this save has finished. add_action( 'save_post', array( $this, 'mirror_on_save' ), 20 ); } /** * Renders the two key inputs in the map config form. * * @param MapConfig $config The config being edited. */ public function render_key_fields( MapConfig $config ): void { // The data attribute lets the edit screen script disable and hide // the inputs while another source is chosen; without the script // they stay usable. ?>


coordinates->find_config_for_post( $post_id ); if ( null === $config || MapConfig::SOURCE_META_KEYS !== $config->location_source || '' === $config->lat_meta_key || '' === $config->lng_meta_key ) { return; } $this->coordinates->write( $post_id, $this->coordinates->read_from_meta_keys( $post_id, $config->lat_meta_key, $config->lng_meta_key ) ); } }