| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 3 |
|
| 4 |
function wppb_register_login_widget() { |
| 5 |
register_widget( 'wppb_login_widget' ); |
| 6 |
} |
| 7 |
add_action( 'widgets_init', 'wppb_register_login_widget' ); |
| 8 |
|
| 9 |
class wppb_login_widget extends WP_Widget { |
| 10 |
|
| 11 |
function __construct() { |
| 12 |
$widget_ops = array( 'classname' => 'login', 'description' => __( 'This login widget lets you add a login form in the sidebar.', 'profile-builder' ) ); |
| 13 |
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'wppb-login-widget' ); |
| 14 |
|
| 15 |
do_action( 'wppb_login_widget_settings', $widget_ops, $control_ops); |
| 16 |
|
| 17 |
parent::__construct( 'wppb-login-widget', __('Profile Builder Login Widget', 'profile-builder'), $widget_ops, $control_ops ); |
| 18 |
|
| 19 |
} |
| 20 |
|
| 21 |
function widget( $args, $instance ) { |
| 22 |
extract( $args ); |
| 23 |
|
| 24 |
$title = apply_filters( 'wppb_login_widget_title', ( isset( $instance['title'] ) ? $instance['title'] : '' ) ); |
| 25 |
$redirect = ( isset( $instance['redirect'] ) ? trim( $instance['redirect'] ) : '' ); |
| 26 |
$register = ( isset( $instance['register'] ) ? trim( $instance['register'] ) : '' ); |
| 27 |
$lostpass = ( isset( $instance['lostpass'] ) ? trim( $instance['lostpass'] ) : '' ); |
| 28 |
|
| 29 |
echo wp_kses_post( $args['before_widget'] ); |
| 30 |
|
| 31 |
if ( ! empty( $title ) ) |
| 32 |
echo wp_kses_post( $args['before_title'] . $title . $args['after_title'] ); |
| 33 |
|
| 34 |
echo do_shortcode('[wppb-login display="false" register_url="'.$register.'" lostpassword_url="'.$lostpass.'" redirect_url="'.$redirect.'"]'); |
| 35 |
|
| 36 |
do_action( 'wppb_login_widget_display', $args, $instance); |
| 37 |
|
| 38 |
echo wp_kses_post( $args['after_widget'] ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Update the widget settings. |
| 43 |
*/ |
| 44 |
function update( $new_instance, $old_instance ) { |
| 45 |
$instance = $old_instance; |
| 46 |
|
| 47 |
$instance['title'] = strip_tags( $new_instance['title'] ); |
| 48 |
$instance['redirect'] = strip_tags( $new_instance['redirect'] ); |
| 49 |
$instance['register'] = strip_tags( $new_instance['register'] ); |
| 50 |
$instance['lostpass'] = strip_tags( $new_instance['lostpass'] ); |
| 51 |
|
| 52 |
do_action( 'wppb_login_widget_update_action', $new_instance, $old_instance); |
| 53 |
|
| 54 |
return $instance; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
function form( $instance ) { |
| 60 |
|
| 61 |
$defaults = array( 'title' => __('Login', 'profile-builder'), 'redirect' => '', 'register' => '', 'lostpass' => '' ); |
| 62 |
$instance = wp_parse_args( (array) $instance, $defaults ); ?> |
| 63 |
|
| 64 |
<p> |
| 65 |
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'profile-builder' ); ?></label> |
| 66 |
<input id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" class="widefat" type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" style="width:100%;" /> |
| 67 |
</p> |
| 68 |
|
| 69 |
<p> |
| 70 |
<label for="<?php echo esc_attr( $this->get_field_id( 'redirect' ) ); ?>"><?php esc_html_e( 'After login redirect URL (optional):', 'profile-builder' ); ?></label> |
| 71 |
<input id="<?php echo esc_attr( $this->get_field_id( 'redirect' ) ); ?>" class="widefat wppb-widget-url-field" type="url" name="<?php echo esc_attr( $this->get_field_name( 'redirect' ) ); ?>" value="<?php echo esc_attr( $instance['redirect'] ); ?>" style="width:100%;" /> |
| 72 |
</p> |
| 73 |
|
| 74 |
<p> |
| 75 |
<label for="<?php echo esc_attr( $this->get_field_id( 'register' ) ); ?>"><?php esc_html_e( 'Register page URL (optional):', 'profile-builder' ); ?></label> |
| 76 |
<input id="<?php echo esc_attr( $this->get_field_id( 'register' ) ); ?>" class="widefat wppb-widget-url-field" type="url" name="<?php echo esc_attr( $this->get_field_name( 'register' ) ); ?>" value="<?php echo esc_attr( $instance['register'] ); ?>" style="width:100%;" /> |
| 77 |
</p> |
| 78 |
|
| 79 |
<p> |
| 80 |
<label for="<?php echo esc_attr( $this->get_field_id( 'lostpass' ) ); ?>"><?php esc_html_e( 'Password Recovery page URL (optional):', 'profile-builder' ); ?></label> |
| 81 |
<input id="<?php echo esc_attr( $this->get_field_id( 'lostpass' ) ); ?>" class="widefat wppb-widget-url-field" type="url" name="<?php echo esc_attr( $this->get_field_name( 'lostpass' ) ); ?>" value="<?php echo esc_attr( $instance['lostpass'] ); ?>" style="width:100%;" /> |
| 82 |
</p> |
| 83 |
|
| 84 |
<?php |
| 85 |
|
| 86 |
do_action( 'wppb_login_widget_after_display', $instance); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
// we can apply this easily, if we need it |
| 91 |
function wppb_scroll_down_to_widget($content){ |
| 92 |
return "<script> jQuery('html, body').animate({scrollTop: jQuery('#wppb_login').offset().top }) </script>" . $content; |
| 93 |
} |
| 94 |
//add_filter('wppb_login_wp_error_message', 'wppb_scroll_down_to_widget'); |
| 95 |
|
| 96 |
function wppb_require_jquery(){ |
| 97 |
wp_enqueue_script( 'jquery' ); |
| 98 |
} |
| 99 |
//add_action( 'wp_enqueue_scripts', 'wppb_require_jquery' ); |