-
Notifications
You must be signed in to change notification settings - Fork 83
Add Extra Fields block for ActivityPub profiles #2439
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
Open
pfefferle
wants to merge
22
commits into
trunk
Choose a base branch
from
extra-fields-block
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,542
−3
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
08e6407
Add Extra Fields block for ActivityPub profiles
pfefferle a98502f
Add docblock to Extra Fields block render callback
pfefferle 584ebcf
Update build/extra-fields/render.php
pfefferle 1e1532b
Update src/extra-fields/style.scss
pfefferle 05a20b4
Update src/extra-fields/edit.js
pfefferle b4271a3
Update src/extra-fields/edit.js
pfefferle e5054c6
Add tests and improve extra fields block styles
pfefferle 2159c31
Remove unused $block parameter in user ID retrieval
pfefferle 5f77e9b
Add changelog
matticbot 8f8e458
Add tests for Extra Fields block rendering
pfefferle eda5dc4
Improve author detection and controls in Extra Fields block
pfefferle b82e809
Add paragraph margin styles to extra field descriptions
pfefferle 2fbc569
Merge branch 'trunk' into extra-fields-block
pfefferle 70aa78b
Merge branch 'trunk' into extra-fields-block
pfefferle ea57a71
Rename block and classes to 'Fediverse Extra Fields'
pfefferle 3e7ab98
Rename block styles and update styling for extra fields
pfefferle 563f7ee
Merge branch 'trunk' into extra-fields-block
pfefferle cce4f8d
Merge branch 'trunk' into extra-fields-block
pfefferle 2f3054b
Refactor extra fields block styles and remove save.js
pfefferle 9bc1315
Add profile settings link to extra fields block
pfefferle d68b6d3
Merge branch 'trunk' into extra-fields-block
pfefferle 05337dd
Update mocks and split empty fields message in tests
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,72 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "name": "activitypub/extra-fields", | ||
| "apiVersion": 3, | ||
| "version": "1.0.0", | ||
| "title": "Fediverse Profile Fields", | ||
| "category": "widgets", | ||
| "description": "Display extra profile fields from ActivityPub user profiles", | ||
| "textdomain": "activitypub", | ||
| "icon": "list-view", | ||
| "supports": { | ||
| "html": false, | ||
| "align": [ | ||
| "wide", | ||
| "full" | ||
| ], | ||
| "color": { | ||
| "gradients": true, | ||
| "link": true, | ||
| "__experimentalDefaultControls": { | ||
| "background": true, | ||
| "text": true, | ||
| "link": true | ||
| } | ||
| }, | ||
| "__experimentalBorder": { | ||
| "radius": true, | ||
| "width": true, | ||
| "color": true, | ||
| "style": true | ||
| }, | ||
| "shadow": true, | ||
| "typography": { | ||
| "fontSize": true, | ||
| "__experimentalDefaultControls": { | ||
| "fontSize": true | ||
| } | ||
| } | ||
| }, | ||
| "styles": [ | ||
| { | ||
| "name": "default", | ||
| "label": "Default", | ||
| "isDefault": true | ||
| }, | ||
| { | ||
| "name": "compact", | ||
| "label": "Compact" | ||
| }, | ||
| { | ||
| "name": "cards", | ||
| "label": "Cards" | ||
| } | ||
| ], | ||
| "attributes": { | ||
| "selectedUser": { | ||
| "type": "string", | ||
| "default": "blog" | ||
| }, | ||
| "maxFields": { | ||
| "type": "number", | ||
| "default": 0 | ||
| } | ||
| }, | ||
| "usesContext": [ | ||
| "postType", | ||
| "postId" | ||
| ], | ||
| "editorScript": "file:./index.js", | ||
| "style": "file:./style-index.css", | ||
| "render": "file:./render.php" | ||
| } |
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 @@ | ||
| <?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '1712fbc44f0f619e729a'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,75 @@ | ||
| <?php | ||
| /** | ||
| * Server-side rendering for the Extra Fields block. | ||
| * | ||
| * @package Activitypub | ||
| */ | ||
|
|
||
| use Activitypub\Blocks; | ||
| use Activitypub\Collection\Extra_Fields; | ||
|
|
||
| /* @var array $attributes Block attributes. */ | ||
| $attributes = wp_parse_args( $attributes ); | ||
|
|
||
| /* @var WP_Block $block Block instance. */ | ||
|
|
||
| // Get user ID from selectedUser attribute. | ||
| $user_id = Blocks::get_user_id( $attributes['selectedUser'] ?? 'blog', $block->context ); | ||
|
|
||
| // If user ID couldn't be determined, return empty. | ||
| if ( null === $user_id ) { | ||
| return ''; | ||
| } | ||
|
|
||
| // Get extra fields for this user. | ||
| $fields = Extra_Fields::get_actor_fields( $user_id ); | ||
|
|
||
| // Apply max fields limit if set. | ||
| $max_fields = $attributes['maxFields'] ?? 0; | ||
| if ( $max_fields > 0 && count( $fields ) > $max_fields ) { | ||
| $fields = array_slice( $fields, 0, $max_fields ); | ||
| } | ||
|
|
||
| // Return empty on frontend if no fields (hide block). | ||
| if ( empty( $fields ) ) { | ||
| return ''; | ||
| } | ||
|
|
||
| // Get block wrapper attributes. | ||
| $wrapper_attributes = get_block_wrapper_attributes( | ||
| array( | ||
| 'class' => 'activitypub-extra-fields-block-wrapper', | ||
| ) | ||
| ); | ||
|
|
||
| // Extract background color for cards style. | ||
| $background_color = ''; | ||
| $card_style = ''; | ||
|
|
||
| // Check if this is the cards style by looking at className attribute or wrapper classes. | ||
| $is_cards_style = ( isset( $attributes['className'] ) && str_contains( $attributes['className'], 'is-style-cards' ) ) | ||
| || str_contains( $wrapper_attributes, 'is-style-cards' ); | ||
|
|
||
| if ( $is_cards_style ) { | ||
| // Check for background color in various formats. | ||
| if ( isset( $attributes['backgroundColor'] ) ) { | ||
| $background_color = sprintf( 'var(--wp--preset--color--%s)', $attributes['backgroundColor'] ); | ||
| } elseif ( isset( $attributes['style']['color']['background'] ) ) { | ||
| $background_color = $attributes['style']['color']['background']; | ||
| } | ||
|
|
||
| if ( $background_color ) { | ||
| $card_style = sprintf( ' style="background-color: %s;"', esc_attr( $background_color ) ); | ||
| } | ||
| } | ||
| ?> | ||
| <div <?php echo $wrapper_attributes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | ||
| <dl class="activitypub-extra-fields"> | ||
| <?php foreach ( $fields as $field ) : ?> | ||
| <div class="activitypub-extra-field"<?php echo $card_style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | ||
| <dt><?php echo esc_html( $field->post_title ); ?></dt> | ||
| <dd><?php echo Extra_Fields::get_formatted_content( $field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></dd> | ||
| </div> | ||
| <?php endforeach; ?> | ||
| </dl> | ||
| </div> | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/block.json", | ||
| "name": "activitypub/extra-fields", | ||
| "apiVersion": 3, | ||
| "version": "1.0.0", | ||
| "title": "Fediverse Profile Fields", | ||
| "category": "widgets", | ||
| "description": "Display extra profile fields from ActivityPub user profiles", | ||
| "textdomain": "activitypub", | ||
| "icon": "list-view", | ||
| "supports": { | ||
| "html": false, | ||
| "align": [ "wide", "full" ], | ||
| "color": { | ||
| "gradients": true, | ||
| "link": true, | ||
| "__experimentalDefaultControls": { | ||
| "background": true, | ||
| "text": true, | ||
| "link": true | ||
| } | ||
| }, | ||
| "__experimentalBorder": { | ||
| "radius": true, | ||
| "width": true, | ||
| "color": true, | ||
| "style": true | ||
| }, | ||
| "shadow": true, | ||
| "typography": { | ||
| "fontSize": true, | ||
| "__experimentalDefaultControls": { | ||
| "fontSize": true | ||
| } | ||
| } | ||
| }, | ||
| "styles": [ | ||
| { | ||
| "name": "default", | ||
| "label": "Default", | ||
| "isDefault": true | ||
| }, | ||
| { | ||
| "name": "compact", | ||
| "label": "Compact" | ||
| }, | ||
| { | ||
| "name": "cards", | ||
| "label": "Cards" | ||
| } | ||
| ], | ||
| "attributes": { | ||
| "selectedUser": { | ||
| "type": "string", | ||
| "default": "blog" | ||
| }, | ||
| "maxFields": { | ||
| "type": "number", | ||
| "default": 0 | ||
| } | ||
| }, | ||
| "usesContext": [ "postType", "postId" ], | ||
| "editorScript": "file:./index.js", | ||
| "style": "file:./style-index.css", | ||
| "render": "file:./render.php" | ||
| } |
Oops, something went wrong.
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.