Skip to content

Add a filter for static OpenStreetMap marker colors - #2651

Open
faisalahammad wants to merge 1 commit into
GatherPress:developfrom
faisalahammad:enhancement/2082-static-osm-marker-filter
Open

faisalahammad wants to merge 1 commit into
GatherPress:developfrom
faisalahammad:enhancement/2082-static-osm-marker-filter

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2082

Proposed changes:

  • Add the gatherpress_static_map_marker_colors filter. It takes hex colors for the border, fill, outline and center parts of the marker that OSM::stamp_marker() draws on static OpenStreetMap images. Both the 1x and 2x images use it.
  • A key that is missing, or a value that is not a valid hex color, keeps its default. A filter that returns something other than an array gives the default marker.
  • OSM::get_cache_source() now includes the marker colors, but only when they differ from the default. Saved maps render again after a color change, and sites that keep the default marker keep their saved images (same hash).
  • Document the filter in docs/developer/theme-customizations/README.md, next to the CSS property for the interactive marker.

Example:

add_filter(
	'gatherpress_static_map_marker_colors',
	static function ( array $colors ): array {
		$colors['fill'] = '#2271b1';

		return $colors;
	}
);

Other information:

  • Have you written new tests for your changes, if applicable?

AI assistance

  • An AI tool wrote a significant part of this change.

Testing instructions:

Setup: set the map platform to OpenStreetMap under GatherPress > Settings > Venues. Create a venue with an address, then an event with that venue and a Venue Map block with render mode set to Static. Publish.

  • View the event. The marker is the default red one with a white ring, and the saved image file name is the same as before the update.

  • Add this mu-plugin and reload:

    <?php
    add_filter(
    	'gatherpress_static_map_marker_colors',
    	static function ( array $colors ): array {
    		$colors['fill']   = '#2271b1';
    		$colors['center'] = '#ffcc00';
    
    		return $colors;
    	}
    );

    The marker body is blue and the center dot is yellow, on both the 1x and 2x images. The image has a new file name.

  • Change the fill to 'blue' (not hex). The body goes back to red, and the center stays yellow.

  • Make the filter return 'oops';. The default marker shows, with no PHP error.

  • Remove the mu-plugin. The default marker comes back.

Credit (for release notes)

My WordPress.org username: faisal03

Changelog entry

  • Automatically create a changelog entry from the details below.

The entry is added manually in .github/changelog/2082-static-map-marker-colors.

- Add the gatherpress_static_map_marker_colors filter for the border,
  fill, outline and center colors of the static OpenStreetMap marker.
- Fall back to the default color for any missing or invalid hex value.
- Add the colors to the cache source only when they are not the
  default, so saved maps render again after a change and existing
  maps keep their hash.
- Document the filter in the theme customizations guide.
- Add unit tests for the filter, the color parsing and the cache source.

CSS cannot reach the marker on a static map because it is drawn into
the image on the server. Sites that change the interactive marker had
no way to match it on static maps.

Fixes GatherPress#2082
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad, linewebdigital.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown
Contributor

Preview changes with Playground

Customize PR Playground

To customize the Playground preview for this specific PR, create a file at:

.github/playground/PR-2651-blueprint-override.json

The override is merged into the generated blueprint and can be used to:

  • Enable Playground features
  • Install additional plugins
  • Change site options
  • Run steps before or after the GatherPress' default steps

Example:

{
	"$schema": "https://gatherpress.org/playground-preview/pr-override-schema.json",
	"landingPage": "/wp-admin/edit.php?post_type=gatherpress_venue",
	"siteOptions": {
		"show_on_front": "page"
	},
	"features": {
		"networking": true
	},
	"prependSteps": [
		{
			"step": "installPlugin",
			"pluginData": {
				"resource": "wordpress.org/plugins",
				"slug": "simple-location"
			},
			"options": {
				"activate": true
			}
		}
	],
	"appendSteps": [
		{
			"step": "runPHP",
			"code": ""
		}
	]
}

Go to Playground PR preview customization for more details.

You can preview the recent changes for PR#2651 with the following PHP versions:

PHP Version 8.4

PHP Version 8.2

PHP Version 8.1

Download .zip with build changes

Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions.

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Report

✅ All coverage checks passed!

✅ PHP Coverage
=== PR Coverage Check ===

Configuration loaded:
  Minimum coverage: 100%
  Exclude patterns: 47 patterns
  Low coverage exceptions: 0 files

Checking coverage for files changed from origin/develop...

Found 2 changed PHP file(s):
  - includes/core/classes/venue/map/provider/class-osm.php
  - test/unit/php/includes/tests/core/classes/venue/map/provider/class-test-osm.php

Files requiring coverage check: 1
  - includes/core/classes/venue/map/provider/class-osm.php

✅ Loaded coverage.xml
✅ Loaded coverage-multisite.xml

✅ includes/core/classes/venue/map/provider/class-osm.php - 100% coverage (142/142 lines)

=== Summary ===
✅ Passed: 1 file(s)
⏭️  Excluded: 1 file(s)
❌ Failed: 0 file(s)

✅ All changed files meet the minimum coverage requirement of 100%
✅ JavaScript Coverage
=== PR JavaScript Coverage Check ===

Configuration loaded:
  Minimum coverage: 100%
  Exclude patterns: 47 patterns

Checking coverage for JavaScript files changed from origin/develop...

✅ No JavaScript files changed in this PR.

This comment is automatically updated on each push.

@mauteri mauteri added this to the 0.38.0 milestone Nov 19, 2026

@wppoland wppoland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Clean, well-tested implementation:

  • OSM::DEFAULT_MARKER_COLORS and get_marker_colors() validate each key through sanitize_hex_color() and fall back per key to the default color when missing or invalid.
  • allocate_hex_color() handles both 3-digit and 6-digit hex strings cleanly.
  • get_cache_source() only appends |marker=... when the colors differ from DEFAULT_MARKER_COLORS, preserving existing cached static map hashes on sites using the default marker.
  • Thorough unit test coverage in class-test-osm.php (1x and 2x scale pixel checks, invalid/non-array filter values, 3-digit/6-digit hex allocation, and cache source hash behavior) plus clear documentation in docs/developer/theme-customizations/README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow static OpenStreetMap marker styling through a server-side extension point

3 participants