Repository navigation
feat(post-types): support sharing from additional public post types - #46
Merged
Merged
Conversation
Adds a "Post types" section to the settings page with a checkbox per public REST-exposed post type, defaulting to Posts only. Enabling a type makes it eligible for sharing, registers the Autoblue post meta against it, surfaces the Autoblue editor panel on its edit screen, and pulls Bluesky replies into its native comments thread. - Utils: new get_enabled_post_types(), get_available_post_types(), and sanitize_enabled_post_types() helpers. The sanitizer whitelists against live public+REST post types and drops 'attachment'. - Admin: register autoblue_enabled_post_types setting (array, default ['post']) with REST exposure and the Utils sanitizer. - Meta: loop register_post_meta over enabled post types instead of hardcoding 'post'. Dropped the "Add support for multiple post types" TODO. - PostHandler: replace hardcoded valid_post_types with the accessor. - Comments: replace hardcoded 'post' guard with the accessor so Bluesky replies appear on any enabled CPT's native comments. - Assets: ship availablePostTypes in initial state (it's static metadata, not a setting). - use-settings hook: surface enabledPostTypes / availablePostTypes / togglePostType, backed by useEntityProp on the new setting key. - editor.js: switch to a useIsEnabled hook backed by useEntityProp on the setting so the gate is reactive and consistent with how the existing autoblue_enabled toggle is read. Removes the awkward window.autoblue-vs-bare-autoblue scoping concerns. - use-shares hook: read the current post type's rest_base from the core store and use it in the poll path so the share-status refresh works on any enabled post type (was hardcoded to /wp/v2/posts/). - Settings page: new "Post types" section with a CheckboxControl per available post type. - Tests: new UtilsTest covers the accessor's defaults, stored values, non-array coercion, and the sanitizer's unknown-slug / attachment filtering. The existing global "Automatically share posts to Bluesky" toggle stays global - one default-on value still applies to every enabled post type. Toggling a CPT off in settings does not destructively clean up existing autoblue_shares meta on already-shared content.
The endpoint is manage_options-only, the REST schema already validates 'array of strings', and bogus slugs in the option are harmless (none of the consumers care). The whitelist/intersect also introduced a subtle race with late-registered CPTs. Relying on the schema is simpler and equally safe.
7 of 8 tasks
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 "Post types" section to the settings page with a checkbox per public, REST-exposed post type — defaulting to Posts only. Enabling a type makes it eligible for sharing, registers Autoblue's post meta against it, surfaces the Autoblue editor panel on its edit screen, and pulls Bluesky replies into its native comments thread.
Closes the long-standing
// TODO: Add support for multiple post types.inPostHandlerandeditor.js.Backend
Utils— newget_enabled_post_types(),get_available_post_types(), andsanitize_enabled_post_types()helpers. The sanitizer whitelists against the live public+REST post-type list and dropsattachment(sharing media files isn't the use case).Admin— registersautoblue_enabled_post_typessetting (array, default['post']) with REST exposure and the Utils sanitizer.Meta—register_post_metanow loops over enabled post types instead of hardcoding'post'.PostHandler— replaces the hardcodedvalid_post_typesguard with the accessor.Comments— replaces the hardcoded'post'guard with the accessor so Bluesky replies surface on any enabled CPT's native comments thread.Frontend
Assets— shipsavailablePostTypesin the initial state (static metadata, not a setting).useSettingshook — surfacesenabledPostTypes/availablePostTypes/togglePostType, backed byuseEntityPropon the new setting key (same pattern as the existingautoblue_enabled).BaseControlsection with aCheckboxControlper available post type.editor.js— switched to auseIsEnabledhook backed byuseEntityPropso the gate is reactive and consistent with how the existing toggle is read. (Initial attempt used the inline-script initial state, butconst autoblue = …creates a script-scoped lexical binding, not awindowproperty — the store-backed approach sidesteps that entirely.)useShareshook — reads the current post type'srest_basefrom thecorestore and uses it in the poll path so the editor's post-publish status refresh works for any post type (was hardcoded to/wp/v2/posts/${id}, which 404'd on pages).Confirmed design decisions
autoblue_sharesmeta on already-shared content.Test plan
vendor/bin/codecept run wpunit— 44 tests / 104 assertions, all green (includes 5 newUtilsTestcases covering the accessor's defaults, stored values, non-array coercion, and the sanitizer's unknown-slug / attachment filtering)npm run build— cleanvendor/bin/phpcs— cleanwp option get autoblue_enabled_post_typesreturns['post']by defaultGET /wp/v2/settingsexposes the new key with the array shapeUtils::get_available_post_types()lists Posts + Pages (attachment correctly filtered)attachment/wp-admin/post-new.php?post_type=page, the toggle works, and publishing a page with sharing on writes the autoblue_shares meta (404 on the post-publish status refresh confirmed fixed)