feat: datamachine_socials_platform_priority filter for ordering /platforms response#132
Merged
Conversation
…m slugs to top of /platforms response
Contributor
Homeboy Results —
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
datamachine_socials_platform_priorityfilter so any plugin can pin platform slugs to the top of the/datamachine/v1/socials/platformsresponse in declared order. Default behavior unchanged when nothing hooks the filter.This is PR D of a 2-PR pair — extrachill-studio#25 hooks the filter to pin Instagram first.
Background
The previous
/platformscontract sorted platforms(authenticated DESC, label ASC). That's the right default but not the right answer for every consumer. Studio wants Instagram pinned to the top because Extra Chill's social workflow centers on Instagram.Two approaches were considered:
We picked the filter primitive.
Filter contract
Returns an ordered
string[]of platform slugs. Slugs not in the list fall through to the default sort (authenticated → A-Z).Behavior
Pinned + unauthenticated
Pinned slugs bypass the authenticated-first rule. If a caller pins an unauthenticated platform, it still appears at the top. This honors caller intent. Clients that only want to render authenticated platforms should filter on
authenticatedthemselves (Studio's React already does this).Defensive normalization
The filter result is run through
array_filter(array_map('strval', ...))andarray_values(...)so plugins can't accidentally inject non-strings or sparse arrays. Empty/invalid filter results fall back to the default sort.Verified locally
With
add_filter('datamachine_socials_platform_priority', fn($p) => array_merge(['instagram'], $p)):Without the filter (default behavior): unchanged from v0.13.0.
Test plan
php -lclean