Skip to content
Open
Show file tree
Hide file tree
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 Nov 11, 2025
a98502f
Add docblock to Extra Fields block render callback
pfefferle Nov 11, 2025
584ebcf
Update build/extra-fields/render.php
pfefferle Nov 11, 2025
1e1532b
Update src/extra-fields/style.scss
pfefferle Nov 11, 2025
05a20b4
Update src/extra-fields/edit.js
pfefferle Nov 11, 2025
b4271a3
Update src/extra-fields/edit.js
pfefferle Nov 11, 2025
e5054c6
Add tests and improve extra fields block styles
pfefferle Nov 11, 2025
2159c31
Remove unused $block parameter in user ID retrieval
pfefferle Nov 11, 2025
5f77e9b
Add changelog
matticbot Nov 11, 2025
8f8e458
Add tests for Extra Fields block rendering
pfefferle Nov 11, 2025
eda5dc4
Improve author detection and controls in Extra Fields block
pfefferle Nov 11, 2025
b82e809
Add paragraph margin styles to extra field descriptions
pfefferle Nov 11, 2025
2fbc569
Merge branch 'trunk' into extra-fields-block
pfefferle Nov 13, 2025
70aa78b
Merge branch 'trunk' into extra-fields-block
pfefferle Nov 13, 2025
ea57a71
Rename block and classes to 'Fediverse Extra Fields'
pfefferle Nov 13, 2025
3e7ab98
Rename block styles and update styling for extra fields
pfefferle Nov 13, 2025
563f7ee
Merge branch 'trunk' into extra-fields-block
pfefferle Nov 13, 2025
cce4f8d
Merge branch 'trunk' into extra-fields-block
pfefferle Nov 14, 2025
2f3054b
Refactor extra fields block styles and remove save.js
pfefferle Nov 14, 2025
9bc1315
Add profile settings link to extra fields block
pfefferle Nov 14, 2025
d68b6d3
Merge branch 'trunk' into extra-fields-block
pfefferle Nov 14, 2025
05337dd
Update mocks and split empty fields message in tests
pfefferle Nov 14, 2025
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
72 changes: 72 additions & 0 deletions build/extra-fields/block.json
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"
}
1 change: 1 addition & 0 deletions build/extra-fields/index.asset.php
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');
1 change: 1 addition & 0 deletions build/extra-fields/index.js

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

75 changes: 75 additions & 0 deletions build/extra-fields/render.php
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>
1 change: 1 addition & 0 deletions build/extra-fields/style-index-rtl.css

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

1 change: 1 addition & 0 deletions build/extra-fields/style-index.css

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

1 change: 1 addition & 0 deletions includes/class-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static function handle_in_reply_to_get_param() {
* Register the blocks.
*/
public static function register_blocks() {
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/extra-fields' );
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/follow-me' );
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/followers' );
\register_block_type_from_metadata( ACTIVITYPUB_PLUGIN_DIR . '/build/reactions' );
Expand Down
66 changes: 66 additions & 0 deletions src/extra-fields/block.json
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"
}
Loading
Loading