PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
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
← All changes | includes/blocks/logout/block.php +39 -67 2.9.1 → 2.14.0 View file →
@@ -5,9 +5,9 @@
5 5 exit;
6 6 }
7 7
8 8 use ABlocks\Classes\BlockBaseAbstract;
9 -use ABlocks\Classes\CssGenerator;
9 +use ABlocks\Classes\CssGeneratorV2;
10 10 use ABlocks\Controls\Alignment;
11 11 use ABlocks\Controls\Range;
12 12 use ABlocks\Controls\Border;
13 13 use ABlocks\Controls\Typography;
@@ -12,8 +12,9 @@
12 12 use ABlocks\Controls\Border;
13 13 use ABlocks\Controls\Typography;
14 14 use ABlocks\Controls\TextShadow;
15 15 use ABlocks\Controls\TextStroke;
16 +use ABlocks\Controls\Color;
16 17
17 18
18 19 class Block extends BlockBaseAbstract {
19 20 protected $block_name = 'logout';
@@ -18,12 +19,10 @@
18 19 class Block extends BlockBaseAbstract {
19 20 protected $block_name = 'logout';
20 21
21 22 public function build_css( $attributes ) {
23 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
22 24
23 - // Generate CSS start
24 - $css_generator = new CssGenerator( $attributes, $this->block_name );
25 -
26 25 $css_generator->add_class_styles(
27 26 '{{WRAPPER}} .ablocks-block-logout__label',
28 27 $this->get_log_out_label_color( $attributes )
29 28 );
@@ -31,13 +30,14 @@
31 30 $css_generator->add_class_styles(
32 31 '{{WRAPPER}} .ablocks-block-logout',
33 32 $this->get_log_out_css( $attributes ),
34 33 $this->get_log_out_css( $attributes, 'Tablet' ),
35 - $this->get_log_out_css( $attributes, 'Mobile' )
34 + $this->get_log_out_css( $attributes, 'Mobile' ),
35 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_log_out_css( $attributes, $device ); } )
36 36 );
37 37 $css_generator->add_class_styles(
38 38 '{{WRAPPER}} .ablocks-block-logout__name',
39 - $this->get_name_css( $attributes ),
39 + $this->get_name_css( $attributes )
40 40 );
41 41
42 42 $css_generator->add_class_styles(
43 43 '{{WRAPPER}} .ablocks-block-logout__avatar',
@@ -42,48 +42,38 @@
42 42 $css_generator->add_class_styles(
43 43 '{{WRAPPER}} .ablocks-block-logout__avatar',
44 44 $this->get_avatar_css( $attributes ),
45 45 $this->get_avatar_css( $attributes, 'Tablet' ),
46 - $this->get_avatar_css( $attributes, 'Mobile' )
46 + $this->get_avatar_css( $attributes, 'Mobile' ),
47 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_avatar_css( $attributes, $device ); } )
47 48 );
48 49 $css_generator->add_class_styles(
49 50 '{{WRAPPER}} .ablocks-block-logout__avatar:hover',
50 51 $this->get_avatar_border_hover_css( $attributes ),
51 52 $this->get_avatar_border_hover_css( $attributes, 'Tablet' ),
52 - $this->get_avatar_border_hover_css( $attributes, 'Mobile' )
53 + $this->get_avatar_border_hover_css( $attributes, 'Mobile' ),
54 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_avatar_border_hover_css( $attributes, $device ); } )
53 55 );
54 56
55 57 return $css_generator->generate_css();
56 58 }
57 59
58 -
59 60 public function get_log_out_label_color( $attributes, $device = '' ) {
60 - $log_out_label_color_css = [];
61 - if ( ! empty( $attributes['logOutLabelColor'] ) ) {
62 - $log_out_label_color_css['color'] = $attributes['logOutLabelColor'];
63 - }
64 - if ( ! empty( $attributes['logOutLabelBgColor'] ) ) {
65 - $log_out_label_color_css['background'] = $attributes['logOutLabelBgColor'];
66 - }
67 -
68 61 $typography = isset( $attributes['labelTypography'] ) ? $attributes['labelTypography'] : '';
69 62 $text_stroke = isset( $attributes['labelTextStroke'] ) ? $attributes['labelTextStroke'] : '';
70 63 $text_shadow = isset( $attributes['labelTextShadow'] ) ? $attributes['labelTextShadow'] : '';
71 -
64 + $typographyglobal = ! empty( $attributes['labelTypographyGlobal'] ) ? $attributes['labelTypographyGlobal'] : array();
72 65 return array_merge(
73 - Typography::get_css( $typography, '', $device ),
66 + [ 'color' => Color::get_css( isset( $attributes['logOutLabelColor'] ) ? $attributes['logOutLabelColor'] : '' ) ],
67 + [ 'background' => Color::get_css( isset( $attributes['logOutLabelBgColor'] ) ? $attributes['logOutLabelBgColor'] : '' ) ],
68 + Typography::get_css( $typography, '', $device, $typographyglobal ),
74 69 TextStroke::get_css( $text_stroke, '', $device ),
75 70 TextShadow::get_css( $text_shadow, '', $device ),
76 - $log_out_label_color_css
77 71 );
78 72 }
79 73
80 74 public function get_log_out_css( $attributes, $device = '' ) {
81 75 $log_out_css = [];
82 -
83 - if ( ! empty( $attributes['logOutLabelBgColor'] ) ) {
84 - $log_out_css ['background'] = $attributes['logOutLabelBgColor'];
85 - }
86 76 if ( ! empty( $attributes['direction'][ 'value' . $device ] ) ) {
87 77 $log_out_css['flex-direction'] = $attributes['direction'][ 'value' . $device ];
88 78 }
89 79
@@ -90,30 +80,17 @@
90 80 if ( isset( $attributes['labelAlignment'][ 'value' . $device ] ) ) {
91 81 $log_out_css['justify-content'] = $attributes['labelAlignment'][ 'value' . $device ];
92 82 }
93 83
94 - return $log_out_css;
84 + return array_merge(
85 + [ 'background' => Color::get_css( isset( $attributes['logOutLabelBgColor'] ) ? $attributes['logOutLabelBgColor'] : '' ) ],
86 + $log_out_css
87 + );
95 88 }
96 89
97 90
98 91 public function get_avatar_css( $attributes, $device = '' ) {
99 - $avatar_css = [];
100 92
101 - if ( ! empty( $attributes['avatarWidth'][ 'value' . $device ] ) ) {
102 - $width_value = $attributes['avatarWidth'][ 'value' . $device ];
103 - $width_unit = $attributes['avatarWidth'][ 'valueUnit' . $device ] ?? 'px';
104 - $avatar_css['width'] = $width_value . $width_unit;
105 - }
106 -
107 - if ( ! empty( $attributes['avatarHeight'][ 'value' . $device ] ) ) {
108 - $height_value = $attributes['avatarHeight'][ 'value' . $device ];
109 - $height_unit = ! empty( $attributes['avatarHeight'][ 'valueUnit' . $device ] )
110 - ? $attributes['avatarHeight'][ 'valueUnit' . $device ]
111 - : 'px';
112 -
113 - $avatar_css['height'] = $height_value . $height_unit;
114 - }
115 -
116 93 return array_merge(
117 94 Range::get_css([
118 95 'attributeValue' => $attributes['avatarWidth'],
119 96 'attribute_object_key' => 'value',
@@ -134,9 +111,8 @@
134 111 'property' => 'height',
135 112 'device' => $device,
136 113 ]),
137 114 isset( $attributes['avatarBorder'] ) ? Border::get_css( $attributes['avatarBorder'], '', $device ) : [],
138 - $avatar_css,
139 115 );
140 116 }
141 117
142 118 public function get_avatar_border_hover_css( $attributes, $device = '' ) {
@@ -145,32 +121,26 @@
145 121 );
146 122 }
147 123
148 124 public function get_name_css( $attributes, $device = '' ) {
149 - $name_css = [];
150 -
151 - if ( ! empty( $attributes['nameColor'] ) ) {
152 - $name_css ['color'] = $attributes['nameColor'];
153 - }
154 125 $typography = isset( $attributes['nameTypography'] ) ? $attributes['nameTypography'] : '';
155 126 $text_stroke = isset( $attributes['nameTextStroke'] ) ? $attributes['nameTextStroke'] : '';
156 127 $text_shadow = isset( $attributes['nameTextShadow'] ) ? $attributes['nameTextShadow'] : '';
157 -
128 + $typographyglobal = ! empty( $attributes['nameTypographyGlobal'] ) ? $attributes['nameTypographyGlobal'] : array();
158 129 return array_merge(
159 - Typography::get_css( $typography, '', $device ),
130 + [ 'color' => Color::get_css( isset( $attributes['nameColor'] ) ? $attributes['nameColor'] : '' ) ],
131 + Typography::get_css( $typography, '', $device, $typographyglobal ),
160 132 TextStroke::get_css( $text_stroke, '', $device ),
161 - TextShadow::get_css( $text_shadow, '', $device ),
162 - $name_css
133 + TextShadow::get_css( $text_shadow, '', $device )
163 134 );
164 135 }
165 136
166 -
167 -
168 137 public function render_block_content( $attributes, $content, $block_instance ) {
169 138 $logout_redirect_option = isset( $attributes['logoutRedirect'] ) ? $attributes['logoutRedirect'] : 'current-url';
170 139
171 140 if ( $logout_redirect_option === 'current-url' ) {
172 - $logout_redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
141 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
142 + $logout_redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( $_SERVER['HTTP_HOST'] ) . sanitize_text_field( $_SERVER['REQUEST_URI'] );
173 143 } elseif ( $logout_redirect_option === 'custom-url' ) {
174 144 $logout_redirect_url = isset( $attributes['logoutCustomUrl'] ) && ! empty( $attributes['logoutCustomUrl'] )
175 145 ? esc_url( $attributes['logoutCustomUrl'] )
176 146 : home_url();
@@ -178,9 +148,10 @@
178 148
179 149 $login_redirect_option = isset( $attributes['loginRedirect'] ) ? $attributes['loginRedirect'] : 'current-url';
180 150
181 151 if ( $login_redirect_option === 'current-url' ) {
182 - $login_redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
152 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
153 + $login_redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( $_SERVER['HTTP_HOST'] ) . sanitize_text_field( $_SERVER['REQUEST_URI'] );
183 154 } elseif ( $login_redirect_option === 'custom-url' ) {
184 155 $login_redirect_url = isset( $attributes['loginCustomUrl'] ) && ! empty( $attributes['loginCustomUrl'] )
185 156 ? esc_url( $attributes['loginCustomUrl'] )
186 157 : home_url();
@@ -186,45 +157,46 @@
186 157 : home_url();
187 158 }
188 159
189 160 $current_user = wp_get_current_user();
190 - $profile_picture = get_avatar_url( $current_user->ID );
191 - $display_name = $current_user->display_name;
161 + $profile_picture = esc_url( get_avatar_url( $current_user->ID ) );
162 + $display_name = sanitize_text_field( $current_user->display_name );
192 163
193 164 $button_icon_url = isset( $attributes['buttonIconUrl'] ) && ! empty( $attributes['buttonIconUrl'] )
194 165 ? esc_url( $attributes['buttonIconUrl'] )
195 166 : '';
196 167
197 - $button_class = isset( $attributes['buttonClass'] ) ? esc_attr( $attributes['buttonClass'] ) : 'ablocks-block-logout__label';
168 + $button_class = isset( $attributes['buttonClass'] ) ? sanitize_html_class( $attributes['buttonClass'] ) : 'ablocks-block-logout__label';
198 169 $is_logged_in = is_user_logged_in();
199 170 $is_show_avatar = isset( $attributes['isShowAvatar'] ) && $attributes['isShowAvatar'];
200 171 $is_show_name = isset( $attributes['isShowName'] ) && $attributes['isShowName'];
201 172
202 173 $button_text = $is_logged_in
203 - ? ( isset( $attributes['logOutLabel'] ) ? esc_html( $attributes['logOutLabel'] ) : __( '(Log Out)', 'ablocks' ) )
204 - : ( isset( $attributes['logInLabel'] ) ? esc_html( $attributes['logInLabel'] ) : __( '(Log In)', 'ablocks' ) );
174 + ? ( isset( $attributes['logOutLabel'] ) ? sanitize_text_field( $attributes['logOutLabel'] ) : __( '(Log Out)', 'ablocks' ) )
175 + : ( isset( $attributes['logInLabel'] ) ? sanitize_text_field( $attributes['logInLabel'] ) : __( '(Log In)', 'ablocks' ) );
205 176
206 177 $action_url = $is_logged_in ? wp_logout_url( $logout_redirect_url ) : wp_login_url( $login_redirect_url );
207 178
208 179 ob_start();
209 180 ?>
210 - <div class="ablocks-block-logout">
181 + <div class="ablocks-block-logout">
211 182 <?php if ( $is_logged_in && $is_show_avatar ) : ?>
212 - <img
213 - src="<?php echo esc_url( $profile_picture ); ?>"
214 - alt="<?php echo esc_attr( $display_name ); ?>"
215 - class="ablocks-block-logout__avatar"
183 + <img
184 + src="<?php echo esc_url( $profile_picture ); ?>"
185 + alt="<?php echo esc_attr( $display_name ); ?>"
186 + class="ablocks-block-logout__avatar"
216 187 />
217 188 <?php endif; ?>
218 189 <?php if ( $is_logged_in && $is_show_name ) : ?>
219 190 <span class="ablocks-block-logout__name"><?php echo esc_html( $display_name ); ?></span>
220 - <?php endif; ?>
191 + <?php endif; ?>
221 192 <a href="<?php echo esc_url( $action_url ); ?>" class="<?php echo esc_attr( $button_class ); ?>">
222 193 (<span><?php echo esc_html( $button_text ); ?></span>)
223 194 </a>
224 - </div>
195 + </div>
225 196 <?php
226 197
227 198 return ob_get_clean();
228 199 }
200 +
229 201
230 202 }