Skip to:
Content

bbPress.org

Ticket #1464: login-widget.diff

File login-widget.diff, 9.1 KB (added by GautamGupta, 15 years ago)
  • bbp-includes/bbp-general-template.php

     
    323323 *
    324324 * @since bbPress (r2815)
    325325 *
    326  * @param str $url Pass a URL to redirect to
     326 * @param string $url Pass a URL to redirect to
    327327 * @uses add_query_arg() To add a arg to the url
    328328 * @uses site_url() Toget the site url
    329329 * @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args
     
    10611061<?php endif;
    10621062}
    10631063
     1064/** Login/logout/register/lost pass *******************************************/
     1065
     1066/**
     1067 * Output the logout link
     1068 *
     1069 * @since bbPress (r)
     1070 *
     1071 * @param string $redirect_to Redirect to url
     1072 * @uses bbp_get_logout_link() To get the logout link
     1073 */
     1074function bbp_logout_link( $redirect_to = '' ) {
     1075        echo bbp_get_logout_link( $redirect_to );
     1076}
     1077        /**
     1078         * Return the logout link
     1079         *
     1080         * @since bbPress (r)
     1081         *
     1082         * @param string $redirect_to Redirect to url
     1083         * @uses wp_logout_url() To get the logout url
     1084         * @uses apply_filters() Calls 'bbp_get_logout_link' with the logout link and
     1085         *                        redirect to url
     1086         * @return string The logout link
     1087         */
     1088        function bbp_get_logout_link( $redirect_to = '' ) {
     1089                return apply_filters( 'bbp_get_logout_link', '<a href="' . wp_logout_url() . '">' . __( 'Logout', 'bbpress' ) . '</a>', $redirect_to );
     1090        }
     1091
    10641092?>
  • bbp-includes/bbp-hooks.php

     
    6868}
    6969
    7070// Widgets
     71add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Login_Widget");'   ) );
    7172add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Forums_Widget");'  ) );
    7273add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Topics_Widget");'  ) );
    7374add_action( 'widgets_init', create_function( '', 'return register_widget("BBP_Replies_Widget");' ) );
  • bbp-includes/bbp-user-template.php

     
    363363
    364364        }
    365365
     366/**
     367 * Output the link to the admin section
     368 *
     369 * @since bbPress (r)
     370 *
     371 * @param mixed $args Optional. See {@link bbp_get_admin_link()}
     372 * @uses bbp_get_admin_link() To get the admin link
     373 */
     374function bbp_admin_link( $args = '' ) {
     375        echo bbp_get_admin_link( $args );
     376}
     377        /**
     378         * Return the link to the admin section
     379         *
     380         * @since bbPress (r)
     381         *
     382         * @param mixed $args Optional. This function supports these arguments:
     383         *  - text: The text
     384         *  - before: Before the lnk
     385         *  - after: After the link
     386         * @uses current_user_can() To check if the current user can moderate
     387         * @uses admin_url() To get the admin url
     388         * @uses apply_filters() Calls 'bbp_get_admin_link' with the link & args
     389         * @return The link
     390         */
     391        function bbp_get_admin_link( $args = '' ) {
     392                if ( !current_user_can( 'moderate' ) )
     393                        return;
     394
     395                if ( $args && is_string( $args ) && false === strpos( $args, '=' ) )
     396                        $args = array( 'text' => $args );
     397
     398                $defaults = array( 'text' => __( 'Admin', 'bbpress' ), 'before' => '', 'after' => '' );
     399                $args     = wp_parse_args( $args, $defaults );
     400                extract( $args, EXTR_SKIP );
     401
     402                $uri = admin_url();
     403
     404                return apply_filters( 'bbp_get_admin_link', $before . '<a href="' . $uri . '">' . $text . '</a>' . $after, $args );
     405        }
     406
    366407/** Favorites *****************************************************************/
    367408
    368409/**
     
    742783 * @uses bbp_get_current_user_id() To get the current user id
    743784 */
    744785function bbp_logged_in_redirect( $url = '' ) {
    745         if ( is_user_logged_in() ) {
    746                 $redirect_to = !empty( $url ) ? $url : bbp_get_user_profile_url( bbp_get_current_user_id() );
    747                 wp_safe_redirect( $redirect_to );
    748                 exit;
    749         }
     786        if ( !is_user_logged_in() )
     787                return;
     788
     789        $redirect_to = !empty( $url ) ? $url : bbp_get_user_profile_url( bbp_get_current_user_id() );
     790        wp_safe_redirect( $redirect_to );
     791        exit;
    750792}
    751793
    752794/**
  • bbp-includes/bbp-widgets.php

     
    33/**
    44 * bbPress Widgets
    55 *
     6 * Contains the forum list, topic list, reply list and login form widgets.
     7 *
    68 * @package bbPress
    79 * @subpackage Widgets
    810 */
    911
    1012/**
     13 * bbPress Login Widget
     14 *
     15 * Adds a widget which displays the login form
     16 *
     17 * @since bbPress (r)
     18 *
     19 * @uses WP_Widget
     20 */
     21class BBP_Login_Widget extends WP_Widget {
     22
     23        /**
     24         * bbPress Login Widget
     25         *
     26         * Registers the login widget
     27         *
     28         * @since bbPress (r)
     29         *
     30         * @uses apply_filters() Calls 'bbp_login_widget_options' with the
     31         *                        widget options
     32         */
     33        function BBP_Login_Widget() {
     34                $widget_ops = apply_filters( 'bbp_login_widget_options', array(
     35                        'classname'   => 'widget_display_forums',
     36                        'description' => __( 'The login widget.', 'bbpress' )
     37                ) );
     38
     39                parent::WP_Widget( false, __( 'bbPress Login Widget', 'bbpress' ), $widget_ops );
     40        }
     41
     42        /**
     43         * Displays the output, the login form
     44         *
     45         * @since bbPress (r)
     46         *
     47         * @param mixed $args Arguments
     48         * @param array $instance Instance
     49         * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
     50         * @uses get_template_part() To get the login/logged in form
     51         */
     52        function widget( $args, $instance ) {
     53                extract( $args );
     54
     55                $title = apply_filters( 'bbp_login_widget_title', $instance['title'] );
     56
     57                echo $before_widget;
     58                echo $before_title . $title . $after_title;
     59
     60                get_template_part( 'form', is_user_logged_in() ? 'bbp_user_logged_in' : 'bbp_user_login' );
     61
     62                echo $after_widget;
     63        }
     64
     65        /**
     66         * Update the login widget options
     67         *
     68         * @since bbPress (r)
     69         *
     70         * @param array $new_instance The new instance options
     71         * @param array $old_instance The old instance options
     72         */
     73        function update( $new_instance, $old_instance ) {
     74                $instance          = $old_instance;
     75                $instance['title'] = strip_tags( $new_instance['title'] );
     76
     77                return $instance;
     78        }
     79
     80        /**
     81         * Output the login widget options form
     82         *
     83         * @since bbPress (r)
     84         *
     85         * @param $instance Instance
     86         * @uses BBP_Login_Widget::get_field_id() To output the field id
     87         * @uses BBP_Login_Widget::get_field_name() To output the field name
     88         */
     89        function form( $instance ) {
     90                $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?>
     91
     92                <p>
     93                        <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
     94                        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label>
     95                </p>
     96
     97                <?php
     98        }
     99}
     100
     101/**
    11102 * bbPress Forum Widget
    12103 *
    13104 * Adds a widget which displays the forum list
     
    82173
    83174                <?php echo $after_widget;
    84175
    85                 endif;         
     176                endif;
    86177        }
    87178
    88179        /**
     
    278369         * @uses BBP_Topics_Widget::get_field_name() To output the field name
    279370         */
    280371        function form( $instance ) {
    281                 $title     = !empty( $instance['title'] )    ? esc_attr( $instance['title']     ) : '';
     372                $title     = !empty( $instance['title']     ) ? esc_attr( $instance['title']     ) : '';
    282373                $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
    283374                $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
    284375                $pop_check = !empty( $instance['pop_check'] ) ? esc_attr( $instance['pop_check'] ) : ''; ?>
  • bbp-themes/bbp-twentyten/css/bbpress.css

     
    365365        font-size: 11px;
    366366        color: #aaa;
    367367}
     368
     369/* =Widgets
     370-------------------------------------------------------------- */
     371
     372.widget-area .bbp-login-form fieldset legend {
     373        display: none;
     374}
     375
     376.widget-area .bbp-login-form .bbp-username,
     377.widget-area .bbp-login-form .bbp-password,
     378.widget-area .bbp-login-form .bbp-remember-me,
     379.widget-area .bbp-login-form .bbp-submit-wrapper {
     380        margin-top: 10px;
     381}
     382
     383.widget-area .bbp-login-form .bbp-remember-me {
     384        float: left;
     385}
     386
     387.widget-area .bbp-login-form .bbp-submit-wrapper {
     388        float: right;
     389}
  • bbp-themes/bbp-twentyten/form-bbp_user_logged_in.php

     
     1<?php
     2
     3/**
     4 * User Logged in Form
     5 *
     6 * @package bbPress
     7 * @subpackage Theme
     8 */
     9
     10?>
     11
     12        <div class="bbp-logged-in">
     13                <?php printf( __( 'Welcome, %1$s', 'bbpress' ),  bbp_get_user_profile_link( bbp_get_current_user_id() ) ); ?>
     14                <?php bbp_admin_link( array( 'before' => ' | ' ) );?>
     15                | <?php bbp_logout_link(); ?>
     16        </div>