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

Fix: Make PCH Related Posts filters work for non-admins #2467

Merged
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 build/content-helper/editor-sidebar.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'eb6c5ec223f3254dbe5a');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'a16d4a6df7ef859f50df');
2 changes: 1 addition & 1 deletion build/content-helper/editor-sidebar.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export const RelatedPostsPanel = (): JSX.Element => {
const noAuthorsExist = 0 === postData.authors.length;
const noTagsExist = 0 === postData.tags.length;
const noCategoriesExist = 0 === postData.categories.length;
const authorIsUnavailable = filterTypeIsAuthor && ! postData.authors.includes( filter.value );
const tagIsUnavailable = filterTypeIsTag && ! postData.tags.includes( filter.value );
const sectionIsUnavailable = filterTypeIsSection && ! postData.categories.includes( filter.value );

Expand All @@ -308,6 +309,8 @@ export const RelatedPostsPanel = (): JSX.Element => {
setFilter( { type: PostFilterType.Tag, value: postData.tags[ 0 ] } );
} else if ( sectionIsUnavailable ) {
setFilter( { type: PostFilterType.Section, value: postData.categories[ 0 ] } );
} else if ( authorIsUnavailable ) {
setFilter( { type: PostFilterType.Author, value: postData.authors[ 0 ] } );
} else {
fetchPosts( FETCH_RETRIES );
}
Expand Down Expand Up @@ -376,7 +379,7 @@ export const RelatedPostsPanel = (): JSX.Element => {

// No filter data could be retrieved. Prevent the component from rendering.
if ( postData.authors.length === 0 && postData.categories.length === 0 &&
postData.tags.length === 0
postData.tags.length === 0 && isPostDataReady
) {
return (
<div className="wp-parsely-related-posts">
Expand Down
6 changes: 3 additions & 3 deletions src/content-helper/editor-sidebar/related-posts/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function usePostData(): PostData {

if ( Number.isInteger( authorId ) ) {
authorRecords = getEntityRecords(
'root', 'user', { include: [ authorId ] }
'root', 'user', { include: [ authorId ], context: 'view' }
) ?? undefined; // Coalescing null to undefined
} else {
authorRecords = null;
Expand All @@ -66,7 +66,7 @@ export function usePostData(): PostData {
categoryIds.every( Number.isInteger )
) {
categoryRecords = getEntityRecords(
'taxonomy', 'category', { include: categoryIds }
'taxonomy', 'category', { include: categoryIds, context: 'view' }
) ?? undefined; // Coalescing null to undefined
} else {
categoryRecords = null;
Expand All @@ -76,7 +76,7 @@ export function usePostData(): PostData {
tagIds.every( Number.isInteger )
) {
tagRecords = getEntityRecords(
'taxonomy', 'post_tag', { include: tagIds }
'taxonomy', 'post_tag', { include: tagIds, context: 'view' }
) ?? undefined; // Coalescing null to undefined
} else {
tagRecords = null;
Expand Down