Skip to content

Commit

Permalink
Merge branch 'develop' into feature/861
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc authored Jul 30, 2024
2 parents ff8b199 + c8069ca commit 2d90008
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
42 changes: 22 additions & 20 deletions assets/js/gutenberg-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,45 +153,47 @@ const DistributorIcon = () => (
* Add the Distributor panel to Gutenberg
*/
const DistributorPlugin = () => {
// Ensure the user has proper permissions
if (
dtGutenberg.noPermissions &&
1 === parseInt( dtGutenberg.noPermissions )
) {
return null;
}

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow
const postType = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPostType()
);

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow
const postStatus = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPostAttribute( 'status' )
);

// Ensure we are on a supported post type
if (
dtGutenberg.supportedPostTypes &&
dtGutenberg.supportedPostTypes[ postType ] === undefined
) {
return null;
}

// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const distributorTopMenu = document.querySelector(
'#wp-admin-bar-distributor'
);

// eslint-disable-next-line no-shadow, react-hooks/rules-of-hooks -- permission checks are needed.
// eslint-disable-next-line no-shadow
const post = useSelect( ( select ) =>
select( 'core/editor' ).getCurrentPost()
);

// Ensure the user has proper permissions.
if (
dtGutenberg.noPermissions &&
1 === parseInt( dtGutenberg.noPermissions )
) {
return null;
}

// Ensure we are on a supported post type.
if (
dtGutenberg.supportedPostTypes &&
dtGutenberg.supportedPostTypes[ postType ] === undefined
) {
return null;
}

// Make the post title and status available to the top menu.
dt.postTitle = post.title;
dt.postStatus = post.status;

// If we are on a non-supported post status, change what we show
// If we are on a non-supported post status, change what we show.
if (
dtGutenberg.supportedPostStati &&
! dtGutenberg.supportedPostStati.includes( postStatus )
Expand Down
6 changes: 5 additions & 1 deletion includes/classes/DistributorPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,11 @@ protected function parse_blocks_for_attachment_id( $block ) {
}

if ( in_array( $block['blockName'], $block_names, true ) ) {
$media[] = $block['attrs'][ $media_blocks[ $block['blockName'] ] ];
$attribute_key = $media_blocks[ $block['blockName'] ];

if ( isset( $block['attrs'][ $attribute_key ] ) ) {
$media[] = $block['attrs'][ $attribute_key ];
}
}

return $media;
Expand Down
7 changes: 1 addition & 6 deletions includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,7 @@ function distributor_meta() {
* Check user permissions for available post types
*/
function check_post_types_permissions() {
$types = get_post_types(
array(
'show_in_rest' => true,
),
'objects'
);
$types = Utils\distributable_post_types( 'objects' );

$response = array(
'can_get' => array(),
Expand Down
8 changes: 7 additions & 1 deletion includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,13 @@ function excluded_meta() {
*/
function prepare_meta( $post_id ) {
update_postmeta_cache( array( $post_id ) );
$meta = get_post_meta( $post_id );
$meta = get_post_meta( $post_id );

if ( false === $meta ) {
return array();
}

$meta = is_array( $meta ) ? $meta : array();
$prepared_meta = array();
$excluded_meta = excluded_meta();

Expand Down

0 comments on commit 2d90008

Please sign in to comment.