-
Notifications
You must be signed in to change notification settings - Fork 1
Split publish/cleanup gates so allowlist changes don't orphan remote records #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b8af4e7
fix: split publish and cleanup gates in on_status_change/on_before_de…
kraftbj 4f5c2fd
Merge branch 'trunk' into fix/cleanup-gate-split
pfefferle 36cb086
Merge branch 'trunk' into fix/cleanup-gate-split
pfefferle 47d0259
Choose which post types publish to AT Protocol (#41)
pfefferle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Choose which post types are published to AT Protocol from the ATmosphere settings page. Plugins and themes can also opt their custom post types in directly with `add_post_type_support( 'your_type', 'atmosphere' )`. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: fixed | ||
|
|
||
| Preserve remote cleanup of already-synced posts when their post type is removed from the syncable allowlist. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
| /** | ||
| * Post type support resolution and sanitization. | ||
| * | ||
| * @package Atmosphere | ||
| */ | ||
|
|
||
| namespace Atmosphere; | ||
|
|
||
| \defined( 'ABSPATH' ) || exit; | ||
|
|
||
| /** | ||
| * Post Types class. | ||
| */ | ||
| class Post_Types { | ||
|
|
||
| /** | ||
| * Resolve the full set of supported post types. | ||
| * | ||
| * Combines the configured option with anything third parties opted | ||
| * in via `\add_post_type_support( $post_type, 'atmosphere' )`. | ||
| * | ||
| * @return string[] | ||
| */ | ||
| public static function get_supported(): array { | ||
| $configured = (array) \get_option( 'atmosphere_support_post_types', array( 'post' ) ); | ||
| $native = \get_post_types_by_support( 'atmosphere' ); | ||
|
|
||
| $post_types = \array_merge( $configured, $native ); | ||
|
|
||
| /** | ||
| * Filters the post types that support ATmosphere publishing. | ||
| * | ||
| * Runs after the option and native `add_post_type_support()` | ||
| * opt-ins are merged, so plugins can add or remove either source. | ||
| * | ||
| * @param string[] $post_types Post type slugs. | ||
| */ | ||
| $post_types = (array) \apply_filters( 'atmosphere_syncable_post_types', $post_types ); | ||
|
|
||
| // Normalise: drop empties / non-strings, dedupe, re-index. | ||
| $post_types = \array_filter( $post_types, '\is_string' ); | ||
| $post_types = \array_map( 'sanitize_key', $post_types ); | ||
| $post_types = \array_filter( $post_types ); | ||
|
|
||
| return \array_values( \array_unique( $post_types ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Whether a post type is supported. | ||
| * | ||
| * @param string $post_type Post type slug. | ||
| * @return bool | ||
| */ | ||
| public static function supports( string $post_type ): bool { | ||
| return \in_array( $post_type, self::get_supported(), true ); | ||
| } | ||
|
|
||
| /** | ||
| * Sanitize the option on save. | ||
| * | ||
| * Normalises input to a clean string[] of unique public post type | ||
| * slugs. Coerces empty input (e.g. all checkboxes unchecked) to an | ||
| * empty array. | ||
| * | ||
| * @param mixed $value Submitted value. | ||
| * @return string[] | ||
| */ | ||
| public static function sanitize( $value ): array { | ||
| if ( empty( $value ) ) { | ||
| return array(); | ||
| } | ||
|
|
||
| $allowed = \get_post_types( array( 'public' => true ) ); | ||
|
|
||
| $value = \array_filter( (array) $value, '\is_string' ); | ||
| $value = \array_map( 'sanitize_key', $value ); | ||
| $value = \array_filter( $value ); | ||
|
|
||
| return \array_values( \array_unique( \array_intersect( $value, $allowed ) ) ); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.