Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/23/2025 02:20:11 AM (7 months ago)
Author:
espellcaste
Message:

bp_get_blog_latest_post() make use of the the_title filter hook but 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 https://github.com/buddypress/buddypress/pull/411
Fixes #9286 (trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-template.php

    r14077 r14165  
    492492        }
    493493
     494/**
     495 * Output the permalink of the current blog in the loop.
     496 *
     497 * @since 1.0.0
     498 */
    494499function bp_blog_permalink() {
    495500        echo esc_url( bp_get_blog_permalink() );
    496501}
     502        /**
     503         * Return the permalink of the current blog in the loop.
     504         *
     505         * @since 1.0.0
     506         *
     507         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     508         *
     509         * @return string
     510         */
    497511        function bp_get_blog_permalink() {
    498512                global $blogs_template;
     
    529543         * Return the name of the current blog in the loop.
    530544         *
     545         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     546         *
    531547         * @return string The name of the current blog in the loop.
    532548         */
     
    563579         * @since 1.7.0
    564580         *
     581         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     582         *
    565583         * @return int ID of the current blog in the loop.
    566584         */
     
    594612        /**
    595613         * Return the description of the current blog in the loop.
     614         *
     615         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
    596616         *
    597617         * @return string Description of the current blog in the loop.
     
    653673                $classes = array_map( 'sanitize_html_class', apply_filters( 'bp_get_blog_class', $classes ) );
    654674                $classes = array_merge( $classes, array() );
    655                 $retval  = 'class="' . join( ' ', $classes ) . '"';
    656 
    657                 return $retval;
     675
     676                return 'class="' . join( ' ', $classes ) . '"';
    658677        }
    659678
     
    754773                );
    755774
    756                 $retval = bp_get_blog_latest_post_title();
     775                $retval  = bp_get_blog_latest_post_title();
     776                $post_id = bp_get_blog_latest_post_id();
    757777
    758778                if ( ! empty( $retval ) ) {
     
    769789                                        /* translators: %s: the title of the latest post */
    770790                                        __( 'Latest Post: %s', 'buddypress' ),
    771                                         '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>'
     791                                        '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval, $post_id ) . '</a>'
    772792                                );
    773793                        } else {
    774794
    775795                                /** This filter is documented in bp-blogs/bp-blogs-template.php */
    776                                 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>';
     796                                $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval, $post_id ) . '</a>';
    777797                        }
    778798                }
     
    791811
    792812/**
     813 * Output the ID of the latest post on the current blog in the loop.
     814 *
     815 * @since 14.5.0
     816 *
     817 * @see bp_get_blog_latest_post_id()
     818 */
     819function bp_blog_latest_post_id() {
     820        echo bp_get_blog_latest_post_id();
     821}
     822        /**
     823         * Return the ID of the latest post on the current blog in the loop.
     824         *
     825         * @since 14.5.0
     826         *
     827         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     828         *
     829         * @return int
     830         */
     831        function bp_get_blog_latest_post_id() {
     832                global $blogs_template;
     833
     834                $latest_post_id = 0;
     835
     836                if (
     837                        ! empty( $blogs_template->blog->latest_post )
     838                        && ! empty( $blogs_template->blog->latest_post->ID )
     839                        && is_int( $blogs_template->blog->latest_post->ID )
     840                ) {
     841                        $latest_post_id = $blogs_template->blog->latest_post->ID;
     842                }
     843
     844                /**
     845                 * Filters the ID of the latest post on the current blog in the loop.
     846                 *
     847                 * @since 14.5.0
     848                 *
     849                 * @param int $latest_post_id ID of the latest post.
     850                 */
     851                return (int) apply_filters( 'bp_get_blog_latest_post_id', (int) $latest_post_id );
     852        }
     853
     854/**
    793855 * Output the title of the latest post on the current blog in the loop.
    794856 *
     
    814876                $retval = '';
    815877
    816                 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
     878                if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) ) {
    817879                        $retval = $blogs_template->blog->latest_post->post_title;
     880                }
    818881
    819882                /**
     
    842905         * @since 1.7.0
    843906         *
    844          * @global BP_Blogs_Template $blogs_template The main blog template loop class.
    845          *
    846907         * @return string URL of the blog's latest post.
    847908         */
    848909        function bp_get_blog_latest_post_permalink() {
    849                 global $blogs_template;
    850 
    851                 $retval = '';
    852 
    853                 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
    854                         $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
     910                $retval  = '';
     911                $post_id = bp_get_blog_latest_post_id();
     912
     913                if ( ! empty( $post_id ) ) {
     914                        $retval = add_query_arg( 'p', $post_id, bp_get_blog_permalink() );
     915                }
    855916
    856917                /**
Note: See TracChangeset for help on using the changeset viewer.