Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2015 01:37:37 AM (10 years ago)
Author:
r-a-y
Message:

Members: Move member-related widgets over from Core.

Also adds PHPDoc @since tag to related classes and functions.

Props dcavins.

See #5953.

File:
1 copied

Legend:

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

    r9322 r9323  
    11<?php
    22/**
    3  * BuddyPress Core Component Widgets.
     3 * BuddyPress Members Widgets
    44 *
    55 * @package BuddyPress
    6  * @subpackage Core
    76 */
    87
     
    1110
    1211/**
    13  * Register bp-core widgets.
    14  */
    15 function bp_core_register_widgets() {
    16     add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Login_Widget");') );
     12 * Register bp-members widgets.
     13 *
     14 * Previously, these widgets were registered in bp-core.
     15 *
     16 * @since BuddyPress (2.2.0)
     17 */
     18function bp_members_register_widgets() {
    1719    add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Members_Widget");') );
    1820    add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Whos_Online_Widget");') );
    1921    add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Recently_Active_Widget");') );
    2022}
    21 add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
    22 
    23 /**
    24  * BuddyPress Login Widget.
    25  *
    26  * @since BuddyPress (1.9.0)
    27  */
    28 class BP_Core_Login_Widget extends WP_Widget {
    29 
    30     /**
    31      * Constructor method.
    32      */
    33     public function __construct() {
    34         parent::__construct(
    35             false,
    36             _x( '(BuddyPress) Log In', 'Title of the login widget', 'buddypress' ),
    37             array(
    38                 'description' => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
    39                 'classname' => 'widget_bp_core_login_widget buddypress widget',
    40             )
    41         );
    42     }
    43 
    44     /**
    45      * Display the login widget.
    46      *
    47      * @see WP_Widget::widget() for description of parameters.
    48      *
    49      * @param array $args Widget arguments.
    50      * @param array $instance Widget settings, as saved by the user.
    51      */
    52     public function widget( $args, $instance ) {
    53         $title = isset( $instance['title'] ) ? $instance['title'] : '';
    54         $title = apply_filters( 'widget_title', $title );
    55 
    56         echo $args['before_widget'];
    57 
    58         echo $args['before_title'] . esc_html( $title ) . $args['after_title']; ?>
    59 
    60         <?php if ( is_user_logged_in() ) : ?>
    61 
    62             <?php do_action( 'bp_before_login_widget_loggedin' ); ?>
    63 
    64             <div class="bp-login-widget-user-avatar">
    65                 <a href="<?php echo bp_loggedin_user_domain(); ?>">
    66                     <?php bp_loggedin_user_avatar( 'type=thumb&width=50&height=50' ); ?>
    67                 </a>
    68             </div>
    69 
    70             <div class="bp-login-widget-user-links">
    71                 <div class="bp-login-widget-user-link"><?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?></div>
    72                 <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>
    73             </div>
    74 
    75             <?php do_action( 'bp_after_login_widget_loggedin' ); ?>
    76 
    77         <?php else : ?>
    78 
    79             <?php do_action( 'bp_before_login_widget_loggedout' ); ?>
    80 
    81             <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">
    82                 <label for="bp-login-widget-user-login"><?php _e( 'Username', 'buddypress' ); ?></label>
    83                 <input type="text" name="log" id="bp-login-widget-user-login" class="input" value="" />
    84 
    85                 <label for="bp-login-widget-user-pass"><?php _e( 'Password', 'buddypress' ); ?></label>
    86                 <input type="password" name="pwd" id="bp-login-widget-user-pass" class="input" value=""  />
    87 
    88                 <div class="forgetmenot"><label><input name="rememberme" type="checkbox" id="bp-login-widget-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ); ?></label></div>
    89 
    90                 <input type="submit" name="wp-submit" id="bp-login-widget-submit" value="<?php esc_attr_e( 'Log In', 'buddypress' ); ?>" />
    91 
    92                 <?php if ( bp_get_signup_allowed() ) : ?>
    93 
    94                     <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>
    95 
    96                 <?php endif; ?>
    97 
    98             </form>
    99 
    100             <?php do_action( 'bp_after_login_widget_loggedout' ); ?>
    101 
    102         <?php endif;
    103 
    104         echo $args['after_widget'];
    105     }
    106 
    107     /**
    108      * Update the login widget options.
    109      *
    110      * @param array $new_instance The new instance options.
    111      * @param array $old_instance The old instance options.
    112      * @return array $instance The parsed options to be saved.
    113      */
    114     public function update( $new_instance, $old_instance ) {
    115         $instance             = $old_instance;
    116         $instance['title']    = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
    117 
    118         return $instance;
    119     }
    120 
    121     /**
    122      * Output the login widget options form.
    123      *
    124      * @param $instance Settings for this widget.
    125      */
    126     public function form( $instance = array() ) {
    127 
    128         $settings = wp_parse_args( $instance, array(
    129             'title' => '',
    130         ) ); ?>
    131 
    132         <p>
    133             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?>
    134             <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>
    135         </p>
    136 
    137         <?php
    138     }
    139 }
     23add_action( 'bp_register_widgets', 'bp_members_register_widgets' );
    14024
    14125/**
    14226 * Members Widget.
     27 *
     28 * @since BuddyPress (1.0.3)
    14329 */
    14430class BP_Core_Members_Widget extends WP_Widget {
     
    306192}
    307193
    308 /*** WHO'S ONLINE WIDGET *****************/
    309 
     194/**
     195 * Who's Online Widget.
     196 *
     197 * @since BuddyPress (1.0.3)
     198 */
    310199class BP_Core_Whos_Online_Widget extends WP_Widget {
    311200
     
    409298}
    410299
    411 /*** RECENTLY ACTIVE WIDGET *****************/
    412 
     300/**
     301 * Recently Active Members Widget.
     302 *
     303 * @since BuddyPress (1.0.3)
     304 */
    413305class BP_Core_Recently_Active_Widget extends WP_Widget {
    414306
     
    514406/**
    515407 * AJAX request handler for Members widgets.
     408 *
     409 * @since BuddyPress (1.0.0)
    516410 */
    517411function bp_core_ajax_widget_members() {
Note: See TracChangeset for help on using the changeset viewer.