Skip to content
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

Blocks for Co-Authors #997

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
9c7a6bb
add coauthors and coauthor-display-name blocks
douglas-johnson Mar 7, 2023
2efcc43
instantiate block classes
douglas-johnson Mar 7, 2023
a2fb1c0
wrap display name in something, start with p
douglas-johnson Mar 7, 2023
15cc2d2
wip: support separators; inline and block layouts
douglas-johnson Jul 17, 2023
2c1524c
add prefix and suffix, storage in json is ugly
douglas-johnson Jul 18, 2023
57cd915
wp_kses removes style attribute, removing for now
douglas-johnson Jul 18, 2023
03d45bf
wip adding block specifc api routes
douglas-johnson Jul 18, 2023
752c06e
add api route for single coauthor by name
douglas-johnson Jul 19, 2023
b90c30e
add link toggle to display name block
douglas-johnson Jul 20, 2023
ae5c3d9
provide link in context from coauthors block
douglas-johnson Jul 20, 2023
e9d4109
output link in display name block render callback
douglas-johnson Jul 20, 2023
df51b94
missed one link target
douglas-johnson Jul 20, 2023
dff5263
ignore node_modules. wherever they are
douglas-johnson Jul 26, 2023
5e4999b
add avatar_urls to api response
douglas-johnson Jul 27, 2023
26fa69d
tabs fix
douglas-johnson Jul 28, 2023
c14d406
add avatar block
douglas-johnson Jul 28, 2023
353b87a
add avatar block to main plugin file
douglas-johnson Jul 28, 2023
0d9abee
provide avatar_urls context
douglas-johnson Jul 28, 2023
88b0df2
more general css for inline style
douglas-johnson Jul 28, 2023
fc40fb7
build coauthors block
douglas-johnson Jul 28, 2023
dba39d4
reduce whitespace to match JSX in editor
douglas-johnson Jul 31, 2023
eea9905
wip fse
douglas-johnson Aug 1, 2023
2b73d4b
more FSE support through dummy data and context
douglas-johnson Aug 1, 2023
4a7550d
undo dev permissions change
douglas-johnson Aug 1, 2023
8cb50ad
support vertical spacing, blockgap
douglas-johnson Aug 2, 2023
d35ecd2
better match for client-side gap calculation
douglas-johnson Aug 2, 2023
1530916
move gap to block save func, add text alignment
douglas-johnson Aug 2, 2023
820cf89
default avatars to display block
douglas-johnson Aug 3, 2023
4db7e75
add coauthor description block
douglas-johnson Aug 3, 2023
9fd178d
dont click links in the editor if desc has html
douglas-johnson Aug 3, 2023
92fc4b2
add text align to display name and description
douglas-johnson Aug 3, 2023
4ac7ea5
open up permissions for single coauthor
douglas-johnson Aug 3, 2023
d248c18
typo and whitespace
douglas-johnson Aug 3, 2023
01815d2
add featured media to api responses
douglas-johnson Aug 9, 2023
3eeedb2
add default featured_media
douglas-johnson Aug 9, 2023
9cf110e
add default featured media
douglas-johnson Aug 9, 2023
e85f1c5
build coauthors block
douglas-johnson Aug 9, 2023
0dd33a2
add featured image, sufficient to edit only
douglas-johnson Aug 9, 2023
10bd299
render guest author feature image
douglas-johnson Aug 9, 2023
a2b37e8
build feature image block
douglas-johnson Aug 9, 2023
0551abe
consistent linking to author archive
douglas-johnson Aug 9, 2023
027fd82
unify placeholders, use border not rounded style
douglas-johnson Aug 9, 2023
5e6ec6d
example author in settings, 1 archive context func
douglas-johnson Aug 10, 2023
2ce029c
start using schema for api responses
douglas-johnson Aug 11, 2023
984e92c
use custom store instead of block editor settings
douglas-johnson Aug 11, 2023
09af020
use author placeholder from custom store
douglas-johnson Aug 11, 2023
4e489f1
add descriptions to schema items
douglas-johnson Aug 11, 2023
802c781
support spacing in avatar block
douglas-johnson Aug 11, 2023
4826d38
support register_rest_field
douglas-johnson Aug 11, 2023
17fcb21
support turning off the “show_avatars” option
douglas-johnson Aug 11, 2023
2cfe150
working but slightly bizarre feature image
douglas-johnson Aug 15, 2023
f3fdbda
use custom placeholder, make more like image block
douglas-johnson Aug 16, 2023
55469c0
use image placeholder for avatar, switch to figure
douglas-johnson Aug 16, 2023
dea6f5b
standardize creation of html in Templating class
douglas-johnson Aug 16, 2023
c418f57
try to fix error in test with enqueue assets
douglas-johnson Aug 16, 2023
1835bae
Only do author context in WP 5.9 and above
douglas-johnson Aug 16, 2023
25401fa
allow choosing a tagName for display name
douglas-johnson Aug 17, 2023
b118908
add control for verticalAlign to both image blocks
douglas-johnson Aug 17, 2023
20d7228
alignment support more consistent with image block
douglas-johnson Aug 17, 2023
628a051
start documenting
douglas-johnson Aug 17, 2023
771748c
add classnames again after rebase from upstream
douglas-johnson Sep 4, 2023
a9abea5
naming conventions
douglas-johnson Sep 4, 2023
0a9b0d9
update readme to match
douglas-johnson Sep 4, 2023
8310210
reorganize for a single npm run build command
douglas-johnson Sep 6, 2023
ac35c66
remove union types for php 7.4 compat
douglas-johnson Sep 7, 2023
4fd5543
remove unused permission check
douglas-johnson Sep 7, 2023
4c09f80
use int consistently
douglas-johnson Sep 7, 2023
67709d8
document filter to turn off blocks
douglas-johnson Sep 7, 2023
9db703c
remove var type for php 7.1 compat
douglas-johnson Sep 7, 2023
3dc96e0
esc ( maybe not needed ) to satisfy code sniffer
douglas-johnson Sep 7, 2023
76b1547
remove arrow functions for php 7.1 compat
douglas-johnson Sep 7, 2023
35526e6
one more arrow function
douglas-johnson Sep 7, 2023
e4a4d45
remove viewScript
douglas-johnson Sep 7, 2023
fa72a2f
remove use statements, not needed w/o union types
douglas-johnson Sep 7, 2023
bb1be44
fix validate and sanitize funcs based on arg count
douglas-johnson Sep 7, 2023
c10a920
DRY the server-side get of authors w/ API schema
douglas-johnson Sep 7, 2023
e74e2f4
improve function comment
douglas-johnson Sep 7, 2023
55b5f08
revert change to gitignore
douglas-johnson Sep 7, 2023
0f0cd64
update readme based on compat changes
douglas-johnson Sep 7, 2023
b0f482c
use same textdomain in all blocks
douglas-johnson Sep 7, 2023
0a7304c
Update all blocks to start with version 1.0.0
douglas-johnson Sep 13, 2023
78addc6
Consistent package name, add docblock since 3.6.0
douglas-johnson Sep 13, 2023
54d2ddc
All source files have newline at end of file
douglas-johnson Sep 15, 2023
df0d892
Use __DIR__ instead of dirname( __FILE__ )
douglas-johnson Sep 15, 2023
1385574
Replace all uses for realpath with plugin constant
douglas-johnson Sep 15, 2023
c91405d
Fix arg key, validate and sanitize in right order
douglas-johnson Sep 15, 2023
0e61ba5
Remove digit regex also covered by word
douglas-johnson Sep 15, 2023
0dbbd85
Fix PHPCS warnings about space and punctuation
douglas-johnson Sep 15, 2023
d977c42
FIx PHPCS space and punctuation warnings in api
douglas-johnson Sep 15, 2023
3bd50f9
Correctly add filter for render_block_context
douglas-johnson Sep 15, 2023
463b1f2
Update type declaration spacing per code standard
douglas-johnson Sep 18, 2023
7735e6a
Use Automattic\CoAuthorsPlus for package name
douglas-johnson Sep 18, 2023
a71a22b
Change __construct to run, call it statically
douglas-johnson Sep 18, 2023
cdc0c09
Remove single-use variable in route registration
douglas-johnson Sep 19, 2023
8d2654b
Use correct text domain in API controller
douglas-johnson Sep 21, 2023
29de04d
Update description block so UI says biography
douglas-johnson Sep 21, 2023
80533d0
Provide i18n by moving separator attributes to PHP
douglas-johnson Sep 22, 2023
e81c7c4
No magic number, use first avatar size
douglas-johnson Sep 22, 2023
5cef443
Use sanitize_html_class for html classes
douglas-johnson Sep 22, 2023
8876417
Separate and document REST API routes
douglas-johnson Sep 22, 2023
ef41034
Add text domain to i18n in edit.js for all blocks
douglas-johnson Sep 22, 2023
72a4a7b
Update wordpress/icons dependency
douglas-johnson Sep 22, 2023
6d4684f
Add icons for each block
douglas-johnson Sep 22, 2023
44add83
Update block namespace, simplify author context
douglas-johnson Sep 26, 2023
7032b14
Make block descriptions more uniform and useful
douglas-johnson Sep 27, 2023
6362e81
Expand readme with notes on each block
douglas-johnson Sep 27, 2023
c70ecca
Update REST API endpoints to existing namespace
douglas-johnson Sep 27, 2023
bb06e70
Move blocks to theme category, same as Post Author
douglas-johnson Sep 28, 2023
0c3ddcf
Fix, coauthors API endpoint should be plural
douglas-johnson Sep 28, 2023
b66d2f4
Applied format:js for consistency
douglas-johnson Oct 23, 2023
509ce20
Add coauthors keyword for easier block search
douglas-johnson Oct 23, 2023
954638c
Provide i18n of author placeholder content
douglas-johnson Oct 23, 2023
90be7a9
esc display_name and link, clarify render_element
douglas-johnson Oct 23, 2023
e36b07e
Don’t misuse the 406 response code
douglas-johnson Oct 23, 2023
dd52632
Update GET coauthors API endpoint to be public
douglas-johnson Oct 30, 2023
f262210
Fix error in featured_media property for WP_User
douglas-johnson Nov 6, 2023
972f872
Address review of layout settings for avatar block
douglas-johnson Dec 13, 2023
69ea0a6
Update layout icons for Co-Authors Block
douglas-johnson Dec 13, 2023
fbacc98
Address apiVersion and naming convention feedback
douglas-johnson Dec 13, 2023
bf8b4a9
remove errant comma to fix php 7.1 test failure
douglas-johnson Dec 13, 2023
bfd1244
Allow more layouts, only align where applicable
douglas-johnson Jan 10, 2024
028e14a
Use remove-outline to see cursor in site editor
douglas-johnson Jan 16, 2024
2de42ac
Default feature image block to thumbnail not full
douglas-johnson Feb 8, 2024
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
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,87 @@ Yes! Guest authors can be disabled entirely through a filter. Having the followi
## Change Log

[View the change log](https://github.com/Automattic/Co-Authors-Plus/blob/master/CHANGELOG.md).

GaryJones marked this conversation as resolved.
Show resolved Hide resolved
## Blocks
GaryJones marked this conversation as resolved.
Show resolved Hide resolved

### Co-Authors

Use this block to create a repeating template that displays the co-authors of a post. By default it contains the Co-Author Name block, but you can add any other block you want to the template. If you choose another Co-Author block like avatar, biography or image it will automatically be supplied the author `context` that it needs. This works similarly to creating a Post Template in a Query Loop block.

The Co-Authors Block supports two layouts:

#### Inline Layout

Use the inline layout to display co-authors in a list on a single wrapping line.

You can control the characters displayed before, between and after co-authors in the list using the block settings, or change the defaults using the following server-side filters:

```
coauthors_default_before
coauthors_default_between
coauthors_default_between_last
coauthors_default_after
```

#### Block Layout

Use the block layout to display co-authors in a vertical stack. While using the block layout you can use block spacing settings to control the vertical space between co-authors.

Then you can create your own layout using blocks like group, row or stack and it will be applied to each co-author, similar to applying a layout to each post in a query loop.

### Co-Author Name

This block displays a co-author's `Display Name` and optionally turns it into a link to their author archive.

Using the block's advanced settings you can select which HTML element is used to output the name. This is useful in contexts such as an author archive where you might want their name to be a heading.

### Co-Author Avatar

Like the post author avatar, or comment author avatar, this block displays a small scale square image of a co-author and utilizes the Gravatar default avatars as configured in your site's discussion options.

To customize the available sizes, use the [rest_avatar_sizes](https://developer.wordpress.org/reference/hooks/rest_avatar_sizes/) filter.

### Co-Author Biography

This block outputs the biographical information for a co-author based on either their user or guest author data.

The content is wrapped in paragraph elements using `wpautop` and is escaped using `wp_kses_post`.

### Co-Author Featured Image

This block requires the use of Guest Authors. Because guest author avatars are uploaded to the WordPress media library, there are more options for displaying these images.

This block utilizes the image sizes configured in your theme and your site's media settings to present a guest author's avatar at a larger scale or higher resolution. It does not support Gravatars.

## Block Context

### Post, Page, Query Loop

By default, all blocks receive the post context. The job of the Co-Authors Block is to use this context to find the relevant authors and provide context to its inner blocks.

### Author Archive

If you want to display data about the author on their own archive, use the individual co-author blocks directly without wrapping them in the Co-Authors Block. During requests for an author archive the correct context is derived from the `author_name` query variable and provided to all blocks that declare their use of the context `co-authors-plus/author`.

### Extending

If you make a custom block and want to use the author context, add `co-authors-plus/author` to the `usesContext` property in your block.json file.

Example:
```json
{
"usesContext": ["co-authors-plus/author"]
}
```

## Block Example Data

When working with Full Site Editing, or in the post editor before the authors are loaded, example data is used. The example data provided with the co-author blocks resembles a response to the `/coauthors/v1/coauthors/:user-nicename` REST API endpoint.

### Extending

If you have written a plugin that modifies the REST API response, you can similarly modify the example data either on the server-side using the filter `coauthors_blocks_store_data` or the client-side using the filter `co-authors-plus.author-placeholder`.

## Block Non-support

To declare a lack of support for Co-Author Plus blocks on your site, use the filter `coauthors_plus_support_blocks` to return `false`.
1 change: 1 addition & 0 deletions build/blocks-store/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-data', 'wp-hooks'), 'version' => '82f1cda3f1d3fbb0136c');
1 change: 1 addition & 0 deletions build/blocks-store/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions build/blocks/block-coauthor-avatar/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "co-authors-plus/avatar",
"version": "1.0.0",
"title": "Co-Author Avatar",
"category": "theme",
"description": "Displays a small scale version of a co-author's avatar. Utilizes fallbacks from Gravatar so everyone has an avatar.",
"keywords": [
"coauthors"
],
"supports": {
"html": false,
"__experimentalBorder": {
"color": true,
"radius": true,
"width": true,
"__experimentalSelector": "img, .block-editor-media-placeholder",
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"color": false,
"radius": false,
"width": false
}
},
"spacing": {
"margin": true,
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
}
},
"usesContext": [
"co-authors-plus/author",
"co-authors-plus/layout"
],
"attributes": {
"size": {
"type": "number",
"default": 24
},
"isLink": {
"type": "boolean",
"default": false
},
"rel": {
"type": "string"
},
"verticalAlign": {
"type": "string"
},
"align": {
"type": "string"
}
},
"textdomain": "co-authors-plus",
"editorScript": "file:./index.js",
"style": "file:./style-index.css"
}
1 change: 1 addition & 0 deletions build/blocks/block-coauthor-avatar/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'b6b841ac8f86f7358245');
1 change: 1 addition & 0 deletions build/blocks/block-coauthor-avatar/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/blocks/block-coauthor-avatar/style-index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions build/blocks/block-coauthor-description/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "co-authors-plus/description",
"version": "1.0.0",
"title": "Co-Author Biography",
"category": "theme",
"description": "Displays a co-author's biographical description.",
"keywords": [
"coauthors",
"description",
"bio",
"biography"
],
"supports": {
"html": false,
"color": {
"link": true,
"text": true,
"background": true,
"__experimentalDefaultControls": {}
},
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontFamily": true,
GaryJones marked this conversation as resolved.
Show resolved Hide resolved
"__experimentalTextDecoration": true,
"__experimentalFontStyle": true,
"__experimentalFontWeight": true,
"__experimentalLetterSpacing": true,
"__experimentalTextTransform": true,
"__experimentalDefaultControls": {}
},
"spacing": {
"margin": true,
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
}
},
"usesContext": [
"co-authors-plus/author"
],
"attributes": {
"textAlign": {
"type": "string"
}
},
"textdomain": "co-authors-plus",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css"
}
GaryJones marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions build/blocks/block-coauthor-description/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => 'd61297f0bd62592218f0');
1 change: 1 addition & 0 deletions build/blocks/block-coauthor-description/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.wp-block-co-authors-plus-description a{pointer-events:none}
1 change: 1 addition & 0 deletions build/blocks/block-coauthor-description/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions build/blocks/block-coauthor-image/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "co-authors-plus/image",
"version": "1.0.0",
"title": "Co-Author Featured Image",
"category": "theme",
"description": "Uses your theme's image sizes to display a scalable avatar for a co-author with a guest author profile. Does not fallback to Gravatar images.",
"keywords": [
"coauthors"
],
"supports": {
"__experimentalBorder": {
"color": true,
"radius": true,
"width": true,
"__experimentalSelector": "img, .block-editor-media-placeholder",
"__experimentalSkipSerialization": true,
"__experimentalDefaultControls": {
"color": false,
"radius": false,
"width": false
}
},
"spacing": {
"margin": true,
"padding": true,
"__experimentalDefaultControls": {
"margin": false,
"padding": false
}
}
},
"usesContext": [
"co-authors-plus/author",
"co-authors-plus/layout"
],
"attributes": {
"isLink": {
"type": "boolean",
"default": false
},
"rel": {
"type": "string"
},
"aspectRatio": {
"type": "string"
},
"width": {
"type": "string"
},
"height": {
"type": "string"
},
"scale": {
"type": "string",
"default": "cover"
},
"sizeSlug": {
"type": "string"
},
"verticalAlign": {
"type": "string"
},
"align": {
"type": "string"
}
},
"textdomain": "co-authors-plus",
"editorScript": "file:./index.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css"
}
1 change: 1 addition & 0 deletions build/blocks/block-coauthor-image/index.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives'), 'version' => '97710ad46fb953ce4975');
Loading
Loading