Fix: bp_get_blog_latest_post using the_title filters with missing param#411
Fix: bp_get_blog_latest_post using the_title filters with missing param#411rollybueno wants to merge 3 commits intobuddypress:masterfrom
Conversation
…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/
src/bp-blogs/bp-blogs-template.php
Outdated
| * @see bp_get_blog_latest_post_id() | ||
| */ | ||
| function bp_blog_latest_post_id() { | ||
| echo esc_html( bp_get_blog_latest_post_id() ); |
There was a problem hiding this comment.
You shouldn't need esc_html() here, as long as bp_get_blog_latest_post_id() always returns an integer.
There was a problem hiding this comment.
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. 🍺
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Hi, I've updated this. Thanks!
src/bp-blogs/bp-blogs-template.php
Outdated
| * | ||
| * @global BP_Blogs_Template $blogs_template The main blog template loop class. | ||
| * | ||
| * @return string Post ID. |
There was a problem hiding this comment.
The return type should be an integer, since a post ID is an integer.
src/bp-blogs/bp-blogs-template.php
Outdated
| } | ||
|
|
||
| /** | ||
| * Filters the title text of the latest post on the current blog in the loop. |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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 );
src/bp-blogs/bp-blogs-template.php
Outdated
| function bp_get_blog_latest_post_id() { | ||
| global $blogs_template; | ||
|
|
||
| $retval = ''; |
There was a problem hiding this comment.
The default should probably be 0 since we're returning an integer.
…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
…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
…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
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.