sections
5 days ago
class-conditions-manager.php
5 days ago
class-render-handler.php
5 days ago
class-section-base.php
5 days ago
class-section-base.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Abstract base class for all visibility condition sections. |
| 9 | * Each collapsible section in the Visibility tab extends this class. |
| 10 | */ |
| 11 | abstract class WPR_DC_Section_Base { |
| 12 | |
| 13 | /** |
| 14 | * Unique section ID (e.g. 'wpr_dc_visitor_roles'). |
| 15 | */ |
| 16 | abstract public function get_id(); |
| 17 | |
| 18 | /** |
| 19 | * Section label shown in the Elementor panel. |
| 20 | */ |
| 21 | abstract public function get_label(); |
| 22 | |
| 23 | /** |
| 24 | * Sort order in the tab (10, 20, 30...). |
| 25 | */ |
| 26 | abstract public function get_order(); |
| 27 | |
| 28 | /** |
| 29 | * Register Elementor controls for this section. |
| 30 | */ |
| 31 | abstract public function register_controls( $element ); |
| 32 | |
| 33 | /** |
| 34 | * Evaluate conditions for this section. |
| 35 | * |
| 36 | * @return bool|null true = conditions met, false = not met, null = not configured (skip) |
| 37 | */ |
| 38 | abstract public function evaluate( $settings ); |
| 39 | |
| 40 | /** |
| 41 | * Whether this section is available (e.g. required plugin is active). |
| 42 | */ |
| 43 | public function is_available() { |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Compare two values using the given operator. |
| 49 | */ |
| 50 | protected function compare( $actual, $operator, $expected ) { |
| 51 | switch ( $operator ) { |
| 52 | case 'isset': |
| 53 | return '' !== $actual && null !== $actual && false !== $actual; |
| 54 | case 'empty': |
| 55 | return '' === $actual || null === $actual || false === $actual; |
| 56 | case 'equals': |
| 57 | return (string) $actual === (string) $expected; |
| 58 | case 'not_equals': |
| 59 | return (string) $actual !== (string) $expected; |
| 60 | case 'contains': |
| 61 | return false !== strpos( (string) $actual, (string) $expected ); |
| 62 | case 'not_contains': |
| 63 | return false === strpos( (string) $actual, (string) $expected ); |
| 64 | case 'starts_with': |
| 65 | return 0 === strpos( (string) $actual, (string) $expected ); |
| 66 | case 'ends_with': |
| 67 | return substr( (string) $actual, -strlen( (string) $expected ) ) === (string) $expected; |
| 68 | case 'less_than': |
| 69 | return (float) $actual < (float) $expected; |
| 70 | case 'greater_than': |
| 71 | return (float) $actual > (float) $expected; |
| 72 | case 'less_equal': |
| 73 | return (float) $actual <= (float) $expected; |
| 74 | case 'greater_equal': |
| 75 | return (float) $actual >= (float) $expected; |
| 76 | default: |
| 77 | return true; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Get comparison operators for select dropdowns. |
| 83 | */ |
| 84 | protected function get_comparison_operators() { |
| 85 | return [ |
| 86 | 'isset' => esc_html__( 'Has any value', 'wpr-addons' ), |
| 87 | 'empty' => esc_html__( 'Is empty', 'wpr-addons' ), |
| 88 | 'equals' => esc_html__( 'Equals', 'wpr-addons' ), |
| 89 | 'not_equals' => esc_html__( 'Does not equal', 'wpr-addons' ), |
| 90 | 'contains' => esc_html__( 'Contains', 'wpr-addons' ), |
| 91 | 'not_contains' => esc_html__( 'Does not contain', 'wpr-addons' ), |
| 92 | 'starts_with' => esc_html__( 'Starts with', 'wpr-addons' ), |
| 93 | 'ends_with' => esc_html__( 'Ends with', 'wpr-addons' ), |
| 94 | 'less_than' => esc_html__( 'Less than', 'wpr-addons' ), |
| 95 | 'greater_than' => esc_html__( 'Greater than', 'wpr-addons' ), |
| 96 | 'less_equal' => esc_html__( 'Less than or equal to', 'wpr-addons' ), |
| 97 | 'greater_equal' => esc_html__( 'Greater than or equal to', 'wpr-addons' ), |
| 98 | ]; |
| 99 | } |
| 100 | } |
| 101 |