Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Login BP
- Plugin URI: https://www.kevinmamaqi.com
- Description: Login para BuscoPreparador.com
- Version: 1.0
- Author: Kevin Mamaqi
- Author URI: https://www.kevinmamaqi.com
- License: GPL2
- */
- /**
- * Adds Login_BP widget.
- */
- // Turn on output buffering
- ob_start();
- class BP_Login extends WP_Widget {
- static private $login_registration_status;
- /**
- * Register widget with WordPress.
- */
- function __construct() {
- parent::__construct(
- 'bp_login', // Base ID
- __( 'BP_Login', 'text_domain' ), // Name
- array( 'description' => __( 'A tabbed login and registration widget for WordPress', 'text_domain' ), ) // Args
- );
- }
- /**
- * Returns the HTML for the login form
- * @return string
- */
- static function login_form() {
- $html = '<form method="post" action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">';
- $html .= '<div class="form-group"><input type="text" class="form-control" name="login_username" id="login_username" placeholder="Nombre de Usuario"></div>';
- $html .= '<div class="form-group"><input type="password" class="form-control" name="login_password" id="login_password" placeholder="Contraseña"></div>';
- $html .= '<div class="g-recaptcha" data-sitekey="6LefKhoTAAAAALBduf1bC_0TvopN2aUGU0X5rcos"></div>';
- $html .= '<div class="checkbox"><label><input type="checkbox" name="remember_login" value="true" checked="checked"> Recuerdame</label></div>';
- $html .= '<input class="btn btn-primary btn-block" type="submit" name="login_submit" value="Acceder" />';
- $html .= '<li role="separator" style="margin: 1.5em 0;" class="divider"></li>';
- $html .= '<p>¿Todavía no estas registrado?</p>';
- $html .= '<a class="btn btn-warning btn-block" href="' . wp_registration_url() . '">Únete</a>';
- $html .= '</form>';
- return $html;
- }
- /**
- * Login registered users
- */
- function login_user() {
- if ( isset( $_POST['login_submit'] ) ) {
- $creds = array();
- $creds['user_login'] = esc_attr( $_POST['login_username'] );
- $creds['user_password'] = esc_attr( $_POST['login_password'] );
- $creds['remember'] = esc_attr( $_POST['remember_login'] );
- $login_user = wp_signon( $creds, false );
- if ( ! is_wp_error( $login_user ) ) {
- wp_redirect( home_url( 'wp-admin' ) );
- } elseif ( is_wp_error( $login_user ) ) {
- self::$login_registration_status = $login_user->get_error_message();
- }
- }
- }
- public function widget( $args, $instance ) { ?>
- <?php
- $title = apply_filters( 'widget_title', $instance['title'] );
- echo $args['before_widget'];
- if ( ! empty( $title ) ) {
- echo $args['before_title'] . $title . $args['after_title'];
- } ?>
- <?php $this->login_user(); ?>
- <div class="login-reg-error"><?php echo self::$login_registration_status; ?></div>
- <?php echo self::login_form(); ?>
- <?php
- echo $args['after_widget'];
- }
- public function form( $instance ) {
- if ( isset( $instance['title'] ) ) {
- $title = $instance['title'];
- } else {
- $title = __( 'Acceso BP', 'text_domain' );
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
- <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( $title ); ?>">
- </p>
- <?php
- }
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
- return $instance;
- }
- } // class BP_Login
- // register Foo_Widget widget
- function register_bp_login() {
- register_widget( 'BP_login' );
- }
- add_action( 'widgets_init', 'register_bp_login' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement