Repository navigation
Add a filter for static OpenStreetMap marker colors - #2651
faisalahammad wants to merge 1 commit into
Conversation
- 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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Preview changes with PlaygroundCustomize PR PlaygroundTo customize the Playground preview for this specific PR, create a file at:
The override is merged into the generated blueprint and can be used to:
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.4PHP Version 8.2PHP Version 8.1Download Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions. |
Test Coverage Report✅ All coverage checks passed! ✅ PHP Coverage✅ JavaScript CoverageThis comment is automatically updated on each push. |
wppoland
left a comment
There was a problem hiding this comment.
LGTM! Clean, well-tested implementation:
OSM::DEFAULT_MARKER_COLORSandget_marker_colors()validate each key throughsanitize_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 fromDEFAULT_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 indocs/developer/theme-customizations/README.md.
Fixes #2082
Proposed changes:
gatherpress_static_map_marker_colorsfilter. It takes hex colors for theborder,fill,outlineandcenterparts of the marker thatOSM::stamp_marker()draws on static OpenStreetMap images. Both the 1x and 2x images use it.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).docs/developer/theme-customizations/README.md, next to the CSS property for the interactive marker.Example:
Other information:
AI assistance
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:
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
The entry is added manually in
.github/changelog/2082-static-map-marker-colors.