Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/26/2021 12:53:27 AM (4 years ago)
Author:
espellcaste
Message:

Making PHPDoc Improvements to the BP Messages (component) files.

Also, adding several minor PHP changes.

See #8553

File:
1 edited

Legend:

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

    r12990 r13096  
    9494 * Check whether there are more threads to iterate over.
    9595 *
     96 * @global BP_Messages_Box_Template $messages_template
     97 *
    9698 * @return bool
    9799 */
     
    104106 * Set up the current thread inside the loop.
    105107 *
    106  * @return object
     108 * @global BP_Messages_Box_Template $messages_template
     109 *
     110 * @return BP_Messages_Thread
    107111 */
    108112function bp_message_thread() {
     
    120124     * Get the ID of the current thread in the loop.
    121125     *
     126     * @global BP_Messages_Box_Template $messages_template
     127     *
    122128     * @return int
    123129     */
     
    132138         * @param int $thread_id ID of the current thread in the loop.
    133139         */
    134         return apply_filters( 'bp_get_message_thread_id', $messages_template->thread->thread_id );
     140        return apply_filters( 'bp_get_message_thread_id', (int) $messages_template->thread->thread_id );
    135141    }
    136142
     
    144150     * Get the subject of the current thread in the loop.
    145151     *
     152     * @global BP_Messages_Box_Template $messages_template
     153     *
    146154     * @return string
    147155     */
     
    168176     * Generate an excerpt from the current message in the loop.
    169177     *
     178     * @global BP_Messages_Box_Template $messages_template
     179     *
    170180     * @return string
    171181     */
     
    208218     * @since 2.0.0
    209219     *
     220     * @global BP_Messages_Box_Template $messages_template
     221     *
    210222     * @return string The raw content of the last message in the thread.
    211223     */
     
    232244     * Get a link to the page of the current thread's last author.
    233245     *
     246     * @global BP_Messages_Box_Template $messages_template
     247     *
    234248     * @return string
    235249     */
     
    256270     * Generate HTML links to the pages of the current thread's recipients.
    257271     *
     272     * @global BP_Messages_Box_Template $messages_template
     273     *
    258274     * @return string
    259275     */
     
    268284         * @param string $value HTML links to the pages of the current thread's recipients.
    269285         */
    270         return apply_filters( 'bp_message_thread_to', BP_Messages_Thread::get_recipient_links($messages_template->thread->recipients ) );
     286        return apply_filters( 'bp_message_thread_to', BP_Messages_Thread::get_recipient_links( $messages_template->thread->recipients ) );
    271287    }
    272288
     
    288304     *
    289305     * @since 2.9.0 Introduced `$user_id` parameter.
     306     *
     307     * @global BP_Messages_Box_Template $messages_template
    290308     *
    291309     * @param int $thread_id Optional. ID of the thread. Default: current
     
    304322        }
    305323
    306         if ( null === $user_id ) {
     324        if ( empty( $user_id ) ) {
    307325            $user_id = bp_loggedin_user_id();
    308326        }
     
    329347 * @since 2.9.0 Introduced `$user_id` parameter.
    330348 *
    331  * @param int $user_id Optional. ID of the user relative to whom the link
    332  *                     should be generated. Default: ID of logged-in user.
     349 * @param int|null $user_id Optional. ID of the user relative to whom the link
     350 *                          should be generated. Default: ID of logged-in user.
    333351 */
    334352function bp_message_thread_delete_link( $user_id = null ) {
     
    340358     * @since 2.9.0 Introduced `$user_id` parameter.
    341359     *
    342      * @param int $user_id Optional. ID of the user relative to whom the link
    343      *                     should be generated. Default: ID of logged-in user.
     360     * @global BP_Messages_Box_Template $messages_template
     361     *
     362     * @param int|null $user_id Optional. ID of the user relative to whom the link
     363     *                          should be generated. Default: ID of logged-in user.
    344364     * @return string
    345365     */
     
    347367        global $messages_template;
    348368
    349         if ( null === $user_id ) {
     369        if ( empty( $user_id ) ) {
    350370            $user_id = bp_loggedin_user_id();
    351371        }
     
    372392 * @since 2.9.0 Introduced `$user_id` parameter.
    373393 *
    374  * @param int $user_id Optional. ID of the user relative to whom the link
    375  *                     should be generated. Default: ID of logged-in user.
     394 * @param int|null $user_id Optional. ID of the user relative to whom the link
     395 *                          should be generated. Default: ID of logged-in user.
    376396 */
    377397function bp_the_message_thread_mark_unread_url( $user_id = null ) {
     
    384404     * @since 2.9.0 Introduced `$user_id` parameter.
    385405     *
    386      * @param int $user_id Optional. ID of the user relative to whom the link
    387      *                     should be generated. Default: ID of logged-in user.
     406     * @param int|null $user_id Optional. ID of the user relative to whom the link
     407     *                          should be generated. Default: ID of logged-in user.
    388408     * @return string
    389409     */
     
    396416        $args = array(
    397417            'action'     => 'unread',
    398             'message_id' => $id
     418            'message_id' => $id,
    399419        );
    400420
    401         if ( null === $user_id ) {
     421        if ( empty( $user_id ) ) {
    402422            $user_id = bp_loggedin_user_id();
    403423        }
     
    434454 * @since 2.9.0 Introduced `$user_id` parameter.
    435455 *
    436  * @param int $user_id Optional. ID of the user relative to whom the link
    437  *                     should be generated. Default: ID of logged-in user.
     456 * @param int|null $user_id Optional. ID of the user relative to whom the link
     457 *                          should be generated. Default: ID of logged-in user.
    438458 */
    439459function bp_the_message_thread_mark_read_url( $user_id = null ) {
     
    446466     * @since 2.9.0 Introduced `$user_id` parameter.
    447467     *
    448      * @param int $user_id Optional. ID of the user relative to whom the link
    449      *                     should be generated. Default: ID of logged-in user.
     468     * @param int|null $user_id Optional. ID of the user relative to whom the link
     469     *                          should be generated. Default: ID of logged-in user.
    450470     * @return string
    451471     */
     
    458478        $args = array(
    459479            'action'     => 'read',
    460             'message_id' => $id
     480            'message_id' => $id,
    461481        );
    462482
    463         if ( null === $user_id ) {
     483        if ( empty( $user_id ) ) {
    464484            $user_id = bp_loggedin_user_id();
    465485        }
     
    484504         * @param int    $user_id ID of the user relative to whom the link should be generated.
    485505         */
    486         return apply_filters( 'bp_get_the_message_thread_mark_read_url', $url );
     506        return apply_filters( 'bp_get_the_message_thread_mark_read_url', $url, $user_id );
    487507    }
    488508
     
    496516     * Generate the CSS class for the current thread.
    497517     *
     518     * @global BP_Messages_Box_Template $messages_template
     519     *
    498520     * @return string
    499521     */
     
    503525        $class = false;
    504526
    505         if ( $messages_template->current_thread % 2 == 1 ) {
     527        if ( $messages_template->current_thread % 2 === 1 ) {
    506528            $class .= 'alt';
    507529        }
     
    520542 * Check whether the current thread has unread items.
    521543 *
     544 * @global BP_Messages_Box_Template $messages_template
     545 *
    522546 * @return bool True if there are unread items, otherwise false.
    523547 */
     
    525549    global $messages_template;
    526550
    527     $retval = ! empty( $messages_template->thread->unread_count )
    528         ? true
    529         : false;
     551    $retval = ! empty( $messages_template->thread->unread_count );
    530552
    531553    /**
     
    547569    /**
    548570     * Get the current thread's unread count.
     571     *
     572     * @global BP_Messages_Box_Template $messages_template
    549573     *
    550574     * @return int
     
    564588         * @param int $count Current thread unread count.
    565589         */
    566         return apply_filters( 'bp_get_message_thread_unread_count', $count );
     590        return apply_filters( 'bp_get_message_thread_unread_count', (int) $count );
    567591    }
    568592
     
    654678     * Get the unformatted date of the last post in the current thread.
    655679     *
     680     * @global BP_Messages_Box_Template $messages_template
     681     *
    656682     * @return string
    657683     */
     
    707733     * @see bp_core_fetch_avatar() For a description of arguments and
    708734     *      return values.
     735     *
     736     * @global BP_Messages_Box_Template $messages_template
    709737     *
    710738     * @param array|string $args {
     
    759787 * Output the unread messages count for the current inbox.
    760788 *
    761  * @since 2.6.x Added $user_id argument.
     789 * @since 2.6.x Added the `$user_id` paremeter.
    762790 *
    763791 * @param int $user_id The user ID.
    764  *
    765  * @return int $unread_count Total inbox unread count for user.
    766792 */
    767793function bp_total_unread_messages_count( $user_id = 0 ) {
     
    771797     * Get the unread messages count for the current inbox.
    772798     *
    773      * @since 2.6.x Added $user_id argument.
     799     * @since 2.6.x Added the `$user_id` paremeter.
    774800     *
    775801     * @param int $user_id The user ID.
     
    784810         * @since 1.0.0
    785811         *
    786          * @param int $value Unread messages count for the current inbox.
    787          */
    788         return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count( $user_id ) );
     812         * @param int $value   Unread messages count for the current inbox.
     813         * @param int $user_id ID of the user the messages are from.
     814         */
     815        return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count( $user_id ), $user_id );
    789816    }
    790817
     
    798825     * Get the pagination HTML for the current thread loop.
    799826     *
     827     * @global BP_Messages_Box_Template $messages_template
     828     *
    800829     * @return string
    801830     */
     
    815844/**
    816845 * Generate the "Viewing message x to y (of z messages)" string for a loop.
     846 *
     847 * @global BP_Messages_Box_Template $messages_template
    817848 */
    818849function bp_messages_pagination_count() {
     
    10581089 * @since 1.6.0
    10591090 *
     1091 * @global BP_Messages_Box_Template $messages_template
     1092 *
    10601093 * @return bool
    10611094 */
     
    10841117 * @since 1.0.0
    10851118 * @deprecated 1.6.0
    1086  * @return bool
    10871119 */
    10881120function bp_message_is_active_notice() {
     
    11121144 */
    11131145function bp_message_notice_id() {
    1114     echo (int) bp_get_message_notice_id();
     1146    echo bp_get_message_notice_id();
    11151147}
    11161148    /**
    11171149     * Get the ID of the current notice in the loop.
     1150     *
     1151     * @global BP_Messages_Box_Template $messages_template
    11181152     *
    11191153     * @return int
     
    11291163         * @param int $id ID of the current notice in the loop.
    11301164         */
    1131         return apply_filters( 'bp_get_message_notice_id', $messages_template->thread->id );
     1165        return apply_filters( 'bp_get_message_notice_id', (int) $messages_template->thread->id );
    11321166    }
    11331167
     
    11411175     * Get the post date of the current notice in the loop.
    11421176     *
     1177     * @global BP_Messages_Box_Template $messages_template
     1178     *
    11431179     * @return string
    11441180     */
     
    11711207     * @since 5.0.0 The $notice parameter has been added.
    11721208     *
    1173      * @param BP_Messages_Notice $notice The notice object.
     1209     * @global BP_Messages_Box_Template $messages_template
     1210     *
     1211     * @param BP_Messages_Notice|null $notice The notice object.
    11741212     * @return string
    11751213     */
     
    12061244     * @since 5.0.0 The $notice parameter has been added.
    12071245     *
    1208      * @param BP_Messages_Notice $notice The notice object.
     1246     * @global BP_Messages_Box_Template $messages_template
     1247     *
     1248     * @param BP_Messages_Notice|null $notice The notice object.
    12091249     * @return string
    12101250     */
     
    12351275     * Get the URL for deleting the current notice.
    12361276     *
     1277     * @global BP_Messages_Box_Template $messages_template
     1278     *
    12371279     * @return string Delete URL.
    12381280     */
     
    12591301    /**
    12601302     * Get the URL for deactivating the current notice.
     1303     *
     1304     * @global BP_Messages_Box_Template $messages_template
    12611305     *
    12621306     * @return string
     
    12901334     * Generate the text ('Deactivate' or 'Activate') for the notice action link.
    12911335     *
     1336     * @global BP_Messages_Box_Template $messages_template
     1337     *
    12921338     * @return string
    12931339     */
     
    13151361 *
    13161362 * @since 9.0.0
    1317  * @return string URL for dismissing the current notice for the current user.
    13181363 */
    13191364function bp_message_notice_dismiss_link() {
     
    13851430
    13861431    if ( is_array( $closed_notices ) ) {
    1387         if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
     1432        if ( ! in_array( $notice->id, $closed_notices, true ) && $notice->id ) {
    13881433            ?>
    13891434            <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>">
     
    15771622 * Initialize the messages template loop for a specific thread.
    15781623 *
     1624 * @global BP_Messages_Thread_Template $thread_template
     1625 *
    15791626 * @param array|string $args {
    15801627 *     Array of arguments. All are optional.
     
    16191666     * Get the 'ASC' or 'DESC' messages order string for this loop.
    16201667     *
     1668     * @global BP_Messages_Thread_Template $thread_template
     1669     *
    16211670     * @return string
    16221671     */
    16231672    function bp_get_thread_messages_order() {
    16241673        global $thread_template;
     1674
    16251675        return $thread_template->thread->messages_order;
    16261676    }
     
    16281678/**
    16291679 * Check whether there are more messages to iterate over.
     1680 *
     1681 * @global BP_Messages_Thread_Template $thread_template
    16301682 *
    16311683 * @return bool
     
    16401692 * Set up the current thread inside the loop.
    16411693 *
    1642  * @return object
     1694 * @global BP_Messages_Thread_Template $thread_template
     1695 *
     1696 * @return BP_Messages_Message
    16431697 */
    16441698function bp_thread_the_message() {
     
    16571711     * Get the ID of the thread that the current loop belongs to.
    16581712     *
     1713     * @global BP_Messages_Thread_Template $thread_template
     1714     *
    16591715     * @return int
    16601716     */
     
    16801736    /**
    16811737     * Get the subject of the thread currently being iterated over.
     1738     *
     1739     * @global BP_Messages_Thread_Template $thread_template
    16821740     *
    16831741     * @return string
     
    17131771    }
    17141772
     1773    /**
     1774     * Filters the thread recipients.
     1775     *
     1776     * @since 10.0.0
     1777     *
     1778     * @param string $recipients List of thread recipients.
     1779     */
    17151780    return apply_filters( 'bp_get_the_thread_recipients', $recipients );
    17161781}
     
    17201785 *
    17211786 * @since 2.2.0
     1787 *
     1788 * @global BP_Messages_Thread_Template $thread_template
    17221789 *
    17231790 * @return int
     
    17251792function bp_get_thread_recipients_count() {
    17261793    global $thread_template;
     1794
    17271795    /**
    17281796     * Filters the total number of recipients in a thread.
     
    17651833     *
    17661834     * @since 2.2.0
     1835     *
     1836     * @global BP_Messages_Thread_Template $thread_template
    17671837     *
    17681838     * @return string
     
    18061876 */
    18071877function bp_the_thread_message_id() {
    1808     echo (int) bp_get_the_thread_message_id();
     1878    echo bp_get_the_thread_message_id();
    18091879}
    18101880    /**
     
    18121882     *
    18131883     * @since 1.9.0
     1884     *
     1885     * @global BP_Messages_Thread_Template $thread_template
    18141886     *
    18151887     * @return int
     
    18201892        $thread_message_id = isset( $thread_template->message->id )
    18211893            ? (int) $thread_template->message->id
    1822             : null;
     1894            : 0;
    18231895
    18241896        /**
     
    18291901         * @param int $thread_message_id ID of the current message in the thread.
    18301902         */
    1831         return apply_filters( 'bp_get_the_thread_message_id', $thread_message_id );
     1903        return (int) apply_filters( 'bp_get_the_thread_message_id', (int) $thread_message_id );
    18321904    }
    18331905
     
    18451917     * @since 2.1.0
    18461918     *
     1919     * @global BP_Messages_Thread_Template $thread_template
     1920     *
    18471921     * @return string
    18481922     */
     
    18591933
    18601934        // Whether the sender is the same as the logged-in user.
    1861         if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) {
     1935        if ( bp_loggedin_user_id() === $thread_template->message->sender_id ) {
    18621936            $classes[] = 'sent-by-me';
    18631937        }
     
    18841958     * Get the CSS class used for message zebra striping.
    18851959     *
     1960     * @global BP_Messages_Thread_Template $thread_template
     1961     *
    18861962     * @return string
    18871963     */
     
    18891965        global $thread_template;
    18901966
    1891         if ( $thread_template->current_message % 2 == 1 ) {
     1967        $class = 'odd';
     1968        if ( 1 === $thread_template->current_message % 2 ) {
    18921969            $class = 'even alt';
    1893         } else {
    1894             $class = 'odd';
    18951970        }
    18961971
     
    19111986 */
    19121987function bp_the_thread_message_sender_id() {
    1913     echo (int) bp_get_the_thread_message_sender_id();
     1988    echo bp_get_the_thread_message_sender_id();
    19141989}
    19151990    /**
     
    19171992     *
    19181993     * @since 2.1.0
     1994     *
     1995     * @global BP_Messages_Thread_Template $thread_template
    19191996     *
    19201997     * @return int
     
    19482025    /**
    19492026     * Get the avatar for the current message sender.
     2027     *
     2028     * @global BP_Messages_Thread_Template $thread_template
    19502029     *
    19512030     * @param array|string $args {
     
    19982077     * @since 1.1.0
    19992078     *
     2079     * @global BP_Messages_Thread_Template $thread_template
     2080     *
    20002081     * @return string
    20012082     */
     
    20252106     *
    20262107     * @since 1.1.0
     2108     *
     2109     * @global BP_Messages_Thread_Template $thread_template
    20272110     *
    20282111     * @return string
     
    21222205     * @since 2.1.0
    21232206     *
     2207     * @global BP_Messages_Thread_Template $thread_template
    21242208     *
    21252209     * @return int
     
    21502234     *
    21512235     * @since 1.1.0
     2236     *
     2237     * @global BP_Messages_Thread_Template $thread_template
    21522238     *
    21532239     * @return string
     
    21832269 */
    21842270function bp_messages_embed() {
    2185     add_filter( 'embed_post_id',         'bp_get_the_thread_message_id' );
    2186     add_filter( 'bp_embed_get_cache',    'bp_embed_message_cache',      10, 3 );
     2271    add_filter( 'embed_post_id', 'bp_get_the_thread_message_id' );
     2272    add_filter( 'bp_embed_get_cache', 'bp_embed_message_cache', 10, 3 );
    21872273    add_action( 'bp_embed_update_cache', 'bp_embed_message_save_cache', 10, 3 );
    21882274}
Note: See TracChangeset for help on using the changeset viewer.