← All changes
|
features/content-restriction/class-elementor-content-restriction.php
+17
-10
3.16.1
→
4.0.3
View file →
| @@ -226,17 +226,22 @@ | ||
| 226 | 226 | // Verifies if element is hidden |
| 227 | 227 | public function is_hidden( $element ) { |
| 228 | 228 | $settings = $element->get_settings(); |
| 229 | 229 | |
| 230 | - if( is_user_logged_in() && $settings['wppb_restriction_loggedout_users'] === 'yes' ) { | |
| 230 | + // Our controls are not present on every element that goes through these filters, so don't assume the settings exist | |
| 231 | + $restrict_loggedin_users = isset( $settings['wppb_restriction_loggedin_users'] ) ? $settings['wppb_restriction_loggedin_users'] : ''; | |
| 232 | + $restrict_loggedout_users = isset( $settings['wppb_restriction_loggedout_users'] ) ? $settings['wppb_restriction_loggedout_users'] : ''; | |
| 233 | + $restrict_user_roles = isset( $settings['wppb_restriction_user_roles'] ) ? array_filter( (array)$settings['wppb_restriction_user_roles'] ) : array(); | |
| 234 | + | |
| 235 | + if( is_user_logged_in() && $restrict_loggedout_users === 'yes' ) { | |
| 231 | 236 | return true; |
| 232 | 237 | } |
| 233 | 238 | |
| 234 | - if( !empty( $settings['wppb_restriction_user_roles'] ) && is_user_logged_in() ) { | |
| 239 | + if( !empty( $restrict_user_roles ) && is_user_logged_in() ) { | |
| 235 | 240 | |
| 236 | 241 | $user_data = get_userdata( get_current_user_id() ); |
| 237 | 242 | |
| 238 | - foreach( $settings['wppb_restriction_user_roles'] as $restriction_role ) { | |
| 243 | + foreach( $restrict_user_roles as $restriction_role ) { | |
| 239 | 244 | foreach( $user_data->roles as $user_role ) { |
| 240 | 245 | if( $user_role == $restriction_role ) { |
| 241 | 246 | return false; |
| 242 | 247 | } |
| @@ -244,9 +249,9 @@ | ||
| 244 | 249 | } |
| 245 | 250 | |
| 246 | 251 | return true; |
| 247 | 252 | } else if ( !is_user_logged_in() && ( |
| 248 | - ( $settings['wppb_restriction_loggedin_users'] == 'yes' ) || ( !empty( $settings['wppb_restriction_user_roles'] ) ) | |
| 253 | + ( $restrict_loggedin_users == 'yes' ) || ( !empty( $restrict_user_roles ) ) | |
| 249 | 254 | ) ) { |
| 250 | 255 | |
| 251 | 256 | return true; |
| 252 | 257 | } |
| @@ -257,17 +262,19 @@ | ||
| 257 | 262 | // Retrieves custom element message or the default message from PB settings |
| 258 | 263 | private function get_custom_message( $element ) { |
| 259 | 264 | $settings = $element->get_settings(); |
| 260 | 265 | |
| 261 | - if( $settings['wppb_restriction_default_messages'] != 'yes' ) | |
| 266 | + if( !isset( $settings['wppb_restriction_default_messages'] ) || $settings['wppb_restriction_default_messages'] != 'yes' ) | |
| 262 | 267 | return false; |
| 263 | 268 | |
| 264 | - if( $settings['wppb_restriction_custom_messages'] == 'yes' ) { | |
| 269 | + if( isset( $settings['wppb_restriction_custom_messages'] ) && $settings['wppb_restriction_custom_messages'] == 'yes' ) { | |
| 265 | 270 | |
| 266 | - if( $settings['wppb_restriction_custom_messages_type'] == 'text' ) | |
| 267 | - return $settings['wppb_restriction_fallback_text']; | |
| 268 | - elseif( $settings['wppb_restriction_custom_messages_type'] == 'template' ) { | |
| 269 | - return $this->render_template( $settings['wppb_restriction_fallback_template'] ); | |
| 271 | + $custom_message_type = isset( $settings['wppb_restriction_custom_messages_type'] ) ? $settings['wppb_restriction_custom_messages_type'] : ''; | |
| 272 | + | |
| 273 | + if( $custom_message_type == 'text' ) | |
| 274 | + return isset( $settings['wppb_restriction_fallback_text'] ) ? $settings['wppb_restriction_fallback_text'] : ''; | |
| 275 | + elseif( $custom_message_type == 'template' ) { | |
| 276 | + return isset( $settings['wppb_restriction_fallback_template'] ) ? $this->render_template( $settings['wppb_restriction_fallback_template'] ) : ''; | |
| 270 | 277 | } |
| 271 | 278 | } else { |
| 272 | 279 | if( is_user_logged_in() ) |
| 273 | 280 | return wppb_content_restriction_process_content_message( 'logged_in', get_current_user_id() ); |