Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:26:30 AM (9 years ago)
Author:
boonebgorges
Message:

Move bp-core classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-widgets.php

    r10497 r10518  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-core-login-widget.php';
     14
    1315/**
    1416 * Register bp-core widgets.
     
    2022}
    2123add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
    22 
    23 /**
    24  * BuddyPress Login Widget.
    25  *
    26  * @since 1.9.0
    27  */
    28 class BP_Core_Login_Widget extends WP_Widget {
    29 
    30     /**
    31      * Constructor method.
    32      *
    33      * @since 1.9.0
    34      */
    35     public function __construct() {
    36         parent::__construct(
    37             false,
    38             _x( '(BuddyPress) Log In', 'Title of the login widget', 'buddypress' ),
    39             array(
    40                 'description' => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
    41                 'classname' => 'widget_bp_core_login_widget buddypress widget',
    42             )
    43         );
    44     }
    45 
    46     /**
    47      * Display the login widget.
    48      *
    49      * @since 1.9.0
    50      *
    51      * @see WP_Widget::widget() for description of parameters.
    52      *
    53      * @param array $args     Widget arguments.
    54      * @param array $instance Widget settings, as saved by the user.
    55      */
    56     public function widget( $args, $instance ) {
    57         $title = isset( $instance['title'] ) ? $instance['title'] : '';
    58 
    59         /**
    60          * Filters the title of the Login widget.
    61          *
    62          * @since 1.9.0
    63          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    64          *
    65          * @param string $title    The widget title.
    66          * @param array  $instance The settings for the particular instance of the widget.
    67          * @param string $id_base  Root ID for all widgets of this type.
    68          */
    69         $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    70 
    71         echo $args['before_widget'];
    72 
    73         echo $args['before_title'] . esc_html( $title ) . $args['after_title']; ?>
    74 
    75         <?php if ( is_user_logged_in() ) : ?>
    76 
    77             <?php
    78             /**
    79              * Fires before the display of widget content if logged in.
    80              *
    81              * @since 1.9.0
    82              */
    83             do_action( 'bp_before_login_widget_loggedin' ); ?>
    84 
    85             <div class="bp-login-widget-user-avatar">
    86                 <a href="<?php echo bp_loggedin_user_domain(); ?>">
    87                     <?php bp_loggedin_user_avatar( 'type=thumb&width=50&height=50' ); ?>
    88                 </a>
    89             </div>
    90 
    91             <div class="bp-login-widget-user-links">
    92                 <div class="bp-login-widget-user-link"><?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?></div>
    93                 <div class="bp-login-widget-user-logout"><a class="logout" href="<?php echo wp_logout_url( bp_get_requested_url() ); ?>"><?php _e( 'Log Out', 'buddypress' ); ?></a></div>
    94             </div>
    95 
    96             <?php
    97 
    98             /**
    99              * Fires after the display of widget content if logged in.
    100              *
    101              * @since 1.9.0
    102              */
    103             do_action( 'bp_after_login_widget_loggedin' ); ?>
    104 
    105         <?php else : ?>
    106 
    107             <?php
    108 
    109             /**
    110              * Fires before the display of widget content if logged out.
    111              *
    112              * @since 1.9.0
    113              */
    114             do_action( 'bp_before_login_widget_loggedout' ); ?>
    115 
    116             <form name="bp-login-form" id="bp-login-widget-form" class="standard-form" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
    117                 <label for="bp-login-widget-user-login"><?php _e( 'Username', 'buddypress' ); ?></label>
    118                 <input type="text" name="log" id="bp-login-widget-user-login" class="input" value="" />
    119 
    120                 <label for="bp-login-widget-user-pass"><?php _e( 'Password', 'buddypress' ); ?></label>
    121                 <input type="password" name="pwd" id="bp-login-widget-user-pass" class="input" value="" <?php bp_form_field_attributes( 'password' ) ?> />
    122 
    123                 <div class="forgetmenot"><label for="bp-login-widget-rememberme"><input name="rememberme" type="checkbox" id="bp-login-widget-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ); ?></label></div>
    124 
    125                 <input type="submit" name="wp-submit" id="bp-login-widget-submit" value="<?php esc_attr_e( 'Log In', 'buddypress' ); ?>" />
    126 
    127                 <?php if ( bp_get_signup_allowed() ) : ?>
    128 
    129                     <span class="bp-login-widget-register-link"><?php printf( __( '<a href="%s" title="Register for a new account">Register</a>', 'buddypress' ), bp_get_signup_page() ); ?></span>
    130 
    131                 <?php endif; ?>
    132 
    133                 <?php
    134 
    135                 /**
    136                  * Fires inside the display of the login widget form.
    137                  *
    138                  * @since 2.4.0
    139                  */
    140                 do_action( 'bp_login_widget_form' ); ?>
    141 
    142             </form>
    143 
    144             <?php
    145 
    146             /**
    147              * Fires after the display of widget content if logged out.
    148              *
    149              * @since 1.9.0
    150              */
    151             do_action( 'bp_after_login_widget_loggedout' ); ?>
    152 
    153         <?php endif;
    154 
    155         echo $args['after_widget'];
    156     }
    157 
    158     /**
    159      * Update the login widget options.
    160      *
    161      * @since 1.9.0
    162      *
    163      * @param array $new_instance The new instance options.
    164      * @param array $old_instance The old instance options.
    165      * @return array $instance The parsed options to be saved.
    166      */
    167     public function update( $new_instance, $old_instance ) {
    168         $instance             = $old_instance;
    169         $instance['title']    = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
    170 
    171         return $instance;
    172     }
    173 
    174     /**
    175      * Output the login widget options form.
    176      *
    177      * @since 1.9.0
    178      *
    179      * @param array $instance Settings for this widget.
    180      * @return void
    181      */
    182     public function form( $instance = array() ) {
    183 
    184         $settings = wp_parse_args( $instance, array(
    185             'title' => '',
    186         ) ); ?>
    187 
    188         <p>
    189             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?>
    190             <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label>
    191         </p>
    192 
    193         <?php
    194     }
    195 }
Note: See TracChangeset for help on using the changeset viewer.