Make WordPress Core

Opened 9 years ago

Last modified 16 months ago

#34093 new enhancement

New filter: `get_calendar_post_type` in get_calendar()

Reported by: sebastianpisula's profile sebastian.pisula Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch needs-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 9 years ago.
34093-2.patch (3.2 KB) - added by dwainm 9 years ago.
requested changes added plus a refreshed patch after revision 36405
34093-3.patch (3.2 KB) - added by dwainm 9 years ago.
Patch with updated spacing.
34093-4.diff (5.4 KB) - added by dwainm 8 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 8 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 8 years ago.
Adding args to all filters in the function also improve comments.
34093-7.diff (8.3 KB) - added by dwainm 8 years ago.
Adding basic tests

Download all attachments as: .zip

Change History (14)

#1 @swissspidy
9 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
9 years ago

requested changes added plus a refreshed patch after revision 36405

#2 @dwainm
9 years ago

  • Keywords needs-refresh removed

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

@dwainm
9 years ago

Patch with updated spacing.

#3 @dwainm
8 years ago

Hi @swissspidy, is the refreshed patch sufficient?

#4 follow-up: @swissspidy
8 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
8 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
8 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
8 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
8 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
8 years ago

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

@dwainm
8 years ago

Adding basic tests

#7 @moxie
16 months 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.

Note: See TracTickets for help on using tickets.