| 1 |
<?php |
| 2 |
function wppb_register_login_widget() { |
| 3 |
register_widget( 'wppb_login_widget' ); |
| 4 |
} |
| 5 |
add_action( 'widgets_init', 'wppb_register_login_widget' ); |
| 6 |
|
| 7 |
class wppb_login_widget extends WP_Widget { |
| 8 |
|
| 9 |
function wppb_login_widget() { |
| 10 |
$widget_ops = array( 'classname' => 'login', 'description' => __( 'This login widget lets you add a login form in the sidebar.', 'profilebuilder' ) ); |
| 11 |
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'wppb-login-widget' ); |
| 12 |
|
| 13 |
do_action( 'wppb_login_widget_settings', $widget_ops, $control_ops); |
| 14 |
|
| 15 |
$this->WP_Widget( 'wppb-login-widget', __('Profile Builder Login Widget', 'profilebuilder'), $widget_ops, $control_ops ); |
| 16 |
|
| 17 |
} |
| 18 |
|
| 19 |
function widget( $args, $instance ) { |
| 20 |
extract( $args ); |
| 21 |
|
| 22 |
$title = apply_filters('wppb_login_widget_title', $instance['title'] ); |
| 23 |
$redirect = trim($instance['redirect']); |
| 24 |
$register = trim($instance['register']); |
| 25 |
$lostpass = trim($instance['lostpass']); |
| 26 |
|
| 27 |
echo $before_widget; |
| 28 |
|
| 29 |
if ( $title ) |
| 30 |
echo $before_title . $title . $after_title; |
| 31 |
|
| 32 |
echo do_shortcode('[wppb-login display="false" redirect="'.$redirect.'"]'); |
| 33 |
|
| 34 |
if ( $register ){ |
| 35 |
|
| 36 |
/* Check if users can register. */ |
| 37 |
$registration = get_option( 'users_can_register' ); |
| 38 |
|
| 39 |
if ( ( current_user_can( 'create_users' ) || $registration ) && !is_user_logged_in() ){ |
| 40 |
$link = '<a href="'.$register.'" alt="'.__( 'Register', 'profilebuilder' ) .'" title="'.__( 'Register', 'profilebuilder' ).'">'.__( 'Register', 'profilebuilder' ).'</a>'; |
| 41 |
echo $registerLink = apply_filters('wppb_login_widget_register', '<br/>'.__( "Don't have an account?", "profilebuilder" ).' '.$link.'<br/>', $link ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
if ( $lostpass && !is_user_logged_in() ){ |
| 46 |
$link = '<br/><a href="'.$lostpass.'" alt="'. __('Lost Password', 'profilebuilder') .'" title="'. __('Lost Password', 'profilebuilder') .'">'. __('Lost Your Password?', 'profilebuilder') .'</a>'; |
| 47 |
echo $link = apply_filters('wppb_login_widget_lost_password', $link, $lostpass ); |
| 48 |
} |
| 49 |
|
| 50 |
do_action( 'wppb_login_widget_display', $args, $instance); |
| 51 |
|
| 52 |
echo $after_widget; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Update the widget settings. |
| 57 |
*/ |
| 58 |
function update( $new_instance, $old_instance ) { |
| 59 |
$instance = $old_instance; |
| 60 |
|
| 61 |
$instance['title'] = strip_tags( $new_instance['title'] ); |
| 62 |
$instance['redirect'] = strip_tags( $new_instance['redirect'] ); |
| 63 |
$instance['register'] = strip_tags( $new_instance['register'] ); |
| 64 |
$instance['lostpass'] = strip_tags( $new_instance['lostpass'] ); |
| 65 |
|
| 66 |
do_action( 'wppb_login_widget_update_action', $new_instance, $old_instance); |
| 67 |
|
| 68 |
return $instance; |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
function form( $instance ) { |
| 74 |
|
| 75 |
$defaults = array( 'title' => __('Login', 'profilebuilder'), 'redirect' => '', 'register' => '', 'lostpass' => '' ); |
| 76 |
$instance = wp_parse_args( (array) $instance, $defaults ); ?> |
| 77 |
|
| 78 |
<p> |
| 79 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'profilebuilder' ); ?></label> |
| 80 |
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" /> |
| 81 |
</p> |
| 82 |
|
| 83 |
<p> |
| 84 |
<label for="<?php echo $this->get_field_id( 'redirect' ); ?>"><?php _e( 'After login redirect URL (optional):', 'profilebuilder' ); ?></label> |
| 85 |
<input id="<?php echo $this->get_field_id( 'redirect' ); ?>" name="<?php echo $this->get_field_name( 'redirect' ); ?>" value="<?php echo $instance['redirect']; ?>" style="width:100%;" /> |
| 86 |
</p> |
| 87 |
|
| 88 |
<p> |
| 89 |
<label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register page URL (optional):', 'profilebuilder' ); ?></label> |
| 90 |
<input id="<?php echo $this->get_field_id( 'register' ); ?>" name="<?php echo $this->get_field_name( 'register' ); ?>" value="<?php echo $instance['register']; ?>" style="width:100%;" /> |
| 91 |
</p> |
| 92 |
|
| 93 |
<p> |
| 94 |
<label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Password Recovery page URL (optional):', 'profilebuilder' ); ?></label> |
| 95 |
<input id="<?php echo $this->get_field_id( 'lostpass' ); ?>" name="<?php echo $this->get_field_name( 'lostpass' ); ?>" value="<?php echo $instance['lostpass']; ?>" style="width:100%;" /> |
| 96 |
</p> |
| 97 |
|
| 98 |
<?php |
| 99 |
|
| 100 |
do_action( 'wppb_login_widget_after_display', $instance); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
// we can apply this easily, if we need it |
| 105 |
function wppb_scroll_down_to_widget($content){ |
| 106 |
return "<script> jQuery('html, body').animate({scrollTop: jQuery('#wppb_login').offset().top }) </script>" . $content; |
| 107 |
} |
| 108 |
//add_filter('wppb_login_wp_error_message', 'wppb_scroll_down_to_widget'); |
| 109 |
|
| 110 |
function wppb_require_jquery(){ |
| 111 |
wp_enqueue_script( 'jquery' ); |
| 112 |
} |
| 113 |
//add_action( 'wp_enqueue_scripts', 'wppb_require_jquery' ); |