PluginProbe
Gianism / trunk
Gianism vtrunk
4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.4.0 5.0.0 5.0.1 5.0.2 5.1.0 5.2.1 5.2.2 5.3.0 6.0.0 6.0.1 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 65 releases
gianism / app / Gianism / Controller / Login.php

Login.php in Gianism trunk, at app/Gianism/Controller/Login.php

151 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Gianism\Controller;
4
5 use Gianism\Pattern\AbstractController;
6
7
8 /**
9 * Login screen controller
10 *
11 * @package Gianism
12 * @since 2.0.0
13 * @author Takahashi Fumiki
14 */
15 class Login extends AbstractController {
16
17 /**
18 * Hook name
19 *
20 * @deprecated 3.0.4
21 */
22 const LOGIN_FORM_ACTION = 'gianism_login_form';
23
24 /**
25 * Hook name
26 *
27 * @deprecated 3.0.4
28 */
29 const BEFORE_LOGIN_FORM = 'gianism_before_login_form';
30
31 /**
32 * Hook name
33 * @deprecated 3.0.4
34 */
35 const AFTER_LOGIN_FORM = 'gianism_after_login_form';
36
37 /**
38 * Constructor
39 *
40 * @param array $argument
41 */
42 protected function __construct( array $argument = [] ) {
43 parent::__construct( $argument );
44
45 if ( $this->option->is_enabled() ) {
46 // Only for account holder
47 if ( $this->option->show_button_on_login( 'login' ) ) {
48 add_action( 'login_form', array( $this, 'login_form' ) );
49 }
50 // Registration allowed
51 if ( $this->option->show_button_on_login( 'register' ) ) {
52 add_action( 'register_form', array( $this, 'register_form' ) );
53 }
54 // WooCommerce found.
55 if ( gianism_woocommerce_detected() && $this->option->show_button_on_login( 'woocommerce' ) ) {
56 add_action( 'woocommerce_login_form', array( $this, 'woo_form' ) );
57 add_action( 'woocommerce_register_form', array( $this, 'woo_form' ) );
58 add_action( 'woocommerce_after_checkout_shipping_form', array( $this, 'woo_form' ) );
59 add_action( 'woocommerce_lostpassword_form', array( $this, 'woo_form' ) );
60 add_action( 'woocommerce_resetpassword_form', array( $this, 'woo_form' ) );
61 }
62 }
63 }
64
65 /**
66 * Show Login Form
67 *
68 * @param string $before Default '<div id="wpg-login">'.
69 * @param string $after Default '</div>'.
70 * @param bool $register Is register form.
71 * @param string $redirect_to Redirect URL. Default empty string.
72 * @param string $context Context of this form.
73 *
74 * @return void
75 */
76 public function login_form( $before = '', $after = '', $register = false, $redirect_to = '', $context = '' ) {
77 if ( empty( $before ) ) {
78 $class_name = [ 'public-style' ];
79 if ( $register ) {
80 $class_name[] = 'register';
81 }
82 $class_attr = sprintf( ' class="%s"', esc_attr( implode( ' ', $class_name ) ) );
83 $before = sprintf( '<div id="wpg-login"%s>', $class_attr );
84 }
85 if ( empty( $after ) ) {
86 $after = '</div>';
87 }
88 if ( '' === $redirect_to ) {
89 $redirect_query = $this->input->get( 'redirect_to' );
90 if ( $redirect_query ) {
91 $redirect_to = $redirect_query;
92 }
93 }
94 echo wp_kses_post( $before );
95 /**
96 * gianism_before_login_form
97 *
98 * @package Gianism
99 * @since 3.0.4 Add context param.
100 * @param bool $register Is register form
101 * @param string $context Context of this button action.
102 */
103 do_action( 'gianism_before_login_form', $register, $context );
104 /**
105 * gianism_login_form
106 *
107 * Display login buttons.
108 *
109 * @package Gianism
110 * @since 3.0.4 Add context param.
111 * @param bool $register Is register form
112 * @param string $redirect_to Redirect URL after login
113 * @param string $context Context of this button action.
114 */
115 do_action( 'gianism_login_form', $register, $redirect_to, $context );
116 /**
117 * gianism_after_login_form
118 *
119 * @package Gianism
120 * @since 3.0.4 Add context param.
121 * @param bool $register Is register form
122 * @param string $context Context of this button action.
123 */
124 do_action( 'gianism_after_login_form', $register, $context );
125 echo wp_kses_post( $after );
126 }
127
128 /**
129 * Show buttons on register form.
130 *
131 * @return void
132 */
133 public function register_form() {
134 $this->login_form( '', '', true );
135 }
136
137 /**
138 * Show button on WooCommerce login form
139 *
140 * @since 3.0.4
141 */
142 public function woo_form() {
143 if ( is_checkout() ) {
144 $redirect = wc_get_checkout_url();
145 } else {
146 $redirect = wc_get_page_permalink( 'myaccount' );
147 }
148 $this->login_form( '', '', false, $redirect, 'woo-account' );
149 }
150 }
151