Skip to:
Content

BuddyPress.org

Changeset 14164


Ignore:
Timestamp:
12/23/2025 02:18:42 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.

Developed in https://github.com/buddypress/buddypress/pull/411

Props shawfactor, rollybueno, and dcavins.

See #9286 (14.0).

File:
1 edited

Legend:

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

    r13844 r14164  
    490490        }
    491491
     492/**
     493 * Output the permalink of the current blog in the loop.
     494 *
     495 * @since 1.0.0
     496 */
    492497function bp_blog_permalink() {
    493498        echo esc_url( bp_get_blog_permalink() );
    494499}
     500        /**
     501         * Return the permalink of the current blog in the loop.
     502         *
     503         * @since 1.0.0
     504         *
     505         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     506         *
     507         * @return string
     508         */
    495509        function bp_get_blog_permalink() {
    496510                global $blogs_template;
     
    527541         * Return the name of the current blog in the loop.
    528542         *
     543         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     544         *
    529545         * @return string The name of the current blog in the loop.
    530546         */
     
    555571         * @since 1.7.0
    556572         *
     573         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     574         *
    557575         * @return int ID of the current blog in the loop.
    558576         */
     
    586604        /**
    587605         * Return the description of the current blog in the loop.
     606         *
     607         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
    588608         *
    589609         * @return string Description of the current blog in the loop.
     
    645665                $classes = array_map( 'sanitize_html_class', apply_filters( 'bp_get_blog_class', $classes ) );
    646666                $classes = array_merge( $classes, array() );
    647                 $retval  = 'class="' . join( ' ', $classes ) . '"';
    648 
    649                 return $retval;
     667
     668                return 'class="' . join( ' ', $classes ) . '"';
    650669        }
    651670
     
    746765                );
    747766
    748                 $retval = bp_get_blog_latest_post_title();
     767                $retval  = bp_get_blog_latest_post_title();
     768                $post_id = bp_get_blog_latest_post_id();
    749769
    750770                if ( ! empty( $retval ) ) {
     
    761781                                        /* translators: %s: the title of the latest post */
    762782                                        __( 'Latest Post: %s', 'buddypress' ),
    763                                         '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>'
     783                                        '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval, $post_id ) . '</a>'
    764784                                );
    765785                        } else {
    766786
    767787                                /** This filter is documented in bp-blogs/bp-blogs-template.php */
    768                                 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>';
     788                                $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval, $post_id ) . '</a>';
    769789                        }
    770790                }
     
    783803
    784804/**
     805 * Output the ID of the latest post on the current blog in the loop.
     806 *
     807 * @since 14.5.0
     808 *
     809 * @see bp_get_blog_latest_post_id()
     810 */
     811function bp_blog_latest_post_id() {
     812        echo bp_get_blog_latest_post_id();
     813}
     814        /**
     815         * Return the ID of the latest post on the current blog in the loop.
     816         *
     817         * @since 14.5.0
     818         *
     819         * @global BP_Blogs_Template $blogs_template The main blog template loop class.
     820         *
     821         * @return int
     822         */
     823        function bp_get_blog_latest_post_id() {
     824                global $blogs_template;
     825
     826                $latest_post_id = 0;
     827
     828                if (
     829                        ! empty( $blogs_template->blog->latest_post )
     830                        && ! empty( $blogs_template->blog->latest_post->ID )
     831                        && is_int( $blogs_template->blog->latest_post->ID )
     832                ) {
     833                        $latest_post_id = $blogs_template->blog->latest_post->ID;
     834                }
     835
     836                /**
     837                 * Filters the ID of the latest post on the current blog in the loop.
     838                 *
     839                 * @since 14.5.0
     840                 *
     841                 * @param int $latest_post_id ID of the latest post.
     842                 */
     843                return (int) apply_filters( 'bp_get_blog_latest_post_id', (int) $latest_post_id );
     844        }
     845
     846/**
    785847 * Output the title of the latest post on the current blog in the loop.
    786848 *
     
    806868                $retval = '';
    807869
    808                 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
     870                if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) ) {
    809871                        $retval = $blogs_template->blog->latest_post->post_title;
     872                }
    810873
    811874                /**
     
    834897         * @since 1.7.0
    835898         *
    836          * @global BP_Blogs_Template $blogs_template The main blog template loop class.
    837          *
    838899         * @return string URL of the blog's latest post.
    839900         */
    840901        function bp_get_blog_latest_post_permalink() {
    841                 global $blogs_template;
    842 
    843                 $retval = '';
    844 
    845                 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
    846                         $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
     902                $retval  = '';
     903                $post_id = bp_get_blog_latest_post_id();
     904
     905                if ( ! empty( $post_id ) ) {
     906                        $retval = add_query_arg( 'p', $post_id, bp_get_blog_permalink() );
     907                }
    847908
    848909                /**
Note: See TracChangeset for help on using the changeset viewer.