| @@ -1349,8 +1349,26 @@ | ||
| 1349 | 1349 | ); |
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | 1352 | /** |
| 1353 | + * Get Responsive Control Device Suffix | |
| 1354 | + * | |
| 1355 | + * @param array $control | |
| 1356 | + * @return string $device suffix | |
| 1357 | + */ | |
| 1358 | + protected function get_responsive_control_device_suffix( $control ) { | |
| 1359 | + if ( ! empty( $control['responsive']['max'] ) ) { | |
| 1360 | + $query_device = $control['responsive']['max']; | |
| 1361 | + } elseif ( ! empty( $control['responsive']['min'] ) ) { | |
| 1362 | + $query_device = $control['responsive']['min']; | |
| 1363 | + } else { | |
| 1364 | + return ''; | |
| 1365 | + } | |
| 1366 | + | |
| 1367 | + return 'desktop' === $query_device ? '' : '_' . $query_device; | |
| 1368 | + } | |
| 1369 | + | |
| 1370 | + /** | |
| 1353 | 1371 | * Whether the control is visible or not. |
| 1354 | 1372 | * |
| 1355 | 1373 | * Used to determine whether the control is visible or not. |
| 1356 | 1374 | * |
| @@ -1374,8 +1392,10 @@ | ||
| 1374 | 1392 | if ( empty( $control['condition'] ) ) { |
| 1375 | 1393 | return true; |
| 1376 | 1394 | } |
| 1377 | 1395 | |
| 1396 | + $controls = $this->get_controls(); | |
| 1397 | + | |
| 1378 | 1398 | foreach ( $control['condition'] as $condition_key => $condition_value ) { |
| 1379 | 1399 | preg_match( '/([a-z_\-0-9]+)(?:\[([a-z_]+)])?(!?)$/i', $condition_key, $condition_key_parts ); |
| 1380 | 1400 | |
| 1381 | 1401 | $pure_condition_key = $condition_key_parts[1]; |
| @@ -1385,13 +1405,24 @@ | ||
| 1385 | 1405 | if ( ! isset( $values[ $pure_condition_key ] ) || null === $values[ $pure_condition_key ] ) { |
| 1386 | 1406 | return false; |
| 1387 | 1407 | } |
| 1388 | 1408 | |
| 1389 | - $instance_value = $values[ $pure_condition_key ]; | |
| 1409 | + $are_control_and_condition_responsive = isset( $control['responsive'] ) && ! empty( $controls[ $pure_condition_key ]['responsive'] ); | |
| 1410 | + $condition_name_to_check = $pure_condition_key; | |
| 1390 | 1411 | |
| 1412 | + if ( $are_control_and_condition_responsive ) { | |
| 1413 | + $device_suffix = $this->get_responsive_control_device_suffix( $control ); | |
| 1414 | + | |
| 1415 | + $condition_name_to_check = $pure_condition_key . $device_suffix; | |
| 1416 | + | |
| 1417 | + // If the control is not desktop, take the value of the conditioning control of the corresponding device. | |
| 1418 | + $instance_value = $values[ $pure_condition_key . $device_suffix ]; | |
| 1419 | + } else { | |
| 1420 | + $instance_value = $values[ $pure_condition_key ]; | |
| 1421 | + } | |
| 1422 | + | |
| 1391 | 1423 | if ( ! $instance_value ) { |
| 1392 | - $controls = $this->get_controls(); | |
| 1393 | - $parent = isset( $controls[ $pure_condition_key ]['parent'] ) ? $controls[ $pure_condition_key ]['parent'] : false; | |
| 1424 | + $parent = isset( $controls[ $condition_name_to_check ]['parent'] ) ? $controls[ $condition_name_to_check ]['parent'] : false; | |
| 1394 | 1425 | |
| 1395 | 1426 | while ( $parent ) { |
| 1396 | 1427 | $instance_value = $values[ $parent ]; |
| 1397 | 1428 | |