diff --git a/README.md b/README.md index 0dba242..b08a2b6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A Mapbox-backed WordPress map block. Markers are child blocks holding a coordinate pair plus arbitrary content, revealed either as a carousel of slides beside/below the map or as popup cards inside it. -Extracted and generalized from the map functionality we built for the Wikimedia Foundation's digital-first annual reports. +Extracted and generalized from the map functionality built for the Wikimedia Foundation's [digital-first annual reports plugin](https://github.com/wikimedia/wikimedia-wordpress-annual-report-plugin/). ## Features @@ -41,19 +41,6 @@ The blocks work out of the box, but visual design is intentionally left to the i - **JS events**: the block wrapper dispatches `hm-map:ready` (detail: `{ map }`) and `hm-map:pin-activate` (detail: `{ index }`) CustomEvents for site code to hook into. - **Content Security Policy**: if your site sends a CSP, allow `https://api.mapbox.com` in `script-src`/`style-src`, `https://api.mapbox.com https://events.mapbox.com` in `connect-src`, and `blob:` in `worker-src` (Mapbox GL uses web workers). -## Migrating from the annual report plugin - -Content authored with `wmf-reports/map` and `wmf-reports/marker` keeps rendering on the frontend: the legacy block names are registered against the current render templates (editor support is not provided for the legacy names). - -To migrate stored content to the new format, run: - -``` -wp hm-map migrate --dry-run # report what would change -wp hm-map migrate # rewrite block names, slide classes, and copy the API key option -``` - -The command rewrites the block delimiters, renames the `wmf-pattern-reports-carousel-slide` class to `hm-map-slide`, and copies the `wmf-map-api-key` option to `hm_map_api_key` if unset. `wmf-reports/overlay` blocks (a separate feature of the source plugin) are left untouched. Note the default map style is now Mapbox Light rather than Wikimedia's custom style; set a Custom style URI on migrated maps if the old look is required. - ## Development ### Build commands diff --git a/inc/assets.php b/inc/assets.php index fb67dfd..832f6fe 100644 --- a/inc/assets.php +++ b/inc/assets.php @@ -23,7 +23,6 @@ function bootstrap(): void { // Enqueue frontend assets when a map actually renders: has_block() based // checks miss archive and home views which render many posts. add_filter( 'render_block_hm/map', __NAMESPACE__ . '\\enqueue_frontend_assets', 10, 2 ); - add_filter( 'render_block_wmf-reports/map', __NAMESPACE__ . '\\enqueue_frontend_assets', 10, 2 ); } /** @@ -80,8 +79,8 @@ function enqueue_editor_mapbox_styles(): void { /** * Enqueue Mapbox styles and localize the API key when a map block renders. * - * Runs on the render_block filter for both current and legacy block names, - * which fires before footer scripts print regardless of the query type. + * Runs on the render_block filter, which fires before footer scripts print + * regardless of the query type. * * @param string $block_content Rendered block markup. * @param array $block Parsed block, including attributes. diff --git a/inc/cli.php b/inc/cli.php deleted file mode 100644 index cf4732b..0000000 --- a/inc/cli.php +++ /dev/null @@ -1,110 +0,0 @@ - '' => '', - '' => '', - '' => '', - '' => '', - // Pattern-era class names referenced by the plugin styles. - 'wmf-pattern-reports-carousel-slide' => 'hm-map-slide', - ]; - - $query = new WP_Query( [ - 'post_type' => 'any', - 'post_status' => 'any', - 'posts_per_page' => -1, - 'fields' => 'ids', - 's' => 'wp:wmf-reports/map', - ] ); - - $updated = 0; - foreach ( $query->posts as $post_id ) { - $content = get_post_field( 'post_content', $post_id ); - $migrated = str_replace( - array_keys( $replacements ), - array_values( $replacements ), - $content - ); - - if ( $migrated === $content ) { - continue; - } - - ++$updated; - if ( $dry_run ) { - WP_CLI::log( sprintf( 'Would migrate post %d (%s).', $post_id, get_the_title( $post_id ) ) ); - continue; - } - - wp_update_post( [ - 'ID' => $post_id, - 'post_content' => wp_slash( $migrated ), - ] ); - WP_CLI::log( sprintf( 'Migrated post %d (%s).', $post_id, get_the_title( $post_id ) ) ); - } - - // Copy the legacy API key option unless a new key is already stored. - $legacy_key = get_option( LEGACY_OPTION_KEY, '' ); - if ( ! empty( $legacy_key ) && empty( get_option( \HM\MapBlock\Settings\MAP_API_OPTION_KEY, '' ) ) ) { - if ( $dry_run ) { - WP_CLI::log( 'Would copy the legacy API key option to ' . \HM\MapBlock\Settings\MAP_API_OPTION_KEY . '.' ); - } else { - update_option( \HM\MapBlock\Settings\MAP_API_OPTION_KEY, $legacy_key ); - WP_CLI::log( 'Copied the legacy API key option to ' . \HM\MapBlock\Settings\MAP_API_OPTION_KEY . '.' ); - } - } - - WP_CLI::success( - $dry_run - ? sprintf( '%d posts would be migrated.', $updated ) - : sprintf( '%d posts migrated.', $updated ) - ); -} diff --git a/inc/compat.php b/inc/compat.php deleted file mode 100644 index 58bd64b..0000000 --- a/inc/compat.php +++ /dev/null @@ -1,90 +0,0 @@ - [ 'hm/map', 'map/render.php' ], - 'wmf-reports/marker' => [ 'hm/map-marker', 'marker/render.php' ], - ]; - - foreach ( $legacy_map as $legacy_name => [ $current_name, $render_file ] ) { - $current = $registry->get_registered( $current_name ); - if ( ! $current || $registry->is_registered( $legacy_name ) ) { - continue; - } - - $template = \HM\MapBlock\PLUGIN_PATH . '/build/blocks/' . $render_file; - - register_block_type( $legacy_name, [ - 'attributes' => $current->attributes, - // Reuse the current blocks' frontend assets. - 'view_script_handles' => $current->view_script_handles, - 'style_handles' => $current->style_handles, - 'render_callback' => function ( array $attributes, string $content, WP_Block $block ) use ( $template ): string { - $html = render_template( $template, $attributes, $content, $block ); - - // The generated wrapper class follows the legacy block name; - // add the current classes so plugin styles and scripts match. - // Lookbehinds keep this idempotent when the map block - // re-processes marker markup already handled by the marker's - // own callback. Marker first: the map class is a prefix of - // the marker class. - $html = preg_replace( - '/(?