Make WordPress Core

Opened 11 years ago

Closed 14 months ago

#34093 closed task (blessed) (fixed)

New filter: `get_calendar_post_type` in get_calendar()

Reported by: sebastianpisula's profile sebastian.pisula Owned by: audrasjb's profile audrasjb
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Filter for post type in calendar. If I want show posts from others post type

Attachments (7)

34093.patch (2.5 KB) - added by sebastian.pisula 11 years ago.
34093-2.patch (3.2 KB) - added by dwainm 10 years ago.
requested changes added plus a refreshed patch after revision 36405
34093-3.patch (3.2 KB) - added by dwainm 10 years ago.
Patch with updated spacing.
34093-4.diff (5.4 KB) - added by dwainm 10 years ago.
Adding array args parameter with backwards compatibly for older argument types. Changing the filter to be applied to all args and not just the post type. Allow post type to be submitted as an argument. Also laying the foundation allowing for other arguments to be added in future.
34093-5.diff (5.4 KB) - added by dwainm 10 years ago.
Fixed bug where args are being used before filter. Also fix bug where args filter was assigning to $post_type variable and not $args.
34093-6.diff (6.5 KB) - added by dwainm 10 years ago.
Adding args to all filters in the function also improve comments.
34093-7.diff (8.3 KB) - added by dwainm 10 years ago.
Adding basic tests

Download all attachments as: .zip

Change History (35)

#1 @swissspidy
11 years ago

  • Keywords has-patch needs-refresh added

I can see that this enhancement would be helpful.

Just please use $wpdb->prepare to sanitize the post type and check if $post_type is indeed a valid (public) post type.

@dwainm
10 years ago

requested changes added plus a refreshed patch after revision 36405

#2 @dwainm
10 years ago

  • Keywords needs-refresh removed

@swissspidy I've updated the patch with your requested changes. Please confirm if this is in order.

@dwainm
10 years ago

Patch with updated spacing.

#3 @dwainm
10 years ago

Hi @swissspidy, is the refreshed patch sufficient?

#4 follow-up: @swissspidy
10 years ago

Thanks for the ping, and sorry for missing it before!

Implementation-wise it looks OK, just needs a bit of a cleanup eventually (e.g. the spacing is wrong).

I wonder if we should go even one step further and allow passing an $args param to get_calendar(). That way you could configure the post type, whether it should echo, etc. all when calling the function. Of course it should be backwards compatible.

Then, we could have 1 single get_calendar_args filter for these arguments instead of one only for the post type. That means we could use 34093-3.patch to build upon.

@dwainm
10 years ago

Adding array args parameter with backwards compatibly for older argument types. Changing the filter to be applied to all args and not just the post type. Allow post type to be submitted as an argument. Also laying the foundation allowing for other arguments to be added in future.

@dwainm
10 years ago

Fixed bug where args are being used before filter. Also fix bug where args filter was assigning to $post_type variable and not $args.

#5 in reply to: ↑ 4 @dwainm
10 years ago

  • Version set to trunk

Replying to swissspidy:

Thanks for the ping, and sorry for missing it before!

Implementation-wise it looks OK, just needs a bit of a cleanup eventually (e.g. the spacing is wrong).

I wonder if we should go even one step further and allow passing an $args param to get_calendar(). That way you could configure the post type, whether it should echo, etc. all when calling the function. Of course it should be backwards compatible.

Then, we could have 1 single get_calendar_args filter for these arguments instead of one only for the post type. That means we could use 34093-3.patch to build upon.

@swissspidy Please review the changes in 34093-5.diff. The code styling is updated along with the changes your requested.

#6 @swissspidy
10 years ago

  • Component changed from General to Widgets
  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version trunk deleted

Version is for indicating when a bug was first introduced.

The patch is coming along nicely, thanks @dwainm!

I'm changing milestone to Future Release for now. Also changing the component as get_calendar() is only used in the calendar widget right now. The patch might benefit from some unit tests.

At first glance, the function's docblock needs to be updated. $args should probably be passed to the get_calendar filter.

See https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/ for our PHP Documentation Standards.

@dwainm
10 years ago

Adding args to all filters in the function also improve comments.

@dwainm
10 years ago

Adding basic tests

#7 @moxie
3 years ago

This would be a very welcome addition to the calendar block/widget. I can imagine I just want to show posts from one category, like lectures or meetings or future/past events. For this kind of simple use it would remove the need for extra (events) plugins.

This ticket was mentioned in PR #8251 on WordPress/wordpress-develop by @sukhendu2002.


15 months ago
#8

  • Keywords has-unit-tests added; needs-unit-tests removed

#9 @sukhendu2002
15 months ago

Hi @swissspidy, This improvement looks quite valuable! I've refreshed the patch, would you be able to take a look? Thanks!

#10 @swissspidy
15 months ago

  • Milestone set to 6.8

Oh wow, my last comment here is from 8+ years ago! I don't remember any of that :-)

PR looks like a good start at first glance, but I don't have time for a proper review right now. Maybe @SergeyBiryukov or @audrasjb do.

Otherwise I suggest to bring it up in dev chat or so.

#11 @audrasjb
15 months ago

  • Owner set to audrasjb
  • Status changed from new to reviewing

Thanks for the ping, @swissspidy!
Self assigning for review/test.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


14 months ago

@audrasjb commented on PR #8251:


14 months ago
#13

I tested the changeset and it appears it works fine and respect the backward compatibility of this component.

#14 @audrasjb
14 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 59908:

Widgets: Add post type support to get_calendar() function.

This changeset updates the get_calendar() function to allow post type filtering via the $post_type parameter, with backard compatibility for previous params. It also updates the related get_calendar_args and get_calendar hooks accordingly.

Props sebastianpisula, swissspidy, dwainm, moxie, sukhendu2002, audrasjb, mukesh27.
Fixes #34093.

#15 @audrasjb
14 months ago

In 59909:

Docs: Param indentation improvements in get_calendar() function and hooks.

See #34093.

#16 @audrasjb
14 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening as phpunit tests are failing

#18 @audrasjb
14 months ago

In 59917:

Widgets: Fix get_calendar() related PHPUnit tests.

This is a temporary fix for PHPUnit tests failures after [59908].

Follow-up to [59908].

See #34093.

#19 @audrasjb
14 months ago

In 59918:

Widgets: Fix get_calendar() related PHPUnit tests.

This is a new fix for PHPUnit tests failures after [59908].

Follow-up to [59908], [59917].

See #34093.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


14 months ago

#22 @peterwilsoncc
14 months ago

I got interested and started writing some additional tests while looking at the date issue in the original tests.

It appears there are some caching issues as the post_type and initial parameters are not accounted for when generating the cache key, so there's a few minor fixes to the source code needed.

There's a couple of failing tests in the pull request linked to this ticket.

@audrasjb commented on PR #8446:


14 months ago
#23

Closing in favor of #8447.

#24 @SergeyBiryukov
14 months ago

In 59930:

Tests: Move get_calendar() tests to a more appropriate place.

This aims to bring consistency with the tests for the other functions in wp-includes/general-template.php.

Includes correcting the test class name as per the naming conventions.

Follow-up to [59908].

See #34093.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


14 months ago

#26 @JeffPaul
14 months ago

  • Type changed from enhancement to task (blessed)

As the primary work on this enhancement has been committed and the remaining work is to resolve the failing PHPUnit tests, I'm going to convert this to a task to allow work to continue on resolving those tests during the 6.8 beta period.

@peterwilsoncc commented on PR #8447:


14 months ago
#27

Thanks, I've merged those changes. If you're happy I will commit in the next few hours.

The Chicago in me wants to say you were trying to say "Is youse" which is how "is y'all" would be translated.

It's the same translation down under, maaate. 🦐/BBQ

#28 @peterwilsoncc
14 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 59939:

Widgets: Improve caching within get_calendar().

Improves caching of the get_calendar() function by:

  • fixing incorrect cache collisions for different initial post_type and week values, and,
  • ensuring parameter equivalents generate the same cache key, ie passing the same values in a different order.

Improves tests for the function by:

  • navigating to February 2025 in test set up to ensure the correct calendar month is displayed,
  • adding messages for tests with multiple assertions,
  • improving the tests for the calendar captions by wrapping the expected value in the HTML tag,
  • adding dedicated test for the different initial parameter,
  • ensuring caches do not collide for different parameters, and,
  • ensuring caches do collide for equivalent parameters.

Follow up to r4522, r59908, r59909, r59917 (reverted), r59918 (reverted), r59930.

Props peterwilsoncc, jorbin, audrasjb.
Fixes #34093.

Note: See TracTickets for help on using tickets.