" height="50vh"]. * * The reach-everywhere surface: the classic editor, a Text widget, and the * shortcode or text module of every page builder. The block is nicer where * there is a block editor; this is what works where there is not. */ class Shortcode { /** * Shared embed renderer. * * @var Embed */ private Embed $embed; /** * Constructor. * * @param Embed $embed Shared embed renderer. */ public function __construct( Embed $embed ) { $this->embed = $embed; } /** * Registers the shortcode. */ public function register(): void { add_shortcode( 'mapsemble', array( $this, 'render' ) ); } /** * Renders the shortcode. * * @param array|string $atts Shortcode attributes. */ public function render( $atts ): string { $atts = shortcode_atts( array( 'id' => '', // A Mapsemble map id (or "sample"), for embedding a map this // site has no configuration post for. 'map' => '', 'height' => '', 'scroll_capture' => '', 'scroll_offset_top' => '', 'scroll_offset_bottom' => '', 'fill_viewport' => '', // A JSON object, single-quoted in practice so the editor does // not texturize its double quotes: // [mapsemble id="1" filters='{"category":"parks"}']. 'filters' => '', ), is_array( $atts ) ? $atts : array(), 'mapsemble' ); if ( '' !== (string) $atts['id'] && '' !== (string) $atts['map'] ) { // An explicit refusal beats a silent precedence rule: whichever // attribute would have won, the author meant the other one. return current_user_can( \Mapsemble\Capabilities::EDIT_MAPS ) ? '
' . esc_html__( 'Mapsemble: use either id (a map built from this site) or map (a Mapsemble map id), not both.', 'mapsemble' ) . '
' : ''; } $args = array( 'height' => (string) $atts['height'], 'scroll_capture' => (string) $atts['scroll_capture'], 'scroll_offset_top' => (string) $atts['scroll_offset_top'], 'scroll_offset_bottom' => (string) $atts['scroll_offset_bottom'], 'fill_viewport' => (string) $atts['fill_viewport'], 'filters' => (string) $atts['filters'], ); return '' !== (string) $atts['map'] ? $this->embed->render_by_map_id( (string) $atts['map'], $args ) : $this->embed->render( (int) $atts['id'], $args ); } }