| 1 |
<?php |
| 2 |
namespace Elementor\Core\Breakpoints; |
| 3 |
|
| 4 |
use Elementor\Core\Base\Base_Object; |
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\Core\Breakpoints\Manager as Breakpoints_Manager; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
class Breakpoint extends Base_Object { |
| 13 |
|
| 14 |
private $name; |
| 15 |
private $label; |
| 16 |
private $default_value; |
| 17 |
private $db_key; |
| 18 |
private $value; |
| 19 |
private $is_custom; |
| 20 |
private $direction = 'max'; |
| 21 |
private $is_enabled = false; |
| 22 |
private $config; |
| 23 |
|
| 24 |
/** |
| 25 |
* Get Name |
| 26 |
* |
| 27 |
* @since 3.2.0 |
| 28 |
* |
| 29 |
* @return string |
| 30 |
*/ |
| 31 |
public function get_name() { |
| 32 |
return $this->name; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Is Enabled |
| 37 |
* |
| 38 |
* Check if the breakpoint is enabled or not. The breakpoint instance receives this data from |
| 39 |
* the Breakpoints Manager. |
| 40 |
* |
| 41 |
* @return bool $is_enabled class variable |
| 42 |
*/ |
| 43 |
public function is_enabled() { |
| 44 |
return $this->is_enabled; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Get Label |
| 49 |
* |
| 50 |
* Retrieve the breakpoint label. |
| 51 |
* |
| 52 |
* @since 3.2.0 |
| 53 |
* |
| 54 |
* @return string $label class variable |
| 55 |
*/ |
| 56 |
public function get_label() { |
| 57 |
return $this->label; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Get Value |
| 62 |
* |
| 63 |
* Retrieve the saved breakpoint value. |
| 64 |
* |
| 65 |
* @since 3.2.0 |
| 66 |
* |
| 67 |
* @return int $value class variable |
| 68 |
*/ |
| 69 |
public function get_value() { |
| 70 |
if ( ! $this->value ) { |
| 71 |
$this->init_value(); |
| 72 |
} |
| 73 |
|
| 74 |
return $this->value; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Is Custom |
| 79 |
* |
| 80 |
* Check if the breakpoint's value is a custom or default value. |
| 81 |
* |
| 82 |
* @since 3.2.0 |
| 83 |
* |
| 84 |
* @return bool $is_custom class variable |
| 85 |
*/ |
| 86 |
public function is_custom() { |
| 87 |
if ( ! $this->is_custom ) { |
| 88 |
$this->get_value(); |
| 89 |
} |
| 90 |
|
| 91 |
return $this->is_custom; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Get Default Value |
| 96 |
* |
| 97 |
* Returns the Breakpoint's default value. |
| 98 |
* |
| 99 |
* @since 3.2.0 |
| 100 |
* |
| 101 |
* @return int $default_value class variable |
| 102 |
*/ |
| 103 |
public function get_default_value() { |
| 104 |
return $this->default_value; |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Get Direction |
| 109 |
* |
| 110 |
* Returns the Breakpoint's direction ('min'/'max'). |
| 111 |
* |
| 112 |
* @since 3.2.0 |
| 113 |
* |
| 114 |
* @return string $direction class variable |
| 115 |
*/ |
| 116 |
public function get_direction() { |
| 117 |
return $this->direction; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Set Value |
| 122 |
* |
| 123 |
* Set the `$value` class variable and the `$is_custom` class variable. |
| 124 |
* |
| 125 |
* @since 3.2.0 |
| 126 |
* |
| 127 |
* @return int $value class variable |
| 128 |
*/ |
| 129 |
private function init_value() { |
| 130 |
$cached_value = Plugin::$instance->kits_manager->get_current_settings( $this->db_key ); |
| 131 |
|
| 132 |
if ( $cached_value ) { |
| 133 |
$this->value = (int) $cached_value; |
| 134 |
|
| 135 |
$this->is_custom = $this->value !== $this->default_value; |
| 136 |
} else { |
| 137 |
$this->value = $this->default_value; |
| 138 |
|
| 139 |
$this->is_custom = false; |
| 140 |
} |
| 141 |
|
| 142 |
return $this->value; |
| 143 |
} |
| 144 |
|
| 145 |
public function __construct( $args ) { |
| 146 |
$this->name = $args['name']; |
| 147 |
$this->label = $args['label']; |
| 148 |
// Used for CSS generation |
| 149 |
$this->db_key = Breakpoints_Manager::BREAKPOINT_SETTING_PREFIX . $args['name']; |
| 150 |
$this->direction = $args['direction']; |
| 151 |
$this->is_enabled = $args['is_enabled']; |
| 152 |
$this->default_value = $args['default_value']; |
| 153 |
} |
| 154 |
} |
| 155 |
|