namespace Elementor\Core\Base;
use Elementor\Core\Base\Elements_Iteration_Actions\Assets as Assets_Iteration_Action;
use Elementor\Core\Base\Elements_Iteration_Actions\Base as Elements_Iteration_Action;
use Elementor\Core\Behaviors\Interfaces\Lock_Behavior;
use Elementor\Core\Files\CSS\Post as Post_CSS;
use Elementor\Core\Settings\Page\Model as Page_Model;
use Elementor\Core\Utils\Collection;
use Elementor\Core\Utils\Exceptions;
use Elementor\Includes\Elements\Container;
use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\TemplateLibrary\Source_Local;
use Elementor\Core\Settings\Manager as SettingsManager;
use Elementor\Widget_Base;
use Elementor\Core\Settings\Page\Manager as PageManager;
use ElementorPro\Modules\Library\Widgets\Template;
use Elementor\Core\Utils\Promotions\Filtered_Promotions_Manager;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
* An abstract class that provides the needed properties and methods to
* manage and handle documents in inheriting classes.
abstract class Document extends Controls_Stack {
* Document type meta key.
const TYPE_META_KEY = '_elementor_template_type';
const PAGE_META_KEY = '_elementor_page_settings';
const ELEMENTOR_DATA_META_KEY = '_elementor_data';
const BUILT_WITH_ELEMENTOR_META_KEY = '_elementor_edit_mode';
const CACHE_META_KEY = '_elementor_element_cache';
* Document publish status.
const STATUS_PUBLISH = 'publish';
const STATUS_DRAFT = 'draft';
* Document private status.
const STATUS_PRIVATE = 'private';
* Document autosave status.
const STATUS_AUTOSAVE = 'autosave';
* Document pending status.
const STATUS_PENDING = 'pending';
private $is_saving = false;
private static $properties = [];
* @var Elements_Iteration_Action[]
private $elements_iteration_actions = [];
* Holds the document post data.
* @var \WP_Post WordPress post data.
* @param array $internal_elements
private function get_container_elements_data( array $internal_elements ): array {
'id' => Utils::generate_random_string(),
'elements' => $internal_elements,
* @param array $internal_elements
private function get_sections_elements_data( array $internal_elements ): array {
'id' => Utils::generate_random_string(),
'id' => Utils::generate_random_string(),
'elements' => $internal_elements,
protected static function get_editor_panel_categories() {
return Plugin::$instance->elements_manager->get_categories();
* Retrieve the document properties.
* @return array Document properties.
public static function get_properties() {
'show_in_finder' => true,
'show_on_admin_bar' => true,
'show_navigator' => true,
'allow_adding_widgets' => true,
'support_page_layout' => true,
'show_copy_and_share' => false,
'library_close_title' => esc_html__( 'Close', 'elementor' ),
'publish_button_title' => esc_html__( 'Publish', 'elementor' ),
'allow_closing_remote_library' => true,
public static function get_editor_panel_config() {
$default_route = 'panel/elements/categories';
if ( ! Plugin::instance()->role_manager->user_can( 'design' ) ) {
$default_route = 'panel/page-settings/settings';
'title' => static::get_title(), // JS Container title.
'widgets_settings' => [],
'elements_categories' => self::get_filtered_editor_panel_categories(),
'default_route' => $default_route,
'has_elements' => static::get_property( 'has_elements' ),
'support_kit' => static::get_property( 'support_kit' ),
'publish_notification' => sprintf(
/* translators: %s: Document title. */
esc_html__( 'Hurray! Your %s is live.', 'elementor' ),
'show_navigator' => static::get_property( 'show_navigator' ),
'allow_adding_widgets' => static::get_property( 'allow_adding_widgets' ),
'show_copy_and_share' => static::get_property( 'show_copy_and_share' ),
'library_close_title' => static::get_property( 'library_close_title' ),
'publish_button_title' => static::get_property( 'publish_button_title' ),
'allow_closing_remote_library' => static::get_property( 'allow_closing_remote_library' ),
public static function get_filtered_editor_panel_categories(): array {
$categories = static::get_editor_panel_categories();
$has_pro = Utils::has_pro();
foreach ( $categories as $index => $category ) {
if ( isset( $category['promotion'] ) ) {
$categories = self::get_panel_category_item( $category['promotion'], $index, $categories, $has_pro );
* @param array $categories
private static function get_panel_category_item( $promotion, $index, array $categories, bool $has_pro ): array {
$categories[ $index ]['promotion'] = Filtered_Promotions_Manager::get_filtered_promotion_data(
'elementor/panel/' . $index . '/custom_promotion',
unset( $categories[ $index ]['promotion'] );
* Retrieve the element title.
* @return string Element title.
public static function get_title() {
return esc_html__( 'Document', 'elementor' );
public static function get_plural_title() {
return static::get_title();
public static function get_add_new_title() {
/* translators: %s: Document title. */
esc_html__( 'Add New %s', 'elementor' ),
* Retrieve the document property.
* @param string $key The property key.
* @return mixed The property value.
public static function get_property( $key ) {
$id = static::get_class_full_name();
if ( ! isset( self::$properties[ $id ] ) ) {
self::$properties[ $id ] = static::get_properties();
return self::get_items( self::$properties[ $id ], $key );
public static function get_class_full_name() {
return get_called_class();
public static function get_create_url() {
$properties = static::get_properties();
// BC Support - Each document should define it own CPT this code is for BC support.
$cpt = Source_Local::CPT;
if ( isset( $properties['cpt'][0] ) ) {
$cpt = $properties['cpt'][0];
return Plugin::$instance->documents->get_create_new_post_url( $cpt, static::get_type() );
public function get_name() {
return static::get_type();
public function get_unique_name() {
return static::get_type() . '-' . $this->post->ID;
public function get_post_type_title() {
$post_type_object = get_post_type_object( $this->post->post_type );
return $post_type_object->labels->singular_name;
public function get_main_id() {
if ( ! $this->main_id ) {
$post_id = $this->post->ID;
$parent_post_id = wp_is_post_revision( $post_id );
$post_id = $parent_post_id;
$this->main_id = $post_id;
* @return null|Lock_Behavior
public static function get_lock_behavior_v2() {
* @throws \Exception If the widget was not found.
public function render_element( $data ) {
/** @var Widget_Base $widget */
$widget = Plugin::$instance->elements_manager->create_element_instance( $data );
throw new \Exception( 'Widget not found.' );
$widget->render_content();
$render_html = ob_get_clean();
public function get_main_post() {
return get_post( $this->get_main_id() );
public function get_container_attributes() {
$id = $this->get_main_id();
'data-elementor-type' => $this->get_name(),
'data-elementor-id' => $id,
'class' => 'elementor elementor-' . $id,
$version_meta = $this->get_main_meta( '_elementor_version' );
if ( version_compare( $version_meta, '2.5.0', '<' ) ) {
$attributes['class'] .= ' elementor-bc-flex-widget';
if ( Plugin::$instance->preview->is_preview() ) {
$attributes['data-elementor-title'] = static::get_title();
$elementor_settings = $this->get_frontend_settings();
if ( ! empty( $elementor_settings ) ) {
$attributes['data-elementor-settings'] = wp_json_encode( $elementor_settings );
// apply this filter to allow the attributes to be modified by different sources
return apply_filters( 'elementor/document/wrapper_attributes', $attributes, $this );
public function get_wp_preview_url() {
$main_post_id = $this->get_main_id();
// Ajax request from editor.
$initial_document_id = Utils::get_super_global_value( $_POST, 'initial_document_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
if ( ! empty( $initial_document_id ) ) {
$document = Plugin::$instance->documents->get( $initial_document_id ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
$url = get_preview_post_link(
$document->get_main_id(),
'preview_id' => $main_post_id,
'preview_nonce' => wp_create_nonce( 'post_preview_' . $main_post_id ),
* Document "WordPress preview" URL.
* Filters the WordPress preview URL.
* @param string $url WordPress preview URL.
* @param Document $this The document instance.
$url = apply_filters( 'elementor/document/urls/wp_preview', $url, $this );
public function get_exit_to_dashboard_url() {
$url = get_edit_post_link( $this->get_main_id(), 'raw' );
* Document "exit to dashboard" URL.
* Filters the "Exit To Dashboard" URL.
* @param string $url The exit URL
* @param Document $this The document instance.
$url = apply_filters( 'elementor/document/urls/exit_to_dashboard', $url, $this );
* Get url of the page which display all the posts of the current active document's post type.