Skip to content
Merged
Show file tree
Hide file tree
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 Jan 17, 2023
b92523c
Rename
braican Jan 17, 2023
c00028a
Improve readme
braican Jan 19, 2023
87cd830
Local dev
braican Jan 19, 2023
e08559a
Start building
braican Jan 19, 2023
112dc15
More deps
braican Jan 19, 2023
200c0b6
Prevent unnecessary rules
braican Jan 19, 2023
314ea33
Pull over author taxonomy
braican Jan 19, 2023
28a3dc3
Set up config
braican Jan 20, 2023
fa6a434
Some docs
braican Jan 20, 2023
2b37b45
Better way to hide default author panel
braican Jan 23, 2023
1da5ce9
Cleanup
braican Jan 23, 2023
971df4e
Docs, cleanup
braican Jan 23, 2023
f280b49
Article topper
braican Jan 24, 2023
0835b71
Readme
braican Jan 24, 2023
2df34a9
More docs
braican Jan 24, 2023
967aef5
Attachment credits
braican Jan 24, 2023
1d7ebab
Pull in the block stuff
braican Jan 26, 2023
0736215
Remove button in favor of theme.json
braican Jan 27, 2023
cbe34c1
Little refactor for config
braican Jan 30, 2023
65248d2
Some readme
braican Jan 30, 2023
e2be0ab
More docs
braican Jan 30, 2023
d18da8e
Node version
braican Jan 31, 2023
ff4978e
Remove docker stuff
braican Jan 31, 2023
766ea9d
Account for missing options
braican Feb 2, 2023
af1cf44
Wholesale rename the bylines panel
braican Feb 2, 2023
e204cb9
Use the right indexof
braican Feb 2, 2023
c9fb7ae
Update a few styles
braican Feb 3, 2023
e7ef32f
Remove style picker from core/image block
Feb 15, 2023
0e4fc39
Remove style picker from core/button block
Feb 15, 2023
f2b2f5e
Revert "Remove style picker from core/button block"
Feb 15, 2023
0533098
Fix keys
braican Feb 15, 2023
6c080d9
Fix sass division
braican Feb 15, 2023
300af21
Update per packagist recs
braican Feb 16, 2023
679bbe1
Ignore on zip downloads
braican Feb 17, 2023
e8571bc
Test building assets
braican Feb 17, 2023
a356508
Remove workflows, add build
braican Feb 17, 2023
1027c28
Add husky for git hooks
braican Feb 17, 2023
3af667b
Use pre-push instead
braican Feb 17, 2023
2d322bf
Build assets
braican Feb 17, 2023
ac6b85a
Remove husky
braican Feb 17, 2023
56641f8
Try a build asset step
braican Feb 17, 2023
ec6f4de
Attach to PR branch
braican Feb 17, 2023
a752fad
Build production assets (from GitHub Actions)
braican Feb 17, 2023
9be1e36
Remove hard-coded block style names in favor of array
Feb 21, 2023
4d98001
Add documentation to image registerFormatType
Feb 21, 2023
b38b124
Adjust comment
Feb 21, 2023
3255662
Add enable_block_styles as configuration option
Feb 21, 2023
1579b84
Add autoloader
braican Feb 22, 2023
c795b83
Little syntax updates
braican Feb 22, 2023
89a3f6b
Linting
braican Feb 23, 2023
30e71a2
Cleanup
braican Feb 23, 2023
24c7049
Readme
braican Feb 23, 2023
f75bd89
Merge pull request #3 from Upstatement/v2-remove-image-style-panel
braican Feb 23, 2023
0e91ffc
Merge pull request #4 from Upstatement/v2-ci
braican Feb 23, 2023
b3783c3
Build production assets (from GitHub Actions)
braican Feb 23, 2023
55c08fa
Linting in github actions
braican Feb 23, 2023
ca13944
Build production assets (from GitHub Actions)
braican Feb 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Attachment credits
  • Loading branch information
braican committed Jan 24, 2023
commit 967aef575e883f7f29b8e4b05cac1635c6ab51d7
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ To set up a configuration file, add a `ups-editorial.php` file to your theme's r
*/

return array(
'bylines' => true,
'article_topper' => true,
'bylines' => true,
'article_topper' => true,
'attachment_credit' => true,
);
```

Expand All @@ -99,6 +100,14 @@ Enable or disable the plugin's `Author` taxonomy, as well as the control mechani

Enable or disable the registration of fields for article toppers and the Gutenberg panel that controls those fields.

#### `attachment_credit`

**Allowed types:** `boolean`

**Default value:** `true`

Enable or disable the registration of a `credit` field for attachments.

## Theme API

There are a few globally-available functions that can be used by your theme to retrieve data defined by this plugin's functionality. These functions are defined in the `Template.php` file at the root of the plugin directory, and exist under the `Upstatement\Editorial` namespace.
Expand Down
6 changes: 4 additions & 2 deletions UpsEditorial.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class UpsEditorial {
* @return void
*/
public static function register() {
$plugin = new self();

Config::read();
Copy link

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_support and get_theme_support functions to somewhat standardize the activation of feature flags.

For example, I can imagine a system where WSK does something like:

add_theme_support( 'ups-editorial-author-panel' );

And, Ups Editorial Plugin reads that with:

if ( get_theme_support( 'ups-editorial-author-panel' ) ) {
	Taxonomy\Author::register();
}

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.

Copy link
Member Author

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 use disable_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

add_filter( 'ups_editorial_author_panel', '__return_false' );

Plugin

if ( apply_filters( 'ups_editorial_author_panel', true ) ) {
    Taxonomy\Author::register();
}

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_false callback 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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the simplicity of a singular config file that is scoped to a specific application that defines settings for that application

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.

Assets::register();

Expand All @@ -41,6 +39,10 @@ public static function register() {
if ( Config::get( 'article_topper' ) ) {
Meta\ArticleTopper::register();
}

if ( Config::get( 'attachment_credit' ) ) {
Meta\AttachmentCredit::register();
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions includes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class Config {
* @var array
*/
private static array $defaults = array(
// Enables the bylines functionality, including the `Authors` taxonomy.
'bylines' => true,
// Enable the bylines functionality, including the `Authors` taxonomy.
'bylines' => true,

// Enable the article topper fields.
'article_topper' => true,
'article_topper' => true,

// Enable the credit field for attachments.
'attachment_credit' => true,
);

/**
Expand Down
110 changes: 110 additions & 0 deletions includes/Meta/AttachmentCredit.php
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,
)
);
}
}
}