-
Notifications
You must be signed in to change notification settings - Fork 0
Add On This Day section to Activity widget #66
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
base: trunk
Are you sure you want to change the base?
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1015,7 +1015,7 @@ function wp_dashboard_recent_posts( $args ) { | |||||||||||||||||
|
|
||||||||||||||||||
| $today = current_time( 'Y-m-d' ); | ||||||||||||||||||
| $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' ); | ||||||||||||||||||
| $year = current_time( 'Y' ); | ||||||||||||||||||
| $year = (int) current_time( 'Y' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| while ( $posts->have_posts() ) { | ||||||||||||||||||
| $posts->the_post(); | ||||||||||||||||||
|
|
@@ -1053,6 +1053,106 @@ function wp_dashboard_recent_posts( $args ) { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| echo '</ul>'; | ||||||||||||||||||
|
|
||||||||||||||||||
| /* | ||||||||||||||||||
| * List posts published on this day in previous years if the final post | ||||||||||||||||||
| * in the recently published list is within the past year (minus 1 day). | ||||||||||||||||||
| */ | ||||||||||||||||||
| if ( 'published-posts' === $args['id'] && is_int( $time ) | ||||||||||||||||||
| && $time > ( current_time( 'U' ) - YEAR_IN_SECONDS + ( 1 * DAY_IN_SECONDS ) ) ) { | ||||||||||||||||||
|
|
||||||||||||||||||
| $wp_otd_date = current_datetime(); | ||||||||||||||||||
|
Owner
Author
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. These variable names with |
||||||||||||||||||
| $wp_otd_clauses = array(); | ||||||||||||||||||
| $window_before_days = 0; // Edit before and after if creating a range. | ||||||||||||||||||
| $window_after_days = 0; | ||||||||||||||||||
| $user_id = get_current_user_id(); | ||||||||||||||||||
|
|
||||||||||||||||||
| for ( $offset = -$window_before_days; $offset <= $window_after_days; $offset++ ) { | ||||||||||||||||||
| $wp_otd_day_date = $wp_otd_date->modify( ( $offset >= 0 ? '+' : '' ) . $offset . ' days' ); | ||||||||||||||||||
| $wp_otd_clauses[] = array( | ||||||||||||||||||
| 'month' => (int) $wp_otd_day_date->format( 'n' ), | ||||||||||||||||||
| 'day' => (int) $wp_otd_day_date->format( 'j' ), | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| $wp_otd_date_query = array( | ||||||||||||||||||
| 'relation' => 'AND', | ||||||||||||||||||
| array( | ||||||||||||||||||
| 'before' => array( 'year' => $year ), | ||||||||||||||||||
| ), | ||||||||||||||||||
| array_merge( | ||||||||||||||||||
| array( 'relation' => 'OR' ), | ||||||||||||||||||
| $wp_otd_clauses | ||||||||||||||||||
| ), | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| $wp_otd_args = array( | ||||||||||||||||||
| 'author' => (int) $user_id, | ||||||||||||||||||
|
Owner
Author
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. Like PR 11630, this limits the posts to any created by (or assigned to) the current user instead of all posts on the site. The argument could be removed, either for the default query or for individual sites with the |
||||||||||||||||||
| 'post_type' => 'post', | ||||||||||||||||||
| 'post_status' => array( 'publish' ), | ||||||||||||||||||
| 'posts_per_page' => 50, | ||||||||||||||||||
| 'ignore_sticky_posts' => true, | ||||||||||||||||||
| 'orderby' => 'date', | ||||||||||||||||||
| 'order' => 'DESC', | ||||||||||||||||||
| 'no_found_rows' => true, | ||||||||||||||||||
| 'update_post_term_cache' => false, | ||||||||||||||||||
| 'date_query' => $wp_otd_date_query, | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Filters the arguments used to query posts for the On This Day dashboard widget. | ||||||||||||||||||
| * | ||||||||||||||||||
| * @since 7.1.0 | ||||||||||||||||||
| * | ||||||||||||||||||
| * @param array $wp_otd_args WP_Query arguments. | ||||||||||||||||||
| * @param int $user_id The author ID the query is scoped to. | ||||||||||||||||||
| */ | ||||||||||||||||||
| $wp_otd_args = apply_filters( 'wp_dashboard_on_this_day_query_args', $wp_otd_args, $user_id ); | ||||||||||||||||||
|
|
||||||||||||||||||
| $wp_otd_query = new WP_Query( $wp_otd_args ); | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( $wp_otd_query->have_posts() ) { | ||||||||||||||||||
|
|
||||||||||||||||||
| echo '<div id="wp-on-this-day" class="activity-block">'; | ||||||||||||||||||
|
|
||||||||||||||||||
| echo '<h3>' . __( 'Published On This Day' ) . '</h3>'; | ||||||||||||||||||
|
|
||||||||||||||||||
| echo '<ul>'; | ||||||||||||||||||
|
|
||||||||||||||||||
| while ( $wp_otd_query->have_posts() ) { | ||||||||||||||||||
| $wp_otd_query->the_post(); | ||||||||||||||||||
|
|
||||||||||||||||||
| $time = get_the_time( 'U' ); | ||||||||||||||||||
|
|
||||||||||||||||||
| if ( ! is_int( $time ) ) { | ||||||||||||||||||
| /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */ | ||||||||||||||||||
| $date = get_the_date( __( 'M jS Y' ) ); | ||||||||||||||||||
| } else { | ||||||||||||||||||
| /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */ | ||||||||||||||||||
| $date = date_i18n( __( 'M jS Y' ), $time ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // Use the post edit link for those who can edit, the permalink otherwise. | ||||||||||||||||||
| $recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink(); | ||||||||||||||||||
|
|
||||||||||||||||||
| $draft_or_post_title = _draft_or_post_title(); | ||||||||||||||||||
| printf( | ||||||||||||||||||
| '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>', | ||||||||||||||||||
| $date, | ||||||||||||||||||
| $recent_post_link, | ||||||||||||||||||
| /* translators: %s: Post title. */ | ||||||||||||||||||
| esc_attr( sprintf( __( 'Edit “%s”' ), $draft_or_post_title ) ), | ||||||||||||||||||
| $draft_or_post_title | ||||||||||||||||||
| ); | ||||||||||||||||||
|
Owner
Author
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. I copied this from lines 1040 to 1052, and changed the date and time to only the date. As a result, the link is for editing the post if the user has edit access. If the link is for viewing regardless of access, it would have no need for the ARIA label.
Suggested change
But then the Recent posts could indicate visually that links in the recent and future lists are for editing, to make the difference clearer. |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| echo '</ul>'; | ||||||||||||||||||
| echo '</div>'; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| wp_reset_postdata(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| echo '</div>'; | ||||||||||||||||||
|
|
||||||||||||||||||
| } else { | ||||||||||||||||||
|
|
||||||||||||||||||
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.
The time condition avoids running the On This Day query if the Recent posts list might already include a post from the same day in a previous year. If the query uses a date range, the number of days in seconds would increase.