Skip to content

Add On This Day section to Activity widget#66

Open
sabernhardt wants to merge 1 commit into
trunkfrom
activity-widget-on-this-day
Open

Add On This Day section to Activity widget#66
sabernhardt wants to merge 1 commit into
trunkfrom
activity-widget-on-this-day

Conversation

@sabernhardt

Copy link
Copy Markdown
Owner

Lists posts published on the same day (or within date range) in previous years, within the Activity widget.

Based on WordPress#11630 by @alshakero

posts published on this day, within the Activity widget

Trac 65116

Use of AI Tools

nothing in addition to the tool used in PR 11630


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sabernhardt.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

* 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 ) ) ) {

Copy link
Copy Markdown
Owner Author

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.

if ( 'published-posts' === $args['id'] && is_int( $time )
&& $time > ( current_time( 'U' ) - YEAR_IN_SECONDS + ( 1 * DAY_IN_SECONDS ) ) ) {

$wp_otd_date = current_datetime();

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variable names with otd would need editing, but I was more concerned with making them unique for now.

);

$wp_otd_args = array(
'author' => (int) $user_id,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The 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 wp_dashboard_on_this_day_query_args filter.

/* translators: %s: Post title. */
esc_attr( sprintf( __( 'Edit “%s”' ), $draft_or_post_title ) ),
$draft_or_post_title
);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The 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
);
$draft_or_post_title = _draft_or_post_title();
printf(
'<li><span>%1$s</span> <a href="%2$s">%3$s</a></li>',
$date,
get_permalink(),
$draft_or_post_title
);

But then the Recent posts could indicate visually that links in the recent and future lists are for editing, to make the difference clearer.

			$draft_or_post_title = _draft_or_post_title();
			if ( current_user_can( 'edit_post', get_the_ID() ) ) {
				printf(
					'<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
					/* translators: 1: Relative date, 2: Time. */
					sprintf( _x( '%1$s, %2$s', 'dashboard' ), $date, get_the_time() ),
					get_edit_post_link(),
					/* translators: %s: Post title. */
					esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $draft_or_post_title ) ),
					'<span class="dashicons dashicons-edit" aria-hidden="true"></span>' . $draft_or_post_title
				);
			} else {
				printf(
					'<li><span>%1$s</span> <a href="%2$s">%3$s</a></li>',
					/* translators: 1: Relative date, 2: Time. */
					sprintf( _x( '%1$s, %2$s', 'dashboard' ), $date, get_the_time() ),
					get_permalink(),
					$draft_or_post_title
				);
			}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant