Skip to:
Content

BuddyPress.org

Changeset 8408


Ignore:
Timestamp:
05/10/2014 01:37:05 AM (6 years ago)
Author:
boonebgorges
Message:

Introduce 'latest_format' param for bp_get_blog_latest_post()

This param allows themers to omit BP's 'Latest post: %s' wrapper around the
link to the latest post.

Fixes #5392

Props lenasterg

Location:
trunk
Files:
3 edited

Legend:

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

    r8407 r8408  
    672672/**
    673673 * Output the latest post from the current blog in the loop.
    674  */
    675 function bp_blog_latest_post() {
    676     echo bp_get_blog_latest_post();
     674 *
     675 * @param array $args See {@link bp_get_blog_latest_post()}.
     676 */
     677function bp_blog_latest_post( $args = array() ) {
     678    echo bp_get_blog_latest_post( $args );
    677679}
    678680    /**
    679681     * Return the latest post from the current blog in the loop.
    680682     *
     683     * @param array $args {
     684     *     Array of optional arguments.
     685     *     @type bool $latest_format If true, formatted "Latest post:
     686     *           [link to post]". If false, formatted "[link to post]".
     687     *           Default: true.
     688     * }
    681689     * @return string $retval String of the form 'Latest Post: [link to post]'.
    682690     */
    683     function bp_get_blog_latest_post() {
     691    function bp_get_blog_latest_post( $args = array() ) {
    684692        global $blogs_template;
    685693
     694        $r = wp_parse_args( $args, array(
     695            'latest_format' => true,
     696        ) );
     697
    686698        $retval = bp_get_blog_latest_post_title();
    687699
    688         if ( ! empty( $retval ) )
    689             $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
     700        if ( ! empty( $retval ) ) {
     701            if ( ! empty( $r['latest_format'] ) ) {
     702                $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
     703            } else {
     704                $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>';
     705            }
     706        }
    690707
    691708        return apply_filters( 'bp_get_blog_latest_post', $retval );
  • trunk/src/bp-languages/buddypress.pot

    r8404 r8408  
    55"Project-Id-Version: BuddyPress 2.1-alpha\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/buddypress\n"
    7 "POT-Creation-Date: 2014-05-10 00:44:57+00:00\n"
     7"POT-Creation-Date: 2014-05-10 01:35:41+00:00\n"
    88"MIME-Version: 1.0\n"
    99"Content-Type: text/plain; charset=utf-8\n"
     
    784784msgstr ""
    785785
    786 #: bp-activity/bp-activity-screens.php:271 bp-blogs/bp-blogs-template.php:997
     786#: bp-activity/bp-activity-screens.php:271 bp-blogs/bp-blogs-template.php:1035
    787787#: bp-friends/bp-friends-screens.php:86 bp-groups/bp-groups-screens.php:937
    788788#: bp-messages/bp-messages-screens.php:169
     
    792792msgstr ""
    793793
    794 #: bp-activity/bp-activity-screens.php:272 bp-blogs/bp-blogs-template.php:1001
     794#: bp-activity/bp-activity-screens.php:272 bp-blogs/bp-blogs-template.php:1039
    795795#: bp-friends/bp-friends-screens.php:87 bp-groups/bp-groups-screens.php:938
    796796#: bp-messages/bp-messages-screens.php:170
     
    960960
    961961#: bp-blogs/bp-blogs-loader.php:208 bp-blogs/bp-blogs-screens.php:204
    962 #: bp-blogs/bp-blogs-template.php:1114 bp-blogs/bp-blogs-template.php:1182
    963 #: bp-blogs/bp-blogs-template.php:1183 bp-core/bp-core-filters.php:466
     962#: bp-blogs/bp-blogs-template.php:1152 bp-blogs/bp-blogs-template.php:1220
     963#: bp-blogs/bp-blogs-template.php:1221 bp-core/bp-core-filters.php:466
    964964#: bp-themes/bp-default/blogs/create.php:21
    965965#: bp-themes/bp-default/blogs/index.php:21
     
    977977msgstr ""
    978978
    979 #: bp-blogs/bp-blogs-template.php:648 bp-core/bp-core-classes.php:816
     979#: bp-blogs/bp-blogs-template.php:661 bp-core/bp-core-classes.php:816
    980980#: bp-groups/bp-groups-template.php:3394 bp-groups/bp-groups-widgets.php:85
    981981#: bp-groups/bp-groups-widgets.php:197 bp-members/bp-members-template.php:811
     
    988988msgstr ""
    989989
    990 #: bp-blogs/bp-blogs-template.php:668
     990#: bp-blogs/bp-blogs-template.php:666 bp-members/bp-members-template.php:816
     991msgid "Never active"
     992msgstr ""
     993
     994#: bp-blogs/bp-blogs-template.php:702
    991995msgid "Latest Post: %s"
    992996msgstr ""
    993997
    994 #: bp-blogs/bp-blogs-template.php:915
     998#: bp-blogs/bp-blogs-template.php:953
    995999msgid "There was a problem, please correct the form below and try again."
    9961000msgstr ""
    9971001
    998 #: bp-blogs/bp-blogs-template.php:918
     1002#: bp-blogs/bp-blogs-template.php:956
    9991003msgid ""
    10001004"By filling out the form below, you can <strong>add a site to your "
     
    10031007msgstr ""
    10041008
    1005 #: bp-blogs/bp-blogs-template.php:920
     1009#: bp-blogs/bp-blogs-template.php:958
    10061010msgid ""
    10071011"If you&#8217;re not going to use a great domain, leave it for a new user. "
     
    10091013msgstr ""
    10101014
    1011 #: bp-blogs/bp-blogs-template.php:929
     1015#: bp-blogs/bp-blogs-template.php:967
    10121016msgid "Create Site"
    10131017msgstr ""
    10141018
    1015 #: bp-blogs/bp-blogs-template.php:951
     1019#: bp-blogs/bp-blogs-template.php:989
    10161020msgid "Site Name:"
    10171021msgstr ""
    10181022
    1019 #: bp-blogs/bp-blogs-template.php:953
     1023#: bp-blogs/bp-blogs-template.php:991
    10201024msgid "Site Domain:"
    10211025msgstr ""
    10221026
    1023 #: bp-blogs/bp-blogs-template.php:967
     1027#: bp-blogs/bp-blogs-template.php:1005
    10241028msgid "Your address will be "
    10251029msgstr ""
    10261030
    1027 #: bp-blogs/bp-blogs-template.php:970
     1031#: bp-blogs/bp-blogs-template.php:1008
    10281032msgid "blogname"
    10291033msgstr ""
    10301034
    1031 #: bp-blogs/bp-blogs-template.php:972
     1035#: bp-blogs/bp-blogs-template.php:1010
    10321036msgid "domain."
    10331037msgstr ""
    10341038
    1035 #: bp-blogs/bp-blogs-template.php:975
     1039#: bp-blogs/bp-blogs-template.php:1013
    10361040msgid ""
    10371041"Must be at least 4 characters, letters and numbers only. It cannot be "
     
    10391043msgstr ""
    10401044
    1041 #: bp-blogs/bp-blogs-template.php:981
     1045#: bp-blogs/bp-blogs-template.php:1019
    10421046msgid "Site Title:"
    10431047msgstr ""
    10441048
    1045 #: bp-blogs/bp-blogs-template.php:992
     1049#: bp-blogs/bp-blogs-template.php:1030
    10461050msgid "Privacy:"
    10471051msgstr ""
    10481052
    1049 #: bp-blogs/bp-blogs-template.php:993
     1053#: bp-blogs/bp-blogs-template.php:1031
    10501054#: bp-templates/bp-legacy/buddypress/members/register.php:145
    10511055#: bp-themes/bp-default/registration/register.php:229
     
    10551059msgstr ""
    10561060
    1057 #: bp-blogs/bp-blogs-template.php:1100
     1061#: bp-blogs/bp-blogs-template.php:1138
    10581062msgid "Congratulations! You have successfully registered a new site."
    10591063msgstr ""
    10601064
    1061 #: bp-blogs/bp-blogs-template.php:1102
     1065#: bp-blogs/bp-blogs-template.php:1140
    10621066msgid ""
    10631067"<a href=\"%1$s\">%2$s</a> is your new site.  <a href=\"%3$s\">Login</a> as "
     
    10651069msgstr ""
    10661070
    1067 #: bp-blogs/bp-blogs-template.php:1131
     1071#: bp-blogs/bp-blogs-template.php:1169
    10681072msgid "%s's Sites"
    10691073msgstr ""
    10701074
    1071 #: bp-blogs/bp-blogs-template.php:1132
     1075#: bp-blogs/bp-blogs-template.php:1170
    10721076msgid "%s's Recent Posts"
    10731077msgstr ""
    10741078
    1075 #: bp-blogs/bp-blogs-template.php:1133
     1079#: bp-blogs/bp-blogs-template.php:1171
    10761080msgid "%s's Recent Comments"
    10771081msgstr ""
    10781082
    1079 #: bp-blogs/bp-blogs-template.php:1149 bp-core/deprecated/1.5.php:417
     1083#: bp-blogs/bp-blogs-template.php:1187 bp-core/deprecated/1.5.php:417
    10801084#: bp-forums/bp-forums-template.php:2196 bp-groups/bp-groups-template.php:2798
    10811085#: bp-members/bp-members-template.php:999
     
    10851089msgstr ""
    10861090
    1087 #: bp-blogs/bp-blogs-template.php:1232 bp-blogs/bp-blogs-template.php:1233
     1091#: bp-blogs/bp-blogs-template.php:1270 bp-blogs/bp-blogs-template.php:1271
    10881092msgid "Visit Site"
    10891093msgstr ""
    10901094
    1091 #: bp-blogs/bp-blogs-template.php:1288
     1095#: bp-blogs/bp-blogs-template.php:1326
    10921096msgid "%s site"
    10931097msgid_plural "%s sites"
     
    46344638msgstr[0] ""
    46354639msgstr[1] ""
    4636 
    4637 #: bp-members/bp-members-template.php:816
    4638 msgid "Never active"
    4639 msgstr ""
    46404640
    46414641#: bp-members/bp-members-template.php:1693
  • trunk/tests/phpunit/testcases/blogs/template.php

    r8407 r8408  
    6262        $this->assertEquals( __( 'Never active', 'buddypress' ), bp_get_blog_last_active() );
    6363    }
     64
     65    /**
     66     * @group bp_get_blog_latest_post
     67     */
     68    public function test_bp_get_blog_latest_post_default_params() {
     69        // Fake the global
     70        global $blogs_template;
     71
     72        $blogs_template = new stdClass;
     73        $blogs_template->blog = new stdClass;
     74        $blogs_template->blog->latest_post = new stdClass;
     75        $blogs_template->blog->latest_post->guid = 'foo';
     76        $blogs_template->blog->latest_post->post_title = 'bar';
     77
     78        $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post() );
     79
     80        $blogs_template->blog = null;
     81    }
     82
     83    /**
     84     * @group bp_get_blog_latest_post
     85     */
     86    public function test_bp_get_blog_latest_post_latest_format_true() {
     87        // Fake the global
     88        global $blogs_template;
     89
     90        $blogs_template = new stdClass;
     91        $blogs_template->blog = new stdClass;
     92        $blogs_template->blog->latest_post = new stdClass;
     93        $blogs_template->blog->latest_post->guid = 'foo';
     94        $blogs_template->blog->latest_post->post_title = 'bar';
     95
     96        $this->assertSame( sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="foo">bar</a>' ), bp_get_blog_latest_post( array( 'latest_format' => true, ) ) );
     97
     98        $blogs_template->blog = null;
     99    }
     100
     101    /**
     102     * @group bp_get_blog_latest_post
     103     */
     104    public function test_bp_get_blog_latest_post_latest_format_false() {
     105        // Fake the global
     106        global $blogs_template;
     107
     108        $blogs_template = new stdClass;
     109        $blogs_template->blog = new stdClass;
     110        $blogs_template->blog->latest_post = new stdClass;
     111        $blogs_template->blog->latest_post->guid = 'foo';
     112        $blogs_template->blog->latest_post->post_title = 'bar';
     113
     114        $this->assertSame( '<a href="foo">bar</a>', bp_get_blog_latest_post( array( 'latest_format' => false, ) ) );
     115
     116        $blogs_template->blog = null;
     117    }
    64118}
Note: See TracChangeset for help on using the changeset viewer.