-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Calendar block: Always show current month for non post types on the editor #13873
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,18 +13,22 @@ | |
* @return string Returns the block content. | ||
*/ | ||
function render_block_core_calendar( $attributes ) { | ||
global $monthnum, $year, $post; | ||
global $monthnum, $year; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there lint options available to make it so this sort of error is impossible to introduce? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like there are some tools created by the community that allows us to do that https://github.com/sirbrillig/phpcs-variable-analysis. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related discussion WordPress/WordPress-Coding-Standards#1221. |
||
|
||
$previous_monthnum = $monthnum; | ||
$previous_year = $year; | ||
|
||
if ( isset( $attributes['month'] ) ) { | ||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
$monthnum = $attributes['month']; | ||
} | ||
|
||
if ( isset( $attributes['year'] ) ) { | ||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
$year = $attributes['year']; | ||
if ( isset( $attributes['month'] ) && isset( $attributes['year'] ) ) { | ||
$permalink_structure = get_option( 'permalink_structure' ); | ||
if ( | ||
strpos( $permalink_structure, '%monthnum%' ) !== false && | ||
strpos( $permalink_structure, '%year%' ) !== false | ||
) { | ||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
$monthnum = $attributes['month']; | ||
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited | ||
$year = $attributes['year']; | ||
} | ||
} | ||
|
||
$custom_class_name = empty( $attributes['className'] ) ? '' : ' ' . $attributes['className']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Why is the block dependent on the current post being edited? Is the widget dependent on posts too? Doesn't seem like it since the widget can be used in pages without any post?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's complex, see my investigation summarized in this comment: #13772 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @youknowriad, In fact, the widget depends on the post and shows the calendar of the post publish date the widget is being shown in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a summary of the research I did while implementing the block:
The calendar widget renders the calendar of the month the current post was published, if the widget is an archives page it renders the calendar of that month, and if it is a neutral non-date specific page (homepage, taxonomy, author, and as @gziolo referred page and other cpts) it renders the calendar of the current month.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it :) I guess we'll have to revisit this once we start the widgets page as there won't be any
getEditedPostAttribute
selector there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is going to be an interesting challenge.