| 1 |
<?php |
| 2 |
namespace Elementor\Core\Kits\Documents; |
| 3 |
|
| 4 |
use Elementor\Core\DocumentTypes\PageBase; |
| 5 |
use Elementor\Core\Files\CSS\Post as Post_CSS; |
| 6 |
use Elementor\Core\Kits\Documents\Tabs; |
| 7 |
use Elementor\Core\Settings\Manager as SettingsManager; |
| 8 |
use Elementor\Core\Settings\Page\Manager as PageManager; |
| 9 |
use Elementor\Plugin; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly |
| 13 |
} |
| 14 |
|
| 15 |
class Kit extends PageBase { |
| 16 |
/** |
| 17 |
* @var Tabs\Tab_Base[] |
| 18 |
*/ |
| 19 |
private $tabs; |
| 20 |
|
| 21 |
public function __construct( array $data = [] ) { |
| 22 |
parent::__construct( $data ); |
| 23 |
|
| 24 |
$this->tabs = [ |
| 25 |
'global-colors' => new Tabs\Global_Colors( $this ), |
| 26 |
'global-typography' => new Tabs\Global_Typography( $this ), |
| 27 |
'theme-style-typography' => new Tabs\Theme_Style_Typography( $this ), |
| 28 |
'theme-style-buttons' => new Tabs\Theme_Style_Buttons( $this ), |
| 29 |
'theme-style-images' => new Tabs\Theme_Style_Images( $this ), |
| 30 |
'theme-style-form-fields' => new Tabs\Theme_Style_Form_Fields( $this ), |
| 31 |
'settings-site-identity' => new Tabs\Settings_Site_Identity( $this ), |
| 32 |
'settings-background' => new Tabs\Settings_Background( $this ), |
| 33 |
'settings-layout' => new Tabs\Settings_Layout( $this ), |
| 34 |
'settings-lightbox' => new Tabs\Settings_Lightbox( $this ), |
| 35 |
'settings-custom-css' => new Tabs\Settings_Custom_CSS( $this ), |
| 36 |
]; |
| 37 |
} |
| 38 |
|
| 39 |
public static function get_properties() { |
| 40 |
$properties = parent::get_properties(); |
| 41 |
|
| 42 |
$properties['has_elements'] = false; |
| 43 |
$properties['show_in_finder'] = false; |
| 44 |
$properties['show_on_admin_bar'] = false; |
| 45 |
$properties['edit_capability'] = 'edit_theme_options'; |
| 46 |
$properties['support_kit'] = true; |
| 47 |
|
| 48 |
return $properties; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_name() { |
| 52 |
return 'kit'; |
| 53 |
} |
| 54 |
|
| 55 |
public static function get_title() { |
| 56 |
return __( 'Kit', 'elementor' ); |
| 57 |
} |
| 58 |
|
| 59 |
protected function get_have_a_look_url() { |
| 60 |
return ''; |
| 61 |
} |
| 62 |
|
| 63 |
public static function get_editor_panel_config() { |
| 64 |
$config = parent::get_editor_panel_config(); |
| 65 |
$config['default_route'] = 'panel/global/menu'; |
| 66 |
|
| 67 |
$config['needHelpUrl'] = 'https://go.elementor.com/global-settings'; |
| 68 |
|
| 69 |
return $config; |
| 70 |
} |
| 71 |
|
| 72 |
public function get_css_wrapper_selector() { |
| 73 |
return '.elementor-kit-' . $this->get_main_id(); |
| 74 |
} |
| 75 |
|
| 76 |
public function save( $data ) { |
| 77 |
$saved = parent::save( $data ); |
| 78 |
|
| 79 |
if ( $saved ) { |
| 80 |
// Should set is_saving to true, to avoid infinite loop when updating |
| 81 |
// settings like: 'site_name" or "site_description". |
| 82 |
$this->set_is_saving( true ); |
| 83 |
|
| 84 |
foreach ( $this->tabs as $tab ) { |
| 85 |
$tab->on_save( $data ); |
| 86 |
} |
| 87 |
|
| 88 |
$this->set_is_saving( false ); |
| 89 |
} |
| 90 |
|
| 91 |
return $saved; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* @since 2.0.0 |
| 96 |
* @access protected |
| 97 |
*/ |
| 98 |
protected function _register_controls() { |
| 99 |
$this->register_document_controls(); |
| 100 |
|
| 101 |
foreach ( $this->tabs as $tab ) { |
| 102 |
$tab->register_controls(); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
protected function get_post_statuses() { |
| 107 |
return [ |
| 108 |
'draft' => sprintf( '%s (%s)', __( 'Disabled', 'elementor' ), __( 'Draft', 'elementor' ) ), |
| 109 |
'publish' => __( 'Published', 'elementor' ), |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
public function add_repeater_row( $control_id, $item ) { |
| 114 |
$meta_key = PageManager::META_KEY; |
| 115 |
$document_settings = $this->get_meta( $meta_key ); |
| 116 |
|
| 117 |
if ( ! $document_settings ) { |
| 118 |
$document_settings = []; |
| 119 |
} |
| 120 |
|
| 121 |
if ( ! isset( $document_settings[ $control_id ] ) ) { |
| 122 |
$document_settings[ $control_id ] = []; |
| 123 |
} |
| 124 |
|
| 125 |
$document_settings[ $control_id ][] = $item; |
| 126 |
|
| 127 |
$page_settings_manager = SettingsManager::get_settings_managers( 'page' ); |
| 128 |
$page_settings_manager->save_settings( $document_settings, $this->get_id() ); |
| 129 |
|
| 130 |
/** @var Kit $autosave **/ |
| 131 |
$autosave = $this->get_autosave(); |
| 132 |
|
| 133 |
if ( $autosave ) { |
| 134 |
$autosave->add_repeater_row( $control_id, $item ); |
| 135 |
} |
| 136 |
|
| 137 |
// Remove Post CSS. |
| 138 |
$post_css = Post_CSS::create( $this->post->ID ); |
| 139 |
|
| 140 |
$post_css->delete(); |
| 141 |
|
| 142 |
// Refresh Cache. |
| 143 |
Plugin::$instance->documents->get( $this->post->ID, false ); |
| 144 |
|
| 145 |
$post_css = Post_CSS::create( $this->post->ID ); |
| 146 |
|
| 147 |
$post_css->enqueue(); |
| 148 |
} |
| 149 |
} |
| 150 |
|