Advertisement
Guest User

Untitled

a guest
May 4th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Login BP
  4. Plugin URI: https://www.kevinmamaqi.com
  5. Description: Login para BuscoPreparador.com
  6. Version: 1.0
  7. Author: Kevin Mamaqi
  8. Author URI: https://www.kevinmamaqi.com
  9. License: GPL2
  10. */
  11.  
  12. /**
  13. * Adds Login_BP widget.
  14. */
  15.  
  16. // Turn on output buffering
  17. ob_start();
  18.  
  19.  
  20. class BP_Login extends WP_Widget {
  21.  
  22. static private $login_registration_status;
  23.  
  24. /**
  25. * Register widget with WordPress.
  26. */
  27. function __construct() {
  28. parent::__construct(
  29. 'bp_login', // Base ID
  30. __( 'BP_Login', 'text_domain' ), // Name
  31. array( 'description' => __( 'A tabbed login and registration widget for WordPress', 'text_domain' ), ) // Args
  32. );
  33. }
  34.  
  35. /**
  36. * Returns the HTML for the login form
  37. * @return string
  38. */
  39. static function login_form() {
  40. $html = '<form method="post" action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">';
  41. $html .= '<div class="form-group"><input type="text" class="form-control" name="login_username" id="login_username" placeholder="Nombre de Usuario"></div>';
  42. $html .= '<div class="form-group"><input type="password" class="form-control" name="login_password" id="login_password" placeholder="Contraseña"></div>';
  43. $html .= '<div class="g-recaptcha" data-sitekey="6LefKhoTAAAAALBduf1bC_0TvopN2aUGU0X5rcos"></div>';
  44. $html .= '<div class="checkbox"><label><input type="checkbox" name="remember_login" value="true" checked="checked"> Recuerdame</label></div>';
  45. $html .= '<input class="btn btn-primary btn-block" type="submit" name="login_submit" value="Acceder" />';
  46. $html .= '<li role="separator" style="margin: 1.5em 0;" class="divider"></li>';
  47. $html .= '<p>¿Todavía no estas registrado?</p>';
  48. $html .= '<a class="btn btn-warning btn-block" href="' . wp_registration_url() . '">Únete</a>';
  49. $html .= '</form>';
  50.  
  51. return $html;
  52.  
  53. }
  54.  
  55.  
  56. /**
  57. * Login registered users
  58. */
  59. function login_user() {
  60. if ( isset( $_POST['login_submit'] ) ) {
  61.  
  62. $creds = array();
  63. $creds['user_login'] = esc_attr( $_POST['login_username'] );
  64. $creds['user_password'] = esc_attr( $_POST['login_password'] );
  65. $creds['remember'] = esc_attr( $_POST['remember_login'] );
  66.  
  67. $login_user = wp_signon( $creds, false );
  68.  
  69. if ( ! is_wp_error( $login_user ) ) {
  70. wp_redirect( home_url( 'wp-admin' ) );
  71. } elseif ( is_wp_error( $login_user ) ) {
  72. self::$login_registration_status = $login_user->get_error_message();
  73. }
  74. }
  75. }
  76.  
  77.  
  78. public function widget( $args, $instance ) { ?>
  79.  
  80. <?php
  81. $title = apply_filters( 'widget_title', $instance['title'] );
  82.  
  83. echo $args['before_widget'];
  84. if ( ! empty( $title ) ) {
  85. echo $args['before_title'] . $title . $args['after_title'];
  86. } ?>
  87.  
  88. <?php $this->login_user(); ?>
  89.  
  90. <div class="login-reg-error"><?php echo self::$login_registration_status; ?></div>
  91.  
  92. <?php echo self::login_form(); ?>
  93.  
  94. <?php
  95. echo $args['after_widget'];
  96. }
  97.  
  98.  
  99. public function form( $instance ) {
  100. if ( isset( $instance['title'] ) ) {
  101. $title = $instance['title'];
  102. } else {
  103. $title = __( 'Acceso BP', 'text_domain' );
  104. }
  105. ?>
  106. <p>
  107. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  108. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
  109. name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
  110. value="<?php echo esc_attr( $title ); ?>">
  111. </p>
  112. <?php
  113. }
  114.  
  115. public function update( $new_instance, $old_instance ) {
  116. $instance = array();
  117. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  118.  
  119. return $instance;
  120. }
  121.  
  122. } // class BP_Login
  123.  
  124. // register Foo_Widget widget
  125. function register_bp_login() {
  126. register_widget( 'BP_login' );
  127. }
  128.  
  129. add_action( 'widgets_init', 'register_bp_login' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement