Skip to content

Fix: bp_get_blog_latest_post using the_title filters with missing param#411

Closed
rollybueno wants to merge 3 commits intobuddypress:masterfrom
rollybueno:bugfix/bp_get_blog_latest_post
Closed

Fix: bp_get_blog_latest_post using the_title filters with missing param#411
rollybueno wants to merge 3 commits intobuddypress:masterfrom
rollybueno:bugfix/bp_get_blog_latest_post

Conversation

@rollybueno
Copy link
Copy Markdown

Reported on https://buddypress.trac.wordpress.org/ticket/9286, the bp_get_blog_latest_post() will be using the_title filters but only provided 1 out of 2 required params

The patch includes creating new function called bp_get_blog_latest_post_id() which is just a copy of bp_get_blog_latest_post_title(), except it will return latest post ID instead of title.

Then we use this for the required param on the_title filters as per documentation: https://developer.wordpress.org/reference/hooks/the_title/

Ticket: https://buddypress.trac.wordpress.org/ticket/9286

Filter docs: https://developer.wordpress.org/reference/hooks/the_title/

Trac ticket: https://buddypress.trac.wordpress.org/ticket/9286


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

…uired param

Reported on https://buddypress.trac.wordpress.org/ticket/9286, the bp_get_blog_latest_post() will be using the_title filters but only provided 1 out of 2 params

The patch includes creating new function called bp_get_blog_latest_post_id() which is just a copy of bp_get_blog_latest_post_title(), except it will return latest post ID instead of title.

Then we use this for the  required param on the_title filters as per documentation: https://developer.wordpress.org/reference/hooks/the_title/

Ticket: https://buddypress.trac.wordpress.org/ticket/9286

Filter docs: https://developer.wordpress.org/reference/hooks/the_title/
Copy link
Copy Markdown
Contributor

@dcavins dcavins left a comment

Choose a reason for hiding this comment

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

Thanks for your PR!

* @see bp_get_blog_latest_post_id()
*/
function bp_blog_latest_post_id() {
echo esc_html( bp_get_blog_latest_post_id() );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You shouldn't need esc_html() here, as long as bp_get_blog_latest_post_id() always returns an integer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for your feedback. I was get used to the Plugin Check, maybe it's became a habit now 😅

Corrected with the rest of your feedback. 🍺

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The WP coding standards check failed because WP does want this to the be escaped. According to their docs,
echo (int) bp_get_blog_latest_post_id(); or echo absint( bp_get_blog_latest_post_id() );
should be acceptable. Sorry for misdirecting you!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi, I've updated this. Thanks!

*
* @global BP_Blogs_Template $blogs_template The main blog template loop class.
*
* @return string Post ID.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The return type should be an integer, since a post ID is an integer.

}

/**
* Filters the title text of the latest post on the current blog in the loop.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This filter doc block still refers to the title function filter.

*
* @param string $retval Title text for the latest post.
*/
return apply_filters( 'bp_get_blog_latest_post_id', $retval );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It shouldn't be needed, but maybe adding a cast to integer would make everyone feel better here. Like:
return apply_filters( 'bp_get_blog_latest_post_id', (int) $retval );

function bp_get_blog_latest_post_id() {
global $blogs_template;

$retval = '';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The default should probably be 0 since we're returning an integer.

dcavins pushed a commit to dcavins/buddypress-wp-svn that referenced this pull request Jan 26, 2026
…ut only one param is provided.

We are introducing two new getters for the latest post ID. `bp_get_blog_latest_post_id` and `bp_blog_latest_post_id`.

Props shawfactor, rollybueno, and dcavins.

Closes buddypress/buddypress#411
Fixes #9286 (trunk)

git-svn-id: http://buddypress.svn.wordpress.org/trunk@14165 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
dcavins pushed a commit to dcavins/buddypress-wp-svn that referenced this pull request Jan 26, 2026
…ut only one param is provided.

We are introducing two new getters for the latest post ID. `bp_get_blog_latest_post_id` and `bp_blog_latest_post_id`.

Developed in buddypress/buddypress#411

Props shawfactor, rollybueno, and dcavins.

See #9286 (14.0).

git-svn-id: http://buddypress.svn.wordpress.org/branches/14.0@14164 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
boonebgorges pushed a commit that referenced this pull request Jan 26, 2026
…ut only one param is provided.

We are introducing two new getters for the latest post ID. `bp_get_blog_latest_post_id` and `bp_blog_latest_post_id`.

Developed in #411

Props shawfactor, rollybueno, and dcavins.

See #9286 (14.0).

git-svn-id: https://buddypress.svn.wordpress.org/branches/14.0@14164 cdf35c40-ae34-48e0-9cc9-0c9da1808c22
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.

2 participants