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

Added filter for arguments for latest posts block #38283

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

martinjankov
Copy link

@martinjankov martinjankov commented Jan 27, 2022

Trac link: https://core.trac.wordpress.org/ticket/54580

Description

Added widget_posts_args filter for latest posts query arguments.

Testing Instructions

  1. Add widget_posts_args filter and exclude the latest posts via post__not_in
  2. Create new Page / Post and add the Latest Posts Block
  3. The latest post will not show in the list of posts

Screenshots

Types of changes

New feature (non-breaking change which adds functionality)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
  • I've updated related schemas if appropriate.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jan 27, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @martinjankov! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Mamaduka Mamaduka self-requested a review February 2, 2022 10:10
@Mamaduka
Copy link
Member

@ntsekouras, what's the policy for adding classic widget filters to the Widget blocks?

@ntsekouras
Copy link
Contributor

ntsekouras commented Feb 15, 2022

Thanks for the PR @martinjankov!

I don't think we should add a widgets specific filter in a core block. Having said that, @draganescu or @talldan might have more insights about widgets and possible work arounds with another existing filter..

@draganescu
Copy link
Contributor

Hi @martinjankov I don't think this is a good path forward. The block has a directly editable UI for these settings. Adding a filter like that would override user settings. If you need a special case of a block the best way, today, is to create your own block implementing the special case.

Am I missing something obvious?

My suggestion is to close this PR. Any other thoughts @noisysocks ?

@noisysocks
Copy link
Member

Hmm, I'm not sure.

On the one hand, we do have a few other filters in blocks that were designed to replace widgets.

% rg -C 1 apply_filters packages/block-library
packages/block-library/src/post-content/index.php
54-	/** This filter is documented in wp-includes/post-template.php */
55:	$content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) );
56-	unset( $seen_ids[ $post_id ] );

packages/block-library/src/latest-comments/index.php
45-		/** This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php */
46:		apply_filters(
47-			'widget_comments_args',

packages/block-library/src/archives/index.php
29-		/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
30:		$dropdown_args = apply_filters(
31-			'widget_archives_dropdown_args',
--
78-	/** This filter is documented in wp-includes/widgets/class-wp-widget-archives.php */
79:	$archives_args = apply_filters(
80-		'widget_archives_args',

packages/block-library/src/navigation/index.php
349-	 */
350:	return apply_filters( 'block_core_navigation_render_fallback', $fallback_blocks );
351-}

On the other hand, blocks aren't widgets, and we already have filters for customising a block and its attributes before it is rendered e.g. pre_render_block, render_block_data, render_block.

@draganescu
Copy link
Contributor

blocks aren't widgets, and we already have filters for customising a block and its attributes before it is rendered e.g. pre_render_block, render_block_data, render_block.

This is specifically my point.

@skorasaurus skorasaurus added the [Block] Latest Posts Affects the Latest Posts Block label Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latest Posts Affects the Latest Posts Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants