PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.8.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.8.1
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
ablocks / includes / blocks / academy-password-reset-form / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.8.1, at includes/blocks/academy-password-reset-form/block.php

192 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\AcademyPasswordResetForm;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGeneratorV2;
10 use ABlocks\Helper;
11 use ABlocks\Controls\Typography;
12 use ABlocks\Controls\Background;
13 use ABlocks\Controls\Border;
14 use ABlocks\Controls\Dimensions;
15 use ABlocks\Controls\Color;
16
17 class Block extends BlockBaseAbstract {
18 protected $block_name = 'academy-password-reset-form';
19
20 public function __construct() {
21 parent::__construct();
22
23 add_filter( 'academy/shortcode/password_reset_form_is_user_logged_in', [ $this, 'force_showing_reset_form_in_editor' ] );
24
25 }
26
27 public function force_showing_reset_form_in_editor( $flag ) {
28 if ( Helper::is_gutenberg_editor() ) {
29 return false;
30 }
31 return $flag;
32 }
33
34 public function build_css( $attributes ) {
35 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
36
37 $css_generator->add_class_styles(
38 '{{WRAPPER}} .academy-password-reset-form-wrapper',
39 $this->getResetFormCss( $attributes ),
40 $this->getResetFormCss( $attributes, 'Tablet' ),
41 $this->getResetFormCss( $attributes, 'Mobile' )
42 );
43 $css_generator->add_class_styles(
44 '{{WRAPPER}} .academy-password-reset-form-wrapper:hover',
45 $this->getResetFormHoverCss( $attributes ),
46 $this->getResetFormHoverCss( $attributes, 'Tablet' ),
47 $this->getResetFormHoverCss( $attributes, 'Mobile' )
48 );
49
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .academy-password-reset-form-wrapper .academy-password-reset-form .academy-form-group label',
52 $this->getResetFormLabelCss( $attributes ),
53 $this->getResetFormLabelCss( $attributes, 'Tablet' ),
54 $this->getResetFormLabelCss( $attributes, 'Mobile' )
55 );
56
57 $css_generator->add_class_styles(
58 '{{WRAPPER}} .academy-password-reset-form-wrapper .academy-password-reset-form .academy-form-group input',
59 $this->getResetFormInputCss( $attributes ),
60 $this->getResetFormInputCss( $attributes, 'Tablet' ),
61 $this->getResetFormInputCss( $attributes, 'Mobile' )
62 );
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .academy-password-reset-form-wrapper .academy-password-reset-form .academy-form-group input:hover',
65 $this->getResetFormInputHoverCss( $attributes ),
66 $this->getResetFormInputHoverCss( $attributes, 'Tablet' ),
67 $this->getResetFormInputHoverCss( $attributes, 'Mobile' )
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .academy-password-reset-form-wrapper .academy-password-reset-form .academy-form-group button',
71 $this->getResetFormButtonCss( $attributes ),
72 $this->getResetFormButtonCss( $attributes, 'Tablet' ),
73 $this->getResetFormButtonCss( $attributes, 'Mobile' )
74 );
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .academy-password-reset-form-wrapper .academy-password-reset-form .academy-form-group button:hover',
77 $this->getResetFormButtonHoverCss( $attributes ),
78 $this->getResetFormButtonHoverCss( $attributes, 'Tablet' ),
79 $this->getResetFormButtonHoverCss( $attributes, 'Mobile' )
80 );
81 $css_generator->add_class_styles(
82 '{{WRAPPER}} .academy-password-reset-form-wrapper h2.academy-password-reset-form-heading',
83 $this->getResetFormHeaderCss( $attributes ),
84 $this->getResetFormHeaderCss( $attributes, 'Tablet' ),
85 $this->getResetFormHeaderCss( $attributes, 'Mobile' )
86 );
87
88 $css_generator->add_class_styles(
89 '{{WRAPPER}} .academy-password-reset-form-wrapper .academy-password-reset-form-info a',
90 $this->getResetFormFooterCss( $attributes ),
91 $this->getResetFormFooterCss( $attributes, 'Tablet' ),
92 $this->getResetFormFooterCss( $attributes, 'Mobile' )
93 );
94
95 return $css_generator->generate_css();
96 }
97
98 public function getResetFormCss( $attributes, $device = '' ) {
99 $form_border_css = ! empty( $attributes['form_border'] ) ? Border::get_css( $attributes['form_border'], '', $device ) : array();
100 $form_padding_css = ! empty( $attributes['form_padding'] ) ? Dimensions::get_css( $attributes['form_padding'], 'padding', $device ) : array();
101 return array_merge(
102 [ 'background' => Color::get_css( isset( $attributes['form_background_color'] ) ? $attributes['form_background_color'] : '' ) ],
103 $form_border_css,
104 $form_padding_css,
105 );
106 }
107 public function getResetFormHoverCss( $attributes, $device = '' ) {
108 $form_border_hover_css = ! empty( $attributes['form_border'] ) ? Border::get_hover_css( $attributes['form_border'], '', $device ) : array();
109 return array_merge(
110 [ 'background' => Color::get_css( isset( $attributes['form_background_hover_color'] ) ? $attributes['form_background_hover_color'] : '' ) ],
111 $form_border_hover_css
112 );
113 }
114 public function getResetFormLabelCss( $attributes, $device = '' ) {
115 $typographyValueGlobal = ! empty( $attributes['label_typographyGlobal'] ) ? $attributes['label_typographyGlobal'] : '';
116 $reset_form_label_typography_css = isset( $attributes['label_typography'] ) ? $attributes['label_typography'] : [];
117 return array_merge(
118 [ 'color' => Color::get_css( isset( $attributes['label_color'] ) ? $attributes['label_color'] : '' ) ],
119 Typography::get_css( $reset_form_label_typography_css, '', $device, $typographyValueGlobal ),
120 );
121 }
122 public function getResetFormInputCss( $attributes, $device = '' ) {
123 $form_input_border_css = ! empty( $attributes['input_border'] ) ? Border::get_css( $attributes['input_border'], '', $device ) : array();
124 $form_input_padding_css = ! empty( $attributes['input_padding'] ) ? Dimensions::get_css( $attributes['input_padding'], 'padding', $device ) : array();
125 $typographyValueGlobal = ! empty( $attributes['input_field_typographyGlobal'] ) ? $attributes['input_field_typographyGlobal'] : '';
126 $form_input_typography_css = isset( $attributes['input_field_typography'] ) ? $attributes['input_field_typography'] : [];
127 return array_merge(
128 [ 'color' => Color::get_css( isset( $attributes['input_field_color'] ) ? $attributes['input_field_color'] : '' ) ],
129 $form_input_border_css,
130 $form_input_padding_css,
131 Typography::get_css( $form_input_typography_css, '', $device, $typographyValueGlobal ),
132 );
133 }
134 public function getResetFormInputHoverCss( $attributes, $device = '' ) {
135
136 $form_input_border_hover_css = ! empty( $attributes['input_border'] ) ? Border::get_hover_css( $attributes['input_border'], '', $device ) : array();
137 return $form_input_border_hover_css;
138 }
139
140 public function getResetFormButtonCss( $attributes, $device = '' ) {
141 $button_border = ! empty( $attributes['button_border'] ) ? Border::get_css( $attributes['button_border'], '', $device ) : array();
142 $button_padding = ! empty( $attributes['button_padding'] ) ? Dimensions::get_css( $attributes['button_padding'], 'padding', $device ) : array();
143 $typographyValueGlobal = ! empty( $attributes['button_typographyGlobal'] ) ? $attributes['button_typographyGlobal'] : '';
144 $button_typography = isset( $attributes['button_typography'] ) ? $attributes['button_typography'] : [];
145 return array_merge(
146 [ 'color' => Color::get_css( isset( $attributes['button_color'] ) ? $attributes['button_color'] : '' ) ],
147 [ 'background' => Color::get_css( isset( $attributes['button_background_color'] ) ? $attributes['button_background_color'] : '' ) ],
148 $button_border,
149 $button_padding,
150 Typography::get_css( $button_typography, '', $device, $typographyValueGlobal ), $button_typography,
151 );
152 }
153 public function getResetFormButtonHoverCss( $attributes, $device = '' ) {
154 $button_hover_border = ! empty( $attributes['button_border'] ) ? Border::get_hover_css( $attributes['button_border'], '', $device ) : array();
155 return array_merge(
156 [ 'color' => Color::get_css( isset( $attributes['button_hover_color'] ) ? $attributes['button_hover_color'] : '' ) ],
157 [ 'background' => Color::get_css( isset( $attributes['button_background_hover_color'] ) ? $attributes['button_background_hover_color'] : '' ) ],
158 $button_hover_border,
159 );
160 }
161 public function getResetFormHeaderCss( $attributes, $device = '' ) {
162 $typographyValueGlobal = ! empty( $attributes['form_title_typographyGlobal'] ) ? $attributes['form_title_typographyGlobal'] : '';
163 $form_title_typography = isset( $attributes['form_title_typography'] ) ? $attributes['form_title_typography'] : [];
164 return array_merge(
165 [ 'color' => Color::get_css( isset( $attributes['form_title_color'] ) ? $attributes['form_title_color'] : '' ) ],
166 Typography::get_css( $form_title_typography, '', $device, $typographyValueGlobal ),
167 );
168 }
169 public function getResetFormFooterCss( $attributes, $device = '' ) {
170 $typographyValueGlobal = ! empty( $attributes['form_footer_title_typographyGlobal'] ) ? $attributes['form_footer_title_typographyGlobal'] : '';
171 $form_footer_title_typography = isset( $attributes['form_footer_title_typography'] ) ? $attributes['form_footer_title_typography'] : [];
172 return array_merge(
173 [ 'color' => Color::get_css( isset( $attributes['form_footer_title_color'] ) ? $attributes['form_footer_title_color'] : '' ) ],
174 Typography::get_css( $form_footer_title_typography, '', $device, $typographyValueGlobal ),
175 );
176 }
177
178 public function render_block_content( $attributes, $content, $block_instance ) {
179 $attr_array = [
180 'form_title' => sanitize_text_field( Helper::get_attribute_value( $attributes, 'form_title' ) ),
181 'username_label' => sanitize_text_field( Helper::get_attribute_value( $attributes, 'username_label' ) ),
182 'reset_button_label' => sanitize_text_field( Helper::get_attribute_value( $attributes, 'reset_button_label' ) ),
183 'login_button_label' => sanitize_text_field( Helper::get_attribute_value( $attributes, 'login_button_label' ) ),
184 'show_logged_in_message' => filter_var( Helper::get_attribute_value( $attributes, 'show_logged_in_message' ), FILTER_VALIDATE_BOOLEAN ),
185 ];
186
187 $shortcode = '[academy_password_reset_form ' . Helper::attr_shortcode( $attr_array ) . ']';
188 echo do_shortcode( $shortcode );
189 }
190
191 }
192