Skip to content
Open
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
2 changes: 1 addition & 1 deletion assets/js/dist/editor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => '74afaf36e207a8e3185b');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-shortcode', 'wp-url'), 'version' => '3de629e85d4a951d5dd4');
2 changes: 1 addition & 1 deletion assets/js/dist/editor.js

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions assets/js/src/blocks/team-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
import { attrs } from '@wordpress/shortcode';

/**
* Internal dependencies
Expand Down Expand Up @@ -59,10 +60,72 @@ export const settings = {
type: 'string',
default: 'desc',
},
include: {
type: 'array',
default: [],
},
hasPublishedPosts: {
type: 'array',
default: [],
},
},

transforms: {
from: [
{
type: 'block',
blocks: ['core/shortcode'],
isMatch: ({ text }) => {
return text && text.startsWith('[wp_team_list');
},
transform: ({ text }) => {
const shortcode = attrs( text );
const attributes = {
roles: shortcode.named.role ? shortcode.named.role.split(',') : [],
orderBy: shortcode.named.orderby,
order: shortcode.named.order ? shortcode.named.order.toLowerCase : 'desc',
include: shortcode.named.include ? shortcode.named.include.split(',') : [],
hasPublishedPosts: shortcode.named.has_published_posts ? shortcode.named.has_published_posts.split(',') : [],
}
return createBlock(name, attributes);
},
},
{
type: 'shortcode',
tag: 'wp_team_list',
attributes: {
roles: {
type: 'array',
shortcode: ( { named: { role } } ) => {
return role ? role.split(',') : [];
},
},
orderBy: {
type: 'string',
shortcode: ( { named: { orderby } } ) => {
return orderby;
},
},
order: {
type: 'string',
shortcode: ( { named: { order } } ) => {
return order.toLowerCase();
},
},
include: {
type: 'array',
shortcode: ( { named: { include } } ) => {
return include ? include.split(',') : [];
},
},
hasPublishedPosts: {
type: 'array',
shortcode: ( { named: { has_published_posts } } ) => {
return has_published_posts ? has_published_posts.split(',') : [];
},
},
},
},
{
type: 'block',
blocks: [ 'core/legacy-widget' ],
Expand Down
17 changes: 12 additions & 5 deletions includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,13 @@ public function rest_prepare_widget( $response, $widget ) {
*/
public function render_team_list_block( $attributes ) {
$attributes_mappings = [
'number' => 'number',
'showDescription' => 'show_description',
'order' => 'order',
'orderBy' => 'orderby',
'roles' => 'role',
'number' => 'number',
'showDescription' => 'show_description',
'order' => 'order',
'orderBy' => 'orderby',
'roles' => 'role',
'include' => 'include',
'hasPublishedPosts' => 'has_published_posts',
];

$prepared_args = [];
Expand All @@ -717,6 +719,11 @@ public function render_team_list_block( $attributes ) {
}
}

// Convert array to comma-separated string.
if ( \is_array( $prepared_args['has_published_posts'] ) ) {
$prepared_args['has_published_posts'] = implode( ',', $prepared_args['has_published_posts'] );
}

$html = wp_team_list()->render( $prepared_args );

if ( ! empty( $attributes['postId'] ) ) {
Expand Down