Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ A WordPress plugin for enhancing the editorial experience, including some common
- [What This Plugin Does](#what-this-plugin-does)
- [Blocks](#blocks)
- [Editor Plugins](#editor-plugins)
- [Core Enhancements](#core-enhancements)
- [Theme Configuration](#theme-configuration)
- [Theme API](#theme-api)
- [Troubleshooting](#troubleshooting)
Expand All @@ -15,7 +16,7 @@ A WordPress plugin for enhancing the editorial experience, including some common

## What This Plugin Does

The purpose of this plugin is to tailor the Gutenberg editor experience to be better suited to editors using their WordPress theme. Features added as a part of this plugin fall into two categories: block modifications and editor plugins.
The purpose of this plugin is to tailor the Gutenberg editor experience to be better suited to editors using their WordPress theme and to add functionality common to many websites. Features added as a part of this plugin fall into three categories: block modifications, editor plugins, and core enhancements. This plugin also exposes some global functions that can be used in theme templates.

### Blocks

Expand Down Expand Up @@ -51,6 +52,10 @@ The Authors panel allows editors to assign multiple authors to the author byline

These authors also serve as taxonomies for your articles, so archive pages full of an author's own content are auto-generated on your behalf.

### Core Enhancements

- Adds a `Credit` field to attachment posts.

### Template functions

This plugin exposes a few functions that can be used to retrieve relevant values handled by the plugin. See the [Theme API](#theme-api) section for information about the available functions.
Expand Down Expand Up @@ -80,6 +85,7 @@ return array(
'table',
'video',
),
'enable_block_styles' => array(),
);
```

Expand Down Expand Up @@ -129,6 +135,14 @@ array(

A list of blocks that are extended by the plugin. To disable the extension of a certain block, exclude it from this array.

#### `enable_block_styles`

**Allowed types:** `array`

**Default value:** `array()`

WordPress core includes style options for some core blocks. This plugin removes those style options by default, but this parameter can be used to re-enable the core style options for specific blocks. The following blocks have core styles that can be re-enabled via this parameter: `button`, `image`, `quote`, `separator`, `table`.

## 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
3 changes: 3 additions & 0 deletions includes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Config {
'table',
'video',
),

// Enable core block styles.
'enable_block_styles' => array(),
);

/**
Expand Down
18 changes: 9 additions & 9 deletions includes/Meta/AttachmentCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class AttachmentCredit {
*/
private $attachment_fields = array(
array(
'id' => 'credit',
'label' => 'Credit',
'input' => 'text',
'helps' => 'Provide credit to the creator',
'id' => 'credit',
'label' => 'Credit',
'input' => 'text',
'helps' => 'Provide credit to the creator',
'single' => true,
)
),
);

/**
Expand All @@ -35,7 +35,7 @@ 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_filter( 'attachment_fields_to_save', array( $attachment_credit, 'handle_save_fields' ), 10, 2 );

add_action( 'rest_api_init', array( $attachment_credit, 'register_rest_fields' ) );
}
Expand Down Expand Up @@ -72,7 +72,7 @@ public function register_edit_fields( $fields, $post ) {
* @param array $post Array of post data.
* @param array $attachment Attachment metadata.
*
* @return void
* @return array
*/
public function handle_save_fields( $post, $attachment ) {
foreach ( $this->attachment_fields as $field ) {
Expand All @@ -93,12 +93,12 @@ public function handle_save_fields( $post, $attachment ) {
* @return void
*/
public function register_rest_fields() {
foreach ($this->attachment_fields as $field) {
foreach ( $this->attachment_fields as $field ) {
register_rest_field(
'attachment',
$field['id'],
array(
'get_callback' => function($object) use ($field) {
'get_callback' => function( $object ) use ( $field ) {
return get_post_meta( $object['id'], $field['id'], $field['single'] );
},
'update_callback' => null,
Expand Down
50 changes: 33 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,43 @@ import { Cover, File, Gallery, ImageLayout, RelatedArticles, Table, Video } from
});
});

domReady(() => {
// Remove quote style panel
unregisterBlockStyle('core/quote', 'default');
unregisterBlockStyle('core/quote', 'plain');
// ========================
// General editor

// Remove separator style panel
unregisterBlockStyle('core/separator', 'default');
unregisterBlockStyle('core/separator', 'wide');
unregisterBlockStyle('core/separator', 'dots');
domReady(() => {
/**
* Unregister all block styles and variations on core blocks by default, with
* optional overrides provided in configuration. This prevents unnecessary
* options for content editors and gives designers a blank slate when
* implementing core blocks.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/
*/
const activeEnableBlockStyles = window.ups_editorial?.enable_block_styles;
['button', 'image', 'quote', 'separator', 'table']
.filter(
blockName => !activeEnableBlockStyles || activeEnableBlockStyles.indexOf(blockName) === -1,
)
.forEach(blockName =>
wp.blocks
.getBlockType(`core/${blockName}`)
.styles.forEach(({ name: styleName }) =>
unregisterBlockStyle(`core/${blockName}`, styleName),
),
);

// Remove table style panel
unregisterBlockStyle('core/table', 'regular');
unregisterBlockStyle('core/table', 'stripes');
/**
* Unregister core Embed block variations.
*/
getBlockVariations('core/embed').forEach(variation => {
unregisterBlockVariation('core/embed', variation.name);
});

// Updating format type
/**
* Add custom class to inline images added to rich text content. This gives
* theme designers a selector target for inline image styles.
*/
const image = unregisterFormatType('core/image');
image.className = 'wp-rich-text-inline-image';
registerFormatType('core/image', image);

// Unregister all the Embed block variations.
getBlockVariations('core/embed').forEach(variation => {
unregisterBlockVariation('core/embed', variation.name);
});
});