| 1 |
<?php |
| 2 |
namespace Elementor\Core\Settings\Base; |
| 3 |
|
| 4 |
use Elementor\Core\Files\CSS\Base as CSS_File; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly. |
| 8 |
} |
| 9 |
|
| 10 |
abstract class CSS_Manager extends Manager { |
| 11 |
|
| 12 |
/** |
| 13 |
* Get CSS file name. |
| 14 |
* |
| 15 |
* Retrieve CSS file name for the settings base css manager. |
| 16 |
* |
| 17 |
* @since 2.8.0 |
| 18 |
* @access protected |
| 19 |
* @abstract |
| 20 |
* |
| 21 |
* @return string CSS file name |
| 22 |
*/ |
| 23 |
abstract protected function get_css_file_name(); |
| 24 |
|
| 25 |
/** |
| 26 |
* Get model for CSS file. |
| 27 |
* |
| 28 |
* Retrieve the model for the CSS file. |
| 29 |
* |
| 30 |
* @since 2.8.0 |
| 31 |
* @access protected |
| 32 |
* @abstract |
| 33 |
* |
| 34 |
* @param CSS_File $css_file The requested CSS file. |
| 35 |
* |
| 36 |
* @return CSS_Model |
| 37 |
*/ |
| 38 |
abstract protected function get_model_for_css_file( CSS_File $css_file ); |
| 39 |
|
| 40 |
/** |
| 41 |
* Get CSS file for update. |
| 42 |
* |
| 43 |
* Retrieve the CSS file before updating it. |
| 44 |
* |
| 45 |
* @since 2.8.0 |
| 46 |
* @access protected |
| 47 |
* @abstract |
| 48 |
* |
| 49 |
* @param int $id Post ID. |
| 50 |
* |
| 51 |
* @return CSS_File |
| 52 |
*/ |
| 53 |
abstract protected function get_css_file_for_update( $id ); |
| 54 |
|
| 55 |
/** |
| 56 |
* Settings base manager constructor. |
| 57 |
* |
| 58 |
* Initializing Elementor settings base css manager. |
| 59 |
* |
| 60 |
* @since 2.8.0 |
| 61 |
* @access public |
| 62 |
*/ |
| 63 |
public function __construct() { |
| 64 |
parent::__construct(); |
| 65 |
|
| 66 |
$name = $this->get_css_file_name(); |
| 67 |
|
| 68 |
add_action( "elementor/css-file/{$name}/parse", [ $this, 'add_settings_css_rules' ] ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Save settings. |
| 73 |
* |
| 74 |
* Save settings to the database and update the CSS file. |
| 75 |
* |
| 76 |
* @since 2.8.0 |
| 77 |
* @access public |
| 78 |
* |
| 79 |
* @param array $settings Settings. |
| 80 |
* @param int $id Optional. Post ID. Default is `0`. |
| 81 |
*/ |
| 82 |
public function save_settings( array $settings, $id = 0 ) { |
| 83 |
parent::save_settings( $settings, $id ); |
| 84 |
|
| 85 |
$css_file = $this->get_css_file_for_update( $id ); |
| 86 |
|
| 87 |
if ( $css_file ) { |
| 88 |
$css_file->update(); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Add settings CSS rules. |
| 94 |
* |
| 95 |
* Add new CSS rules to the settings manager. |
| 96 |
* |
| 97 |
* Fired by `elementor/css-file/{$name}/parse` action. |
| 98 |
* |
| 99 |
* @since 2.8.0 |
| 100 |
* @access public |
| 101 |
* |
| 102 |
* @param CSS_File $css_file The requested CSS file. |
| 103 |
*/ |
| 104 |
public function add_settings_css_rules( CSS_File $css_file ) { |
| 105 |
$model = $this->get_model_for_css_file( $css_file ); |
| 106 |
|
| 107 |
$css_file->add_controls_stack_style_rules( |
| 108 |
$model, |
| 109 |
$css_file->get_style_controls( $model, null, $model->get_settings() ), |
| 110 |
$model->get_settings(), |
| 111 |
[ '{{WRAPPER}}' ], |
| 112 |
[ $model->get_css_wrapper_selector() ] |
| 113 |
); |
| 114 |
} |
| 115 |
} |
| 116 |
|