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