Skip to:
Content

bbPress.org


Ignore:
Timestamp:
01/17/2011 06:57:34 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Normalize bbp-includes directory. Mostly documentation fixes. Introduce bbp-shortcodes placeholder.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-user-template.php

    r2803 r2812  
    22
    33/**
    4  * bbPress User Functions
     4 * bbPress User Template Tags
    55 *
    66 * @package bbPress
     
    88 */
    99
    10 /** START User Functions ******************************************************/
     10/** Users *********************************************************************/
    1111
    1212/**
     
    5757    }
    5858
    59 /** START Favorites Functions *************************************************/
     59
     60/**
     61 * Output ID of current user
     62 *
     63 * @since bbPress (r2574)
     64 *
     65 * @uses bbp_get_current_user_id() To get the current user id
     66 */
     67function bbp_current_user_id() {
     68    echo bbp_get_current_user_id();
     69}
     70    /**
     71     * Return ID of current user
     72     *
     73     * @since bbPress (r2574)
     74     *
     75     * @uses bbp_get_user_id() To get the current user id
     76     * @uses apply_filters() Calls 'bbp_get_current_user_id' with the id
     77     * @return int Current user id
     78     */
     79    function bbp_get_current_user_id() {
     80        return apply_filters( 'bbp_get_current_user_id', bbp_get_user_id( 0, false, true ) );
     81    }
     82
     83/**
     84 * Output ID of displayed user
     85 *
     86 * @since bbPress (r2688)
     87 *
     88 * @uses bbp_get_displayed_user_id() To get the displayed user id
     89 */
     90function bbp_displayed_user_id() {
     91    echo bbp_get_displayed_user_id();
     92}
     93    /**
     94     * Return ID of displayed user
     95     *
     96     * @since bbPress (r2688)
     97     *
     98     * @uses bbp_get_user_id() To get the displayed user id
     99     * @uses apply_filters() Calls 'bbp_get_displayed_user_id' with the id
     100     * @return int Displayed user id
     101     */
     102    function bbp_get_displayed_user_id() {
     103        return apply_filters( 'bbp_get_displayed_user_id', bbp_get_user_id( 0, true, false ) );
     104    }
     105
     106/**
     107 * Return a sanitized user field value
     108 *
     109 * @since bbPress (r2688)
     110 *
     111 * @param string $field Field to get
     112 * @uses sanitize_text_field() To sanitize the field
     113 * @uses esc_attr() To sanitize the field
     114 * @return string|bool Value of the field if it exists, else false
     115 */
     116function bbp_get_displayed_user_field( $field = '' ) {
     117    global $bbp;
     118
     119    // Return field if exists
     120    if ( isset( $bbp->displayed_user->$field ) )
     121        return esc_attr( sanitize_text_field( $bbp->displayed_user->$field ) );
     122
     123    // Return empty
     124    return false;
     125}
     126
     127/**
     128 * Output name of current user
     129 *
     130 * @since bbPress (r2574)
     131 *
     132 * @uses bbp_get_current_user_name() To get the current user name
     133 */
     134function bbp_current_user_name() {
     135    echo bbp_get_current_user_name();
     136}
     137    /**
     138     * Return name of current user
     139     *
     140     * @since bbPress (r2574)
     141     *
     142     * @uses apply_filters() Calls 'bbp_get_current_user_name' with the
     143     *                        current user name
     144     * @return string
     145     */
     146    function bbp_get_current_user_name() {
     147        global $user_identity;
     148
     149        if ( is_user_logged_in() )
     150            $current_user_name = $user_identity;
     151        else
     152            $current_user_name = __( 'Anonymous', 'bbpress' );
     153
     154        return apply_filters( 'bbp_get_current_user_name', $current_user_name );
     155    }
     156
     157/**
     158 * Output avatar of current user
     159 *
     160 * @since bbPress (r2574)
     161 *
     162 * @param int $size Size of the avatar. Defaults to 40
     163 * @uses bbp_get_current_user_avatar() To get the current user avatar
     164 */
     165function bbp_current_user_avatar( $size = 40 ) {
     166    echo bbp_get_current_user_avatar( $size );
     167}
     168
     169    /**
     170     * Return avatar of current user
     171     *
     172     * @since bbPress (r2574)
     173     *
     174     * @param int $size Size of the avatar. Defaults to 40
     175     * @uses bbp_get_current_user_id() To get the current user id
     176     * @uses bbp_get_current_anonymous_user_data() To get the current
     177     *                                              anonymous user's email
     178     * @uses get_avatar() To get the avatar
     179     * @uses apply_filters() Calls 'bbp_get_current_user_avatar' with the
     180     *                        avatar and size
     181     * @return string Current user avatar
     182     */
     183    function bbp_get_current_user_avatar( $size = 40 ) {
     184
     185        if ( !$user = bbp_get_current_user_id() )
     186            $user = bbp_get_current_anonymous_user_data( 'email' );
     187
     188        return apply_filters( 'bbp_get_current_user_avatar', get_avatar( $user, $size ), $size );
     189    }
     190
     191/**
     192 * Output link to the profile page of a user
     193 *
     194 * @since bbPress (r2688)
     195 *
     196 * @param int $user_id Optional. User id
     197 * @uses bbp_get_user_profile_link() To get user profile link
     198 */
     199function bbp_user_profile_link( $user_id = 0 ) {
     200    echo bbp_get_user_profile_link( $user_id );
     201}
     202    /**
     203     * Return link to the profile page of a user
     204     *
     205     * @since bbPress (r2688)
     206     *
     207     * @param int $user_id Optional. User id
     208     * @uses bbp_get_user_id() To get user id
     209     * @uses get_userdata() To get user data
     210     * @uses bbp_get_user_profile_url() To get user profile url
     211     * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the user
     212     *                        profile link and user id
     213     * @return string User profile link
     214     */
     215    function bbp_get_user_profile_link( $user_id = 0 ) {
     216        if ( !$user_id = bbp_get_user_id( $user_id ) )
     217            return false;
     218
     219        $user      = get_userdata( $user_id );
     220        $name      = esc_attr( $user->display_name );
     221        $user_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . $name . '">' . $name . '</a>';
     222
     223        return apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id );
     224    }
     225
     226/**
     227 * Output URL to the profile page of a user
     228 *
     229 * @since bbPress (r2688)
     230 *
     231 * @param int $user_id Optional. User id
     232 * @param string $user_nicename Optional. User nicename
     233 * @uses bbp_get_user_profile_url() To get user profile url
     234 */
     235function bbp_user_profile_url( $user_id = 0, $user_nicename = '' ) {
     236    echo bbp_get_user_profile_url( $user_id );
     237}
     238    /**
     239     * Return URL to the profile page of a user
     240     *
     241     * @since bbPress (r2688)
     242     *
     243     * @param int $user_id Optional. User id
     244     * @param string $user_nicename Optional. User nicename
     245     * @uses bbp_get_user_id() To get user id
     246     * @uses add_query_arg() To add custom args to the url
     247     * @uses home_url() To get blog home url
     248     * @uses apply_filters() Calls 'bbp_get_user_profile_url' with the user
     249     *                        profile url, user id and user nicename
     250     * @return string User profile url
     251     */
     252    function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) {
     253        global $wp_rewrite, $bbp;
     254
     255        // Use displayed user ID if there is one, and one isn't requested
     256        if ( !$user_id = bbp_get_user_id( $user_id ) )
     257            return false;
     258
     259        // No pretty permalinks
     260        if ( empty( $wp_rewrite->permalink_structure ) ) {
     261            $url = add_query_arg( array( 'bbp_user' => $user_id ), home_url( '/' ) );
     262
     263        // Get URL safe user slug
     264        } else {
     265            $url = $wp_rewrite->front . $bbp->user_slug . '/%bbp_user%';
     266
     267            if ( empty( $user_nicename ) ) {
     268                $user = get_userdata( $user_id );
     269                if ( !empty( $user->user_nicename ) )
     270                    $user_nicename = $user->user_nicename;
     271            }
     272
     273            $url = str_replace( '%bbp_user%', $user_nicename, $url );
     274            $url = home_url( user_trailingslashit( $url ) );
     275        }
     276
     277        return apply_filters( 'bbp_get_user_profile_url', $url, $user_id, $user_nicename );
     278
     279    }
     280
     281/**
     282 * Output link to the profile edit page of a user
     283 *
     284 * @since bbPress (r2688)
     285 *
     286 * @param int $user_id Optional. User id
     287 * @uses bbp_get_user_profile_edit_link() To get user profile edit link
     288 */
     289function bbp_user_profile_edit_link( $user_id = 0 ) {
     290    echo bbp_get_user_profile_edit_link( $user_id );
     291}
     292    /**
     293     * Return link to the profile edit page of a user
     294     *
     295     * @since bbPress (r2688)
     296     *
     297     * @param int $user_id Optional. User id
     298     * @uses bbp_get_user_id() To get user id
     299     * @uses get_userdata() To get user data
     300     * @uses bbp_get_user_profile_edit_url() To get user profile edit url
     301     * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the edit
     302     *                        link and user id
     303     * @return string User profile edit link
     304     */
     305    function bbp_get_user_profile_edit_link( $user_id = 0 ) {
     306        if ( !$user_id = bbp_get_user_id( $user_id ) )
     307            return false;
     308
     309        $user      = get_userdata( $user_id );
     310        $name      = $user->display_name;
     311        $edit_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . esc_attr( $name ) . '">' . $name . '</a>';
     312        return apply_filters( 'bbp_get_user_profile_link', $edit_link, $user_id );
     313    }
     314
     315/**
     316 * Output URL to the profile edit page of a user
     317 *
     318 * @since bbPress (r2688)
     319 *
     320 * @param int $user_id Optional. User id
     321 * @param string $user_nicename Optional. User nicename
     322 * @uses bbp_get_user_profile_edit_url() To get user profile edit url
     323 */
     324function bbp_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
     325    echo bbp_get_user_profile_edit_url( $user_id );
     326}
     327    /**
     328     * Return URL to the profile edit page of a user
     329     *
     330     * @since bbPress (r2688)
     331     *
     332     * @param int $user_id Optional. User id
     333     * @param string $user_nicename Optional. User nicename
     334     * @uses bbp_get_user_id() To get user id
     335     * @uses add_query_arg() To add custom args to the url
     336     * @uses home_url() To get blog home url
     337     * @uses apply_filters() Calls 'bbp_get_user_edit_profile_url' with the
     338     *                        edit profile url, user id and user nicename
     339     * @return string
     340     */
     341    function bbp_get_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
     342        global $wp_rewrite, $bbp;
     343
     344        if ( !$user_id = bbp_get_user_id( $user_id ) )
     345            return;
     346
     347        if ( empty( $wp_rewrite->permalink_structure ) ) {
     348            $url = add_query_arg( array( 'bbp_user' => $user_id, 'edit' => '1' ), home_url( '/' ) );
     349        } else {
     350            $url = $wp_rewrite->front . $bbp->user_slug . '/%bbp_user%/edit';
     351
     352            if ( empty( $user_nicename ) ) {
     353                $user = get_userdata( $user_id );
     354                if ( !empty( $user->user_nicename ) )
     355                    $user_nicename = $user->user_nicename;
     356            }
     357
     358            $url = str_replace( '%bbp_user%', $user_nicename, $url );
     359            $url = home_url( user_trailingslashit( $url ) );
     360        }
     361
     362        return apply_filters( 'bbp_get_user_edit_profile_url', $url, $user_id, $user_nicename );
     363
     364    }
     365
     366/** Favorites *****************************************************************/
    60367
    61368/**
     
    173480    }
    174481
    175 /** END Favorites Functions ***************************************************/
    176 
    177 /** START Subscriptions Functions *********************************************/
     482/** Subscriptions *************************************************************/
    178483
    179484/**
     
    287592    }
    288593
    289 /** END Subscriptions Functions ***********************************************/
    290 
    291 /**
    292  * Output ID of current user
    293  *
    294  * @since bbPress (r2574)
    295  *
    296  * @uses bbp_get_current_user_id() To get the current user id
    297  */
    298 function bbp_current_user_id() {
    299     echo bbp_get_current_user_id();
    300 }
    301     /**
    302      * Return ID of current user
    303      *
    304      * @since bbPress (r2574)
    305      *
    306      * @uses bbp_get_user_id() To get the current user id
    307      * @uses apply_filters() Calls 'bbp_get_current_user_id' with the id
    308      * @return int Current user id
    309      */
    310     function bbp_get_current_user_id() {
    311         return apply_filters( 'bbp_get_current_user_id', bbp_get_user_id( 0, false, true ) );
    312     }
    313 
    314 /**
    315  * Output ID of displayed user
    316  *
    317  * @since bbPress (r2688)
    318  *
    319  * @uses bbp_get_displayed_user_id() To get the displayed user id
    320  */
    321 function bbp_displayed_user_id() {
    322     echo bbp_get_displayed_user_id();
    323 }
    324     /**
    325      * Return ID of displayed user
    326      *
    327      * @since bbPress (r2688)
    328      *
    329      * @uses bbp_get_user_id() To get the displayed user id
    330      * @uses apply_filters() Calls 'bbp_get_displayed_user_id' with the id
    331      * @return int Displayed user id
    332      */
    333     function bbp_get_displayed_user_id() {
    334         return apply_filters( 'bbp_get_displayed_user_id', bbp_get_user_id( 0, true, false ) );
    335     }
    336 
    337 /**
    338  * Return a sanitized user field value
    339  *
    340  * @since bbPress (r2688)
    341  *
    342  * @param string $field Field to get
    343  * @uses sanitize_text_field() To sanitize the field
    344  * @uses esc_attr() To sanitize the field
    345  * @return string|bool Value of the field if it exists, else false
    346  */
    347 function bbp_get_displayed_user_field( $field = '' ) {
    348     global $bbp;
    349 
    350     // Return field if exists
    351     if ( isset( $bbp->displayed_user->$field ) )
    352         return esc_attr( sanitize_text_field( $bbp->displayed_user->$field ) );
    353 
    354     // Return empty
    355     return false;
    356 }
    357 
    358 /**
    359  * Output name of current user
    360  *
    361  * @since bbPress (r2574)
    362  *
    363  * @uses bbp_get_current_user_name() To get the current user name
    364  */
    365 function bbp_current_user_name() {
    366     echo bbp_get_current_user_name();
    367 }
    368     /**
    369      * Return name of current user
    370      *
    371      * @since bbPress (r2574)
    372      *
    373      * @uses apply_filters() Calls 'bbp_get_current_user_name' with the
    374      *                        current user name
    375      * @return string
    376      */
    377     function bbp_get_current_user_name() {
    378         global $user_identity;
    379 
    380         if ( is_user_logged_in() )
    381             $current_user_name = $user_identity;
    382         else
    383             $current_user_name = __( 'Anonymous', 'bbpress' );
    384 
    385         return apply_filters( 'bbp_get_current_user_name', $current_user_name );
    386     }
    387 
    388 /**
    389  * Output avatar of current user
    390  *
    391  * @since bbPress (r2574)
    392  *
    393  * @param int $size Size of the avatar. Defaults to 40
    394  * @uses bbp_get_current_user_avatar() To get the current user avatar
    395  */
    396 function bbp_current_user_avatar( $size = 40 ) {
    397     echo bbp_get_current_user_avatar( $size );
    398 }
    399 
    400     /**
    401      * Return avatar of current user
    402      *
    403      * @since bbPress (r2574)
    404      *
    405      * @param int $size Size of the avatar. Defaults to 40
    406      * @uses bbp_get_current_user_id() To get the current user id
    407      * @uses bbp_get_current_anonymous_user_data() To get the current
    408      *                                              anonymous user's email
    409      * @uses get_avatar() To get the avatar
    410      * @uses apply_filters() Calls 'bbp_get_current_user_avatar' with the
    411      *                        avatar and size
    412      * @return string Current user avatar
    413      */
    414     function bbp_get_current_user_avatar( $size = 40 ) {
    415 
    416         if ( !$user = bbp_get_current_user_id() )
    417             $user = bbp_get_current_anonymous_user_data( 'email' );
    418 
    419         return apply_filters( 'bbp_get_current_user_avatar', get_avatar( $user, $size ), $size );
    420     }
    421 
    422 /**
    423  * Output link to the profile page of a user
    424  *
    425  * @since bbPress (r2688)
    426  *
    427  * @param int $user_id Optional. User id
    428  * @uses bbp_get_user_profile_link() To get user profile link
    429  */
    430 function bbp_user_profile_link( $user_id = 0 ) {
    431     echo bbp_get_user_profile_link( $user_id );
    432 }
    433     /**
    434      * Return link to the profile page of a user
    435      *
    436      * @since bbPress (r2688)
    437      *
    438      * @param int $user_id Optional. User id
    439      * @uses bbp_get_user_id() To get user id
    440      * @uses get_userdata() To get user data
    441      * @uses bbp_get_user_profile_url() To get user profile url
    442      * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the user
    443      *                        profile link and user id
    444      * @return string User profile link
    445      */
    446     function bbp_get_user_profile_link( $user_id = 0 ) {
    447         if ( !$user_id = bbp_get_user_id( $user_id ) )
    448             return false;
    449 
    450         $user      = get_userdata( $user_id );
    451         $name      = esc_attr( $user->display_name );
    452         $user_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . $name . '">' . $name . '</a>';
    453 
    454         return apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id );
    455     }
    456 
    457 /**
    458  * Output URL to the profile page of a user
    459  *
    460  * @since bbPress (r2688)
    461  *
    462  * @param int $user_id Optional. User id
    463  * @param string $user_nicename Optional. User nicename
    464  * @uses bbp_get_user_profile_url() To get user profile url
    465  */
    466 function bbp_user_profile_url( $user_id = 0, $user_nicename = '' ) {
    467     echo bbp_get_user_profile_url( $user_id );
    468 }
    469     /**
    470      * Return URL to the profile page of a user
    471      *
    472      * @since bbPress (r2688)
    473      *
    474      * @param int $user_id Optional. User id
    475      * @param string $user_nicename Optional. User nicename
    476      * @uses bbp_get_user_id() To get user id
    477      * @uses add_query_arg() To add custom args to the url
    478      * @uses home_url() To get blog home url
    479      * @uses apply_filters() Calls 'bbp_get_user_profile_url' with the user
    480      *                        profile url, user id and user nicename
    481      * @return string User profile url
    482      */
    483     function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) {
    484         global $wp_rewrite, $bbp;
    485 
    486         // Use displayed user ID if there is one, and one isn't requested
    487         if ( !$user_id = bbp_get_user_id( $user_id ) )
    488             return false;
    489 
    490         // No pretty permalinks
    491         if ( empty( $wp_rewrite->permalink_structure ) ) {
    492             $url = add_query_arg( array( 'bbp_user' => $user_id ), home_url( '/' ) );
    493 
    494         // Get URL safe user slug
    495         } else {
    496             $url = $wp_rewrite->front . $bbp->user_slug . '/%bbp_user%';
    497 
    498             if ( empty( $user_nicename ) ) {
    499                 $user = get_userdata( $user_id );
    500                 if ( !empty( $user->user_nicename ) )
    501                     $user_nicename = $user->user_nicename;
    502             }
    503 
    504             $url = str_replace( '%bbp_user%', $user_nicename, $url );
    505             $url = home_url( user_trailingslashit( $url ) );
    506         }
    507 
    508         return apply_filters( 'bbp_get_user_profile_url', $url, $user_id, $user_nicename );
    509 
    510     }
    511 
    512 /**
    513  * Output link to the profile edit page of a user
    514  *
    515  * @since bbPress (r2688)
    516  *
    517  * @param int $user_id Optional. User id
    518  * @uses bbp_get_user_profile_edit_link() To get user profile edit link
    519  */
    520 function bbp_user_profile_edit_link( $user_id = 0 ) {
    521     echo bbp_get_user_profile_edit_link( $user_id );
    522 }
    523     /**
    524      * Return link to the profile edit page of a user
    525      *
    526      * @since bbPress (r2688)
    527      *
    528      * @param int $user_id Optional. User id
    529      * @uses bbp_get_user_id() To get user id
    530      * @uses get_userdata() To get user data
    531      * @uses bbp_get_user_profile_edit_url() To get user profile edit url
    532      * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the edit
    533      *                        link and user id
    534      * @return string User profile edit link
    535      */
    536     function bbp_get_user_profile_edit_link( $user_id = 0 ) {
    537         if ( !$user_id = bbp_get_user_id( $user_id ) )
    538             return false;
    539 
    540         $user      = get_userdata( $user_id );
    541         $name      = $user->display_name;
    542         $edit_link = '<a href="' . bbp_get_user_profile_url( $user_id ) . '" title="' . esc_attr( $name ) . '">' . $name . '</a>';
    543         return apply_filters( 'bbp_get_user_profile_link', $edit_link, $user_id );
    544     }
    545 
    546 /**
    547  * Output URL to the profile edit page of a user
    548  *
    549  * @since bbPress (r2688)
    550  *
    551  * @param int $user_id Optional. User id
    552  * @param string $user_nicename Optional. User nicename
    553  * @uses bbp_get_user_profile_edit_url() To get user profile edit url
    554  */
    555 function bbp_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
    556     echo bbp_get_user_profile_edit_url( $user_id );
    557 }
    558     /**
    559      * Return URL to the profile edit page of a user
    560      *
    561      * @since bbPress (r2688)
    562      *
    563      * @param int $user_id Optional. User id
    564      * @param string $user_nicename Optional. User nicename
    565      * @uses bbp_get_user_id() To get user id
    566      * @uses add_query_arg() To add custom args to the url
    567      * @uses home_url() To get blog home url
    568      * @uses apply_filters() Calls 'bbp_get_user_edit_profile_url' with the
    569      *                        edit profile url, user id and user nicename
    570      * @return string
    571      */
    572     function bbp_get_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
    573         global $wp_rewrite, $bbp;
    574 
    575         if ( !$user_id = bbp_get_user_id( $user_id ) )
    576             return;
    577 
    578         if ( empty( $wp_rewrite->permalink_structure ) ) {
    579             $url = add_query_arg( array( 'bbp_user' => $user_id, 'edit' => '1' ), home_url( '/' ) );
    580         } else {
    581             $url = $wp_rewrite->front . $bbp->user_slug . '/%bbp_user%/edit';
    582 
    583             if ( empty( $user_nicename ) ) {
    584                 $user = get_userdata( $user_id );
    585                 if ( !empty( $user->user_nicename ) )
    586                     $user_nicename = $user->user_nicename;
    587             }
    588 
    589             $url = str_replace( '%bbp_user%', $user_nicename, $url );
    590             $url = home_url( user_trailingslashit( $url ) );
    591         }
    592 
    593         return apply_filters( 'bbp_get_user_edit_profile_url', $url, $user_id, $user_nicename );
    594 
    595     }
    596594
    597595/** Edit User *****************************************************************/
     
    728726}
    729727
    730 /** END User Functions ********************************************************/
    731 
    732728?>
Note: See TracChangeset for help on using the changeset viewer.