'page_settings' => $page_settings,
] );
if ( is_wp_error( $template_id ) ) {
return $template_id;
}
return $this->get_item( $template_id );
}
/**
* Prepare template to export.
*
* Retrieve the relevant template data and return them as an array.
*
* @since 1.6.0
* @access private
*
* @param int $template_id The template ID.
*
* @return \WP_Error|array Exported template data.
*/
private function prepare_template_export( $template_id ) {
$document = Plugin::$instance->documents->get( $template_id );
$template_data = $document->get_export_data();
if ( empty( $template_data['content'] ) ) {
return new \WP_Error( 'empty_template', 'The template is empty' );
}
$export_data = [
'content' => $template_data['content'],
'page_settings' => $template_data['settings'],
'version' => DB::DB_VERSION,
'title' => $document->get_main_post()->post_title,
'type' => self::get_template_type( $template_id ),
];
return [
'name' => 'elementor-' . $template_id . '-' . gmdate( 'Y-m-d' ) . '.json',
'content' => wp_json_encode( $export_data ),
];
}
/**
* Send file headers.
*
* Set the file header when export template data to a file.
*
* @since 1.6.0
* @access private
*
* @param string $file_name File name.
* @param int $file_size File size.
*/
private function send_file_headers( $file_name, $file_size ) {
header( 'Content-Type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename=' . $file_name );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate' );
header( 'Pragma: public' );
header( 'Content-Length: ' . $file_size );
}
/**
* Get template label by type.
*
* Retrieve the template label for any given template type.
*
* @since 2.0.0
* @access private
*
* @param string $template_type Template type.
*
* @return string Template label.
*/
private function get_template_label_by_type( $template_type ) {
$document_types = Plugin::instance()->documents->get_document_types();
if ( isset( $document_types[ $template_type ] ) ) {
$template_label = call_user_func( [ $document_types[ $template_type ], 'get_title' ] );
} else {
$template_label = ucwords( str_replace( [ '_', '-' ], ' ', $template_type ) );
}
/**
* Template label by template type.
*
* Filters the template label by template type in the template library .
*
* @since 2.0.0
*
* @param string $template_label Template label.
* @param string $template_type Template type.
*/
$template_label = apply_filters( 'elementor/template-library/get_template_label_by_type', $template_label, $template_type );
return $template_label;
}
/**
* Filter template types in admin query.
*
* Update the template types in the main admin query.
*
* Fired by `parse_query` action.
*
* @since 2.4.0
* @access public
*
* @param \WP_Query $query The `WP_Query` instance.
*/
public function admin_query_filter_types( \WP_Query $query ) {
if ( ! $this->is_current_screen() || ! empty( $query->query_vars['meta_key'] ) ) {
return;
}
$current_tabs_group = $this->get_current_tab_group();
if ( isset( $query->query_vars[ self::TAXONOMY_CATEGORY_SLUG ] ) && '-1' === $query->query_vars[ self::TAXONOMY_CATEGORY_SLUG ] ) {
unset( $query->query_vars[ self::TAXONOMY_CATEGORY_SLUG ] );
}
if ( empty( $current_tabs_group ) ) {
return;
}
$doc_types = Plugin::$instance->documents->get_document_types( [
'admin_tab_group' => $current_tabs_group,
] );
$query->query_vars['meta_key'] = Document::TYPE_META_KEY;
$query->query_vars['meta_value'] = array_keys( $doc_types );
}
/**
* Add template library actions.
*
* Register filters and actions for the template library.
*
* @since 2.0.0
* @access private
*/
private function add_actions() {
if ( is_admin() ) {
add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
$this->register_admin_menu( $admin_menu );
}, static::ADMIN_MENU_PRIORITY );
add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu ) {
$this->admin_menu_reorder( $admin_menu );
}, 800 );
add_action( 'elementor/admin/menu/after_register', function () {
$this->admin_menu_set_current();
} );
add_filter( 'admin_title', [ $this, 'admin_title' ], 10, 2 );
add_action( 'all_admin_notices', [ $this, 'replace_admin_heading' ] );
add_filter( 'post_row_actions', [ $this, 'post_row_actions' ], 10, 2 );
add_action( 'admin_footer', [ $this, 'admin_import_template_form' ] );
add_action( 'save_post', [ $this, 'on_save_post' ], 10, 2 );
add_filter( 'display_post_states', [ $this, 'remove_elementor_post_state_from_library' ], 11, 2 );
add_action( 'parse_query', [ $this, 'admin_query_filter_types' ] );
// Template filter by category.
add_action( 'restrict_manage_posts', [ $this, 'add_filter_by_category' ] );
// Template type column.
add_action( 'manage_' . self::CPT . '_posts_columns', [ $this, 'admin_columns_headers' ] );
add_action( 'manage_' . self::CPT . '_posts_custom_column', [ $this, 'admin_columns_content' ], 10, 2 );
// Template library bulk actions.
add_filter( 'bulk_actions-edit-elementor_library', [ $this, 'admin_add_bulk_export_action' ] );
add_filter( 'handle_bulk_actions-edit-elementor_library', [ $this, 'admin_export_multiple_templates' ], 10, 3 );
// Print template library tabs.
add_filter( 'views_edit-' . self::CPT, [ $this, 'admin_print_tabs' ] );
// Show blank state.
add_action( 'manage_posts_extra_tablenav', [ $this, 'maybe_render_blank_state' ] );
}
add_action( 'template_redirect', [ $this, 'block_template_frontend' ] );
// Remove elementor library templates from WP Sitemap
add_filter(
'wp_sitemaps_post_types',
function( $post_types ) {
return $this->remove_elementor_cpt_from_sitemap( $post_types );
}
);
}
/**
* @since 2.0.6
* @access public
*/
public function admin_columns_content( $column_name, $post_id ) {
if ( 'elementor_library_type' === $column_name ) {
/** @var Document $document */
$document = Plugin::$instance->documents->get( $post_id );
if ( $document && $document instanceof Library_Document ) {
$document->print_admin_column_type();
}
}
}
/**
* @since 2.0.6
* @access public
*/
public function admin_columns_headers( $posts_columns ) {
// Replace original column that bind to the taxonomy - with another column.
unset( $posts_columns['taxonomy-elementor_library_type'] );
$offset = 2;
$posts_columns = array_slice( $posts_columns, 0, $offset, true ) + [
'elementor_library_type' => esc_html__( 'Type', 'elementor' ),
] + array_slice( $posts_columns, $offset, null, true );
return $posts_columns;
}
public function get_current_tab_group( $default = '' ) {
//phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
$current_tabs_group = Utils::get_super_global_value( $_REQUEST, 'tabs_group' ) ?? '';
//phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here.
$type_slug = Utils::get_super_global_value( $_REQUEST, self::TAXONOMY_TYPE_SLUG );
if ( $type_slug ) {
$doc_type = Plugin::$instance->documents->get_document_type( $type_slug, '' );
if ( $doc_type ) {
$current_tabs_group = $doc_type::get_property( 'admin_tab_group' );
}
}
return $current_tabs_group;
}
private function get_library_title() {
$title = '';
if ( $this->is_current_screen() ) {
$current_tab_group = $this->get_current_tab_group();
if ( $current_tab_group ) {
$titles = [
'library' => esc_html__( 'Saved Templates', 'elementor' ),
'theme' => esc_html__( 'Theme Builder', 'elementor' ),
'popup' => esc_html__( 'Popups', 'elementor' ),
];
if ( ! empty( $titles[ $current_tab_group ] ) ) {
$title = $titles[ $current_tab_group ];
}
}
}
return $title;
}
private function is_current_screen() {
global $pagenow, $typenow;
return 'edit.php' === $pagenow && self::CPT === $typenow;
}
/**
* @param array $post_types
*
* @return array
*/
private function remove_elementor_cpt_from_sitemap( array $post_types ) {
unset( $post_types[ self::CPT ] );
return $post_types;
}
/**
* Template library local source constructor.
*
* Initializing the template library local source base by registering custom
* template data and running custom actions.
*
* @since 1.0.0
* @access public
*/
public function __construct() {
parent::__construct();
$this->add_actions();
}
}
Fatal error: Uncaught Error: Class 'Elementor\TemplateLibrary\Source_Local' not found in /home/merciket/public_html/wp-content/plugins/elementor/modules/library/documents/library-document.php:47
Stack trace:
#0 /home/merciket/public_html/wp-content/plugins/elementor/modules/library/documents/not-supported.php(31): Elementor\Modules\Library\Documents\Library_Document::get_properties()
#1 /home/merciket/public_html/wp-content/plugins/elementor/core/base/document.php(274): Elementor\Modules\Library\Documents\Not_Supported::get_properties()
#2 /home/merciket/public_html/wp-content/plugins/elementor/core/documents-manager.php(148): Elementor\Core\Base\Document::get_property('cpt')
#3 /home/merciket/public_html/wp-content/plugins/elementor/modules/library/module.php(46): Elementor\Core\Documents_Manager->register_document_type('not-supported', 'Elementor\\Modul...')
#4 /home/merciket/public_html/wp-content/plugins/elementor/core/base/module.php(85): Elementor\Modules\Library\Module->__construct()
#5 /home/merciket/public_html/w in /home/merciket/public_html/wp-content/plugins/elementor/modules/library/documents/library-document.php on line 47