-
Notifications
You must be signed in to change notification settings - Fork 0
A real v1 #1
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
A real v1 #1
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
f757cc1
Pretty much a full reset
braican b92523c
Rename
braican c00028a
Improve readme
braican 87cd830
Local dev
braican e08559a
Start building
braican 112dc15
More deps
braican 200c0b6
Prevent unnecessary rules
braican 314ea33
Pull over author taxonomy
braican 28a3dc3
Set up config
braican fa6a434
Some docs
braican 2b37b45
Better way to hide default author panel
braican 1da5ce9
Cleanup
braican 971df4e
Docs, cleanup
braican f280b49
Article topper
braican 0835b71
Readme
braican 2df34a9
More docs
braican 967aef5
Attachment credits
braican 1d7ebab
Pull in the block stuff
braican 0736215
Remove button in favor of theme.json
braican cbe34c1
Little refactor for config
braican 65248d2
Some readme
braican e2be0ab
More docs
braican d18da8e
Node version
braican ff4978e
Remove docker stuff
braican 766ea9d
Account for missing options
braican af1cf44
Wholesale rename the bylines panel
braican e204cb9
Use the right indexof
braican c9fb7ae
Update a few styles
braican e7ef32f
Remove style picker from core/image block
0e4fc39
Remove style picker from core/button block
f2b2f5e
Revert "Remove style picker from core/button block"
0533098
Fix keys
braican 6c080d9
Fix sass division
braican 300af21
Update per packagist recs
braican 679bbe1
Ignore on zip downloads
braican e8571bc
Test building assets
braican a356508
Remove workflows, add build
braican 1027c28
Add husky for git hooks
braican 3af667b
Use pre-push instead
braican 2d322bf
Build assets
braican ac6b85a
Remove husky
braican 56641f8
Try a build asset step
braican ec6f4de
Attach to PR branch
braican a752fad
Build production assets (from GitHub Actions)
braican 9be1e36
Remove hard-coded block style names in favor of array
4d98001
Add documentation to image registerFormatType
b38b124
Adjust comment
3255662
Add enable_block_styles as configuration option
1579b84
Add autoloader
braican c795b83
Little syntax updates
braican 89a3f6b
Linting
braican 30e71a2
Cleanup
braican 24c7049
Readme
braican f75bd89
Merge pull request #3 from Upstatement/v2-remove-image-style-panel
braican 0e91ffc
Merge pull request #4 from Upstatement/v2-ci
braican b3783c3
Build production assets (from GitHub Actions)
braican 55c08fa
Linting in github actions
braican ca13944
Build production assets (from GitHub Actions)
braican 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
Attachment credits
- Loading branch information
commit 967aef575e883f7f29b8e4b05cac1635c6ab51d7
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
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,110 @@ | ||
| <?php | ||
| /** | ||
| * Registers a meta field for attachment credits. | ||
| * | ||
| * @package Upstatement\Editorial | ||
| */ | ||
|
|
||
| namespace Upstatement\Editorial\Meta; | ||
|
|
||
| use WP_Post; | ||
|
|
||
| class AttachmentCredit { | ||
|
|
||
| /** | ||
| * Fields to add to the attachment post type. | ||
| * | ||
| * @var array | ||
| */ | ||
| private $attachment_fields = array( | ||
| array( | ||
| 'id' => 'credit', | ||
| 'label' => 'Credit', | ||
| 'input' => 'text', | ||
| 'helps' => 'Provide credit to the creator', | ||
| 'single' => true, | ||
| ) | ||
| ); | ||
|
|
||
| /** | ||
| * Register the credit feature. | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function register() { | ||
| $attachment_credit = new self(); | ||
|
|
||
| add_filter( 'attachment_fields_to_edit', array( $attachment_credit, 'register_edit_fields' ), 10, 2 ); | ||
| add_filter( 'attachment_fields_to_save', array( $attachment_credit, 'handle_save_fields'), 10, 2 ); | ||
|
|
||
| add_action( 'rest_api_init', array( $attachment_credit, 'register_rest_fields' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Register the attachment fields for editing. | ||
| * | ||
| * @see https://developer.wordpress.org/reference/hooks/attachment_fields_to_edit/ | ||
| * | ||
| * @param array $fields Array of attachment form fields. | ||
| * @param WP_Post $post Attachment object. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function register_edit_fields( $fields, $post ) { | ||
| foreach ( $this->attachment_fields as $field ) { | ||
| $fid = $field['id']; | ||
| $value = get_post_meta( $post->ID, $fid, true ); | ||
| $fields[ $fid ] = array( | ||
| 'show_in_rest' => true, | ||
| 'label' => $field['label'], | ||
| 'input' => $field['input'], | ||
| 'value' => $value, | ||
| 'helps' => $field['helps'], | ||
| ); | ||
| } | ||
|
|
||
| return $fields; | ||
| } | ||
|
|
||
| /** | ||
| * Handles saved attachment data. | ||
| * | ||
| * @param array $post Array of post data. | ||
| * @param array $attachment Attachment metadata. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function handle_save_fields( $post, $attachment ) { | ||
| foreach ( $this->attachment_fields as $field ) { | ||
| $fid = $field['id']; | ||
| if ( isset( $attachment[ $fid ] ) ) { | ||
| update_post_meta( $post['ID'], $fid, sanitize_text_field( $attachment[ $fid ] ) ); | ||
| } else { | ||
| delete_post_meta( $post['ID'], $fid ); | ||
| } | ||
| } | ||
|
|
||
| return $post; | ||
| } | ||
|
|
||
| /** | ||
| * Add the attachment fields for the Rest API. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function register_rest_fields() { | ||
| foreach ($this->attachment_fields as $field) { | ||
| register_rest_field( | ||
| 'attachment', | ||
| $field['id'], | ||
| array( | ||
| 'get_callback' => function($object) use ($field) { | ||
| return get_post_meta( $object['id'], $field['id'], $field['single'] ); | ||
| }, | ||
| 'update_callback' => null, | ||
| 'schema' => null, | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered other ways of defining configuration for the connection between plugin and theme? I ask because WordPress has the
add_theme_supportandget_theme_supportfunctions to somewhat standardize the activation of feature flags.For example, I can imagine a system where WSK does something like:
And, Ups Editorial Plugin reads that with:
The advantage is it keeps the "standard WP way" that might feel more friendly to others. The potential disadvantage is it introduces WP's weirdness, like it might run afoul of WP hook sequence firing; I haven't tested this in depth to know the extent of the potential problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to consider alternative ways to implement config but I also want to see how this is used and get a sense from other devs how they would like to manage feature flagging. As for my thinking behind the config files...
Ideally themes would individually remove features rather than need to add them, so I'm not sure that the
add_theme_support()paradigm would work. We may be able to invert this and have themes usedisable_theme_support(), but we'd have to look into that a bit.A similar pattern I did consider was using hooks to handle feature support:
Theme code
Plugin
Ultimately while that is the pattern I see most commonly around enabling/disabling plugin features and is effectively the standard way that WordPress handles this type of thing, I don't love that method: it requires namespaced filter names, which can get cumbersome; I'm never confident on the best place for this code to get added to a theme; and it just isn't that clear as to what it's doing (it took me years to understand that the
__return_falsecallback is a global function in core).I like the simplicity of a singular config file that is scoped to a specific application that defines settings for that application - it's one of the ideas that I pulled over from how Craft CMS handles things. While it's not necessarily a standard WordPress pattern, it's simple enough to be understood by theme developers and robust enough where we can continue adding to it easily without having to create a bunch of individual filters for the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good enough for me! It was helpful to hear your thinking around it, and that you did consider some other WP-native ways, too.