This repository has been archived on 2022-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
divi/includes/builder/module/field/display-conditions/Cookie.php
2021-12-07 11:08:05 +00:00

53 lines
1.3 KiB
PHP

<?php
/**
* Cookie condition logic swiftly crafted.
*
* @since 4.11.0
*
* @package Divi
* @sub-package Builder
*/
namespace Module\Field\DisplayConditions;
/**
* Cookie Condition Trait.
*/
trait CookieCondition {
/**
* Processes "Cookie" condition.
*
* @since 4.11.0
*
* @param array $condition_settings Containing all settings of the condition.
*
* @return boolean Condition output.
*/
protected function _process_cookie_condition( $condition_settings ) {
$display_rule = isset( $condition_settings['cookieDisplay'] ) ? $condition_settings['cookieDisplay'] : 'cookieExists';
$cookie_name = isset( $condition_settings['cookieName'] ) ? $condition_settings['cookieName'] : '';
$cookie_value = isset( $condition_settings['cookieValue'] ) ? $condition_settings['cookieValue'] : '';
$is_cookie_set = ( isset( $_COOKIE[ $cookie_name ] ) ) ? true : false;
$is_cookie_value_equals = ( isset( $_COOKIE[ $cookie_name ] ) ) ? $cookie_value === $_COOKIE[ $cookie_name ] : false;
switch ( $display_rule ) {
case 'cookieExists':
return $is_cookie_set;
case 'cookieDoesNotExist':
return ! $is_cookie_set;
case 'cookieValueEquals':
return $is_cookie_value_equals;
case 'cookieValueDoesNotEqual':
return ! $is_cookie_value_equals;
default:
return false;
}
}
}