PKǞ\VrARRclasses/class-import-images.phpnuW+A_replace_image_ids[ $attachment['id'] ] ) ) { return $this->_replace_image_ids[ $attachment['id'] ]; } $post_id = $wpdb->get_var( $wpdb->prepare( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = \'_elementor_source_image_hash\' AND `meta_value` = %s ;', $this->get_hash_image( $attachment['url'] ) ) ); if ( $post_id ) { $new_attachment = [ 'id' => $post_id, 'url' => wp_get_attachment_url( $post_id ), ]; $this->_replace_image_ids[ $attachment['id'] ] = $new_attachment; return $new_attachment; } return false; } /** * Import image. * * Import a single image from a remote server, upload the image WordPress * uploads folder, create a new attachment in the database and updates the * attachment metadata. * * @since 1.0.0 * @access public * * @param array $attachment The attachment. * * @return false|array Imported image data, or false. */ public function import( $attachment ) { $saved_image = $this->get_saved_image( $attachment ); if ( $saved_image ) { return $saved_image; } // Extract the file name and extension from the url. $filename = basename( $attachment['url'] ); $file_content = wp_remote_retrieve_body( wp_safe_remote_get( $attachment['url'] ) ); if ( empty( $file_content ) ) { return false; } $upload = wp_upload_bits( $filename, null, $file_content ); $post = [ 'post_title' => $filename, 'guid' => $upload['url'], ]; $info = wp_check_filetype( $upload['file'] ); if ( $info ) { $post['post_mime_type'] = $info['type']; } else { // For now just return the origin attachment return $attachment; // return new \WP_Error( 'attachment_processing_error', __( 'Invalid file type.', 'elementor' ) ); } $post_id = wp_insert_attachment( $post, $upload['file'] ); wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); update_post_meta( $post_id, '_elementor_source_image_hash', $this->get_hash_image( $attachment['url'] ) ); $new_attachment = [ 'id' => $post_id, 'url' => $upload['url'], ]; $this->_replace_image_ids[ $attachment['id'] ] = $new_attachment; return $new_attachment; } /** * Template library import images constructor. * * Initializing the images import class used by the template library through * the WordPress Filesystem API. * * @since 1.0.0 * @access public */ public function __construct() { if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); } } PKǞ\@,== manager.phpnuW+Aregister_default_sources(); $this->add_actions(); } /** * @since 2.3.0 * @access public */ public function add_actions() { add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] ); add_action( 'wp_ajax_elementor_library_direct_actions', [ $this, 'handle_direct_actions' ] ); // TODO: bc since 2.3.0 add_action( 'wp_ajax_elementor_update_templates', function() { if ( ! isset( $_POST['templates'] ) ) { return; } foreach ( $_POST['templates'] as & $template ) { if ( ! isset( $template['content'] ) ) { return; } $template['content'] = stripslashes( $template['content'] ); } wp_send_json_success( $this->handle_ajax_request( 'update_templates', $_POST ) ); } ); } /** * Get `Import_Images` instance. * * Retrieve the instance of the `Import_Images` class. * * @since 1.0.0 * @access public * * @return Import_Images Imported images instance. */ public function get_import_images_instance() { if ( null === $this->_import_images ) { $this->_import_images = new Import_Images(); } return $this->_import_images; } /** * Register template source. * * Used to register new template sources displayed in the template library. * * @since 1.0.0 * @access public * * @param string $source_class The name of source class. * @param array $args Optional. Class arguments. Default is an * empty array. * * @return \WP_Error|true True if the source was registered, `WP_Error` * otherwise. */ public function register_source( $source_class, $args = [] ) { if ( ! class_exists( $source_class ) ) { return new \WP_Error( 'source_class_name_not_exists' ); } $source_instance = new $source_class( $args ); if ( ! $source_instance instanceof Source_Base ) { return new \WP_Error( 'wrong_instance_source' ); } $source_id = $source_instance->get_id(); if ( isset( $this->_registered_sources[ $source_id ] ) ) { return new \WP_Error( 'source_exists' ); } $this->_registered_sources[ $source_id ] = $source_instance; return true; } /** * Unregister template source. * * Remove an existing template sources from the list of registered template * sources. * * @deprecated 2.7.0 * * @since 1.0.0 * @access public * * @param string $id The source ID. * * @return bool Whether the source was unregistered. */ public function unregister_source( $id ) { return true; } /** * Get registered template sources. * * Retrieve registered template sources. * * @since 1.0.0 * @access public * * @return Source_Base[] Registered template sources. */ public function get_registered_sources() { return $this->_registered_sources; } /** * Get template source. * * Retrieve single template sources for a given template ID. * * @since 1.0.0 * @access public * * @param string $id The source ID. * * @return false|Source_Base Template sources if one exist, False otherwise. */ public function get_source( $id ) { $sources = $this->get_registered_sources(); if ( ! isset( $sources[ $id ] ) ) { return false; } return $sources[ $id ]; } /** * Get templates. * * Retrieve all the templates from all the registered sources. * * @since 1.0.0 * @access public * * @return array Templates array. */ public function get_templates() { $templates = []; foreach ( $this->get_registered_sources() as $source ) { $templates = array_merge( $templates, $source->get_items() ); } return $templates; } /** * Get library data. * * Retrieve the library data. * * @since 1.9.0 * @access public * * @param array $args Library arguments. * * @return array Library data. */ public function get_library_data( array $args ) { $library_data = Api::get_library_data( ! empty( $args['sync'] ) ); // Ensure all document are registered. Plugin::$instance->documents->get_document_types(); return [ 'templates' => $this->get_templates(), 'config' => $library_data['types_data'], ]; } /** * Save template. * * Save new or update existing template on the database. * * @since 1.0.0 * @access public * * @param array $args Template arguments. * * @return \WP_Error|int The ID of the saved/updated template. */ public function save_template( array $args ) { $validate_args = $this->ensure_args( [ 'post_id', 'source', 'content', 'type' ], $args ); if ( is_wp_error( $validate_args ) ) { return $validate_args; } $source = $this->get_source( $args['source'] ); if ( ! $source ) { return new \WP_Error( 'template_error', 'Template source not found.' ); } $args['content'] = json_decode( $args['content'], true ); $page = SettingsManager::get_settings_managers( 'page' )->get_model( $args['post_id'] ); $args['page_settings'] = $page->get_data( 'settings' ); $template_id = $source->save_item( $args ); if ( is_wp_error( $template_id ) ) { return $template_id; } return $source->get_item( $template_id ); } /** * Update template. * * Update template on the database. * * @since 1.0.0 * @access public * * @param array $template_data New template data. * * @return \WP_Error|Source_Base Template sources instance if the templates * was updated, `WP_Error` otherwise. */ public function update_template( array $template_data ) { $validate_args = $this->ensure_args( [ 'source', 'content', 'type' ], $template_data ); if ( is_wp_error( $validate_args ) ) { return $validate_args; } $source = $this->get_source( $template_data['source'] ); if ( ! $source ) { return new \WP_Error( 'template_error', 'Template source not found.' ); } $template_data['content'] = json_decode( $template_data['content'], true ); $update = $source->update_item( $template_data ); if ( is_wp_error( $update ) ) { return $update; } return $source->get_item( $template_data['id'] ); } /** * Update templates. * * Update template on the database. * * @since 1.0.0 * @access public * * @param array $args Template arguments. * * @return \WP_Error|true True if templates updated, `WP_Error` otherwise. */ public function update_templates( array $args ) { foreach ( $args['templates'] as $template_data ) { $result = $this->update_template( $template_data ); if ( is_wp_error( $result ) ) { return $result; } } return true; } /** * Get template data. * * Retrieve the template data. * * @since 1.5.0 * @access public * * @param array $args Template arguments. * * @return \WP_Error|bool|array ?? */ public function get_template_data( array $args ) { $validate_args = $this->ensure_args( [ 'source', 'template_id' ], $args ); if ( is_wp_error( $validate_args ) ) { return $validate_args; } if ( isset( $args['edit_mode'] ) ) { Plugin::$instance->editor->set_edit_mode( $args['edit_mode'] ); } $source = $this->get_source( $args['source'] ); if ( ! $source ) { return new \WP_Error( 'template_error', 'Template source not found.' ); } do_action( 'elementor/template-library/before_get_source_data', $args, $source ); $data = $source->get_data( $args ); do_action( 'elementor/template-library/after_get_source_data', $args, $source ); return $data; } /** * Delete template. * * Delete template from the database. * * @since 1.0.0 * @access public * * @param array $args Template arguments. * * @return \WP_Post|\WP_Error|false|null Post data on success, false or null * or 'WP_Error' on failure. */ public function delete_template( array $args ) { $validate_args = $this->ensure_args( [ 'source', 'template_id' ], $args ); if ( is_wp_error( $validate_args ) ) { return $validate_args; } $source = $this->get_source( $args['source'] ); if ( ! $source ) { return new \WP_Error( 'template_error', 'Template source not found.' ); } return $source->delete_template( $args['template_id'] ); } /** * Export template. * * Export template to a file. * * @since 1.0.0 * @access public * * @param array $args Template arguments. * * @return mixed Whether the export succeeded or failed. */ public function export_template( array $args ) { $validate_args = $this->ensure_args( [ 'source', 'template_id' ], $args ); if ( is_wp_error( $validate_args ) ) { return $validate_args; } $source = $this->get_source( $args['source'] ); if ( ! $source ) { return new \WP_Error( 'template_error', 'Template source not found' ); } return $source->export_template( $args['template_id'] ); } /** * @since 2.3.0 * @access public */ public function direct_import_template() { /** @var Source_Local $source */ $source = $this->get_source( 'local' ); return $source->import_template( $_FILES['file']['name'], $_FILES['file']['tmp_name'] ); } /** * Import template. * * Import template from a file. * * @since 1.0.0 * @access public * * @param array $data * * @return mixed Whether the export succeeded or failed. */ public function import_template( array $data ) { /** @var Source_Local $source */ $file_content = base64_decode( $data['fileData'] ); $tmp_file = tmpfile(); fwrite( $tmp_file, $file_content ); $source = $this->get_source( 'local' ); $result = $source->import_template( $data['fileName'], stream_get_meta_data( $tmp_file )['uri'] ); fclose( $tmp_file ); return $result; } /** * Mark template as favorite. * * Add the template to the user favorite templates. * * @since 1.9.0 * @access public * * @param array $args Template arguments. * * @return mixed Whether the template marked as favorite. */ public function mark_template_as_favorite( $args ) { $validate_args = $this->ensure_args( [ 'source', 'template_id', 'favorite' ], $args ); if ( is_wp_error( $validate_args ) ) { return $validate_args; } $source = $this->get_source( $args['source'] ); return $source->mark_as_favorite( $args['template_id'], filter_var( $args['favorite'], FILTER_VALIDATE_BOOLEAN ) ); } /** * Register default template sources. * * Register the 'local' and 'remote' template sources that Elementor use by * default. * * @since 1.0.0 * @access private */ private function register_default_sources() { $sources = [ 'local', 'remote', ]; foreach ( $sources as $source_filename ) { $class_name = ucwords( $source_filename ); $class_name = str_replace( '-', '_', $class_name ); $this->register_source( __NAMESPACE__ . '\Source_' . $class_name ); } } /** * Handle ajax request. * * Fire authenticated ajax actions for any given ajax request. * * @since 1.0.0 * @access private * * @param string $ajax_request Ajax request. * * @param array $data * * @return mixed * @throws \Exception */ private function handle_ajax_request( $ajax_request, array $data ) { if ( ! User::is_current_user_can_edit_post_type( Source_Local::CPT ) ) { throw new \Exception( 'Access Denied' ); } if ( ! empty( $data['editor_post_id'] ) ) { $editor_post_id = absint( $data['editor_post_id'] ); if ( ! get_post( $editor_post_id ) ) { throw new \Exception( __( 'Post not found.', 'elementor' ) ); } Plugin::$instance->db->switch_to_post( $editor_post_id ); } $result = call_user_func( [ $this, $ajax_request ], $data ); if ( is_wp_error( $result ) ) { throw new \Exception( $result->get_error_message() ); } return $result; } /** * Init ajax calls. * * Initialize template library ajax calls for allowed ajax requests. * * @since 2.3.0 * @access public * * @param Ajax $ajax */ public function register_ajax_actions( Ajax $ajax ) { $library_ajax_requests = [ 'get_library_data', 'get_template_data', 'save_template', 'update_templates', 'delete_template', 'import_template', 'mark_template_as_favorite', ]; foreach ( $library_ajax_requests as $ajax_request ) { $ajax->register_ajax_action( $ajax_request, function( $data ) use ( $ajax_request ) { return $this->handle_ajax_request( $ajax_request, $data ); } ); } } /** * @since 2.3.0 * @access public */ public function handle_direct_actions() { if ( ! User::is_current_user_can_edit_post_type( Source_Local::CPT ) ) { return; } /** @var Ajax $ajax */ $ajax = Plugin::$instance->common->get_component( 'ajax' ); if ( ! $ajax->verify_request_nonce() ) { $this->handle_direct_action_error( 'Access Denied' ); } $action = $_REQUEST['library_action']; $result = $this->$action( $_REQUEST ); if ( is_wp_error( $result ) ) { /** @var \WP_Error $result */ $this->handle_direct_action_error( $result->get_error_message() . '.' ); } $callback = "on_{$action}_success"; if ( method_exists( $this, $callback ) ) { $this->$callback( $result ); } die; } /** * On successful template import. * * Redirect the user to the template library after template import was * successful finished. * * @since 2.3.0 * @access private */ private function on_direct_import_template_success() { wp_safe_redirect( admin_url( Source_Local::ADMIN_MENU_SLUG ) ); } /** * @since 2.3.0 * @access private */ private function handle_direct_action_error( $message ) { _default_wp_die_handler( $message, 'Elementor Library' ); } /** * Ensure arguments exist. * * Checks whether the required arguments exist in the specified arguments. * * @since 1.0.0 * @access private * * @param array $required_args Required arguments to check whether they * exist. * @param array $specified_args The list of all the specified arguments to * check against. * * @return \WP_Error|true True on success, 'WP_Error' otherwise. */ private function ensure_args( array $required_args, array $specified_args ) { $not_specified_args = array_diff( $required_args, array_keys( array_filter( $specified_args ) ) ); if ( $not_specified_args ) { return new \WP_Error( 'arguments_not_specified', sprintf( 'The required argument(s) "%s" not specified.', implode( ', ', $not_specified_args ) ) ); } return true; } } PKǞ\X&!!sources/base.phpnuW+Aregister_data(); } /** * Mark template as favorite. * * Update user meta containing his favorite templates. For a given template * ID, add the template to the favorite templates or remove it from the * favorites, based on the `favorite` parameter. * * @since 1.9.0 * @access public * * @param int $template_id The template ID. * @param bool $favorite Optional. Whether the template is marked as * favorite, or not. Default is true. * * @return int|bool User meta ID if the key didn't exist, true on successful * update, false on failure. */ public function mark_as_favorite( $template_id, $favorite = true ) { $favorites_templates = $this->get_user_meta( 'favorites' ); if ( ! $favorites_templates ) { $favorites_templates = []; } if ( $favorite ) { $favorites_templates[ $template_id ] = $favorite; } elseif ( isset( $favorites_templates[ $template_id ] ) ) { unset( $favorites_templates[ $template_id ] ); } return $this->update_user_meta( 'favorites', $favorites_templates ); } /** * Get current user meta. * * Retrieve Elementor meta data for the current user. * * @since 1.9.0 * @access public * * @param string $item Optional. User meta key. Default is null. * * @return null|array An array of user meta data, or null otherwise. */ public function get_user_meta( $item = null ) { if ( null === $this->user_meta ) { $this->user_meta = get_user_meta( get_current_user_id(), $this->get_user_meta_prefix(), true ); } if ( ! $this->user_meta ) { $this->user_meta = []; } if ( $item ) { if ( isset( $this->user_meta[ $item ] ) ) { return $this->user_meta[ $item ]; } return null; } return $this->user_meta; } /** * Update current user meta. * * Update user meta data based on meta key an value. * * @since 1.9.0 * @access public * * @param string $key Optional. User meta key. * @param mixed $value Optional. User meta value. * * @return int|bool User meta ID if the key didn't exist, true on successful * update, false on failure. */ public function update_user_meta( $key, $value ) { $meta = $this->get_user_meta(); $meta[ $key ] = $value; $this->user_meta = $meta; return update_user_meta( get_current_user_id(), $this->get_user_meta_prefix(), $meta ); } /** * Replace elements IDs. * * For any given Elementor content/data, replace the IDs with new randomly * generated IDs. * * @since 1.0.0 * @access protected * * @param array $content Any type of Elementor data. * * @return mixed Iterated data. */ protected function replace_elements_ids( $content ) { return Plugin::$instance->db->iterate_data( $content, function( $element ) { $element['id'] = Utils::generate_random_string(); return $element; } ); } /** * Get Elementor library user meta prefix. * * Retrieve user meta prefix used to save Elementor data. * * @since 1.9.0 * @access protected * * @return string User meta prefix. */ protected function get_user_meta_prefix() { return 'elementor_library_' . $this->get_id(); } /** * Process content for export/import. * * Process the content and all the inner elements, and prepare all the * elements data for export/import. * * @since 1.5.0 * @access protected * * @param array $content A set of elements. * @param string $method Accepts either `on_export` to export data or * `on_import` to import data. * * @return mixed Processed content data. */ protected function process_export_import_content( $content, $method ) { return Plugin::$instance->db->iterate_data( $content, function( $element_data ) use ( $method ) { $element = Plugin::$instance->elements_manager->create_element_instance( $element_data ); // If the widget/element isn't exist, like a plugin that creates a widget but deactivated if ( ! $element ) { return null; } return $this->process_element_export_import_content( $element, $method ); } ); } /** * Process single element content for export/import. * * Process any given element and prepare the element data for export/import. * * @since 1.5.0 * @access protected * * @param Controls_Stack $element * @param string $method * * @return array Processed element data. */ protected function process_element_export_import_content( Controls_Stack $element, $method ) { $element_data = $element->get_data(); if ( method_exists( $element, $method ) ) { // TODO: Use the internal element data without parameters. $element_data = $element->{$method}( $element_data ); } foreach ( $element->get_controls() as $control ) { $control_class = Plugin::$instance->controls_manager->get_control( $control['type'] ); // If the control isn't exist, like a plugin that creates the control but deactivated. if ( ! $control_class ) { return $element_data; } if ( method_exists( $control_class, $method ) ) { $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ), $control ); } // On Export, check if the control has an argument 'export' => false. if ( 'on_export' === $method && isset( $control['export'] ) && false === $control['export'] ) { unset( $element_data['settings'][ $control['name'] ] ); } } return $element_data; } } PKǞ\LQsources/remote.phpnuW+Aprepare_template( $template_data ); } } return $templates; } /** * Get remote template. * * Retrieve a single remote template from Elementor.com servers. * * @since 1.0.0 * @access public * * @param int $template_id The template ID. * * @return array Remote template. */ public function get_item( $template_id ) { $templates = $this->get_items(); return $templates[ $template_id ]; } /** * Save remote template. * * Remote template from Elementor.com servers cannot be saved on the * database as they are retrieved from remote servers. * * @since 1.0.0 * @access public * * @param array $template_data Remote template data. * * @return \WP_Error */ public function save_item( $template_data ) { return new \WP_Error( 'invalid_request', 'Cannot save template to a remote source' ); } /** * Update remote template. * * Remote template from Elementor.com servers cannot be updated on the * database as they are retrieved from remote servers. * * @since 1.0.0 * @access public * * @param array $new_data New template data. * * @return \WP_Error */ public function update_item( $new_data ) { return new \WP_Error( 'invalid_request', 'Cannot update template to a remote source' ); } /** * Delete remote template. * * Remote template from Elementor.com servers cannot be deleted from the * database as they are retrieved from remote servers. * * @since 1.0.0 * @access public * * @param int $template_id The template ID. * * @return \WP_Error */ public function delete_template( $template_id ) { return new \WP_Error( 'invalid_request', 'Cannot delete template from a remote source' ); } /** * Export remote template. * * Remote template from Elementor.com servers cannot be exported from the * database as they are retrieved from remote servers. * * @since 1.0.0 * @access public * * @param int $template_id The template ID. * * @return \WP_Error */ public function export_template( $template_id ) { return new \WP_Error( 'invalid_request', 'Cannot export template from a remote source' ); } /** * Get remote template data. * * Retrieve the data of a single remote template from Elementor.com servers. * * @since 1.5.0 * @access public * * @param array $args Custom template arguments. * @param string $context Optional. The context. Default is `display`. * * @return array|\WP_Error Remote Template data. */ public function get_data( array $args, $context = 'display' ) { $data = Api::get_template_content( $args['template_id'] ); if ( is_wp_error( $data ) ) { return $data; } // BC. $data = (array) $data; $data['content'] = $this->replace_elements_ids( $data['content'] ); $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' ); $post_id = $args['editor_post_id']; $document = Plugin::$instance->documents->get( $post_id ); if ( $document ) { $data['content'] = $document->get_elements_raw_data( $data['content'], true ); } return $data; } /** * @since 2.2.0 * @access private */ private function prepare_template( array $template_data ) { $favorite_templates = $this->get_user_meta( 'favorites' ); return [ 'template_id' => $template_data['id'], 'source' => $this->get_id(), 'type' => $template_data['type'], 'subtype' => $template_data['subtype'], 'title' => $template_data['title'], 'thumbnail' => $template_data['thumbnail'], 'date' => $template_data['tmpl_created'], 'author' => $template_data['author'], 'tags' => json_decode( $template_data['tags'] ), 'isPro' => ( '1' === $template_data['is_pro'] ), 'popularityIndex' => (int) $template_data['popularity_index'], 'trendIndex' => (int) $template_data['trend_index'], 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ), 'url' => $template_data['url'], 'favorite' => ! empty( $favorite_templates[ $template_data['id'] ] ), ]; } } PKǞ\_sources/local.phpnuW+Abase && self::CPT === $current_screen->post_type; } /** * Add template type. * * Register new template type to the list of supported local template types. * * @since 1.0.3 * @access public * @static * * @param string $type Template type. */ public static function add_template_type( $type ) { self::$template_types[ $type ] = $type; } /** * Remove template type. * * Remove existing template type from the list of supported local template * types. * * @since 1.8.0 * @access public * @static * * @param string $type Template type. */ public static function remove_template_type( $type ) { if ( isset( self::$template_types[ $type ] ) ) { unset( self::$template_types[ $type ] ); } } public static function get_admin_url( $relative = false ) { $base_url = self::ADMIN_MENU_SLUG; if ( ! $relative ) { $base_url = admin_url( $base_url ); } return add_query_arg( 'tabs_group', 'library', $base_url ); } /** * Get local template ID. * * Retrieve the local template ID. * * @since 1.0.0 * @access public * * @return string The local template ID. */ public function get_id() { return 'local'; } /** * Get local template title. * * Retrieve the local template title. * * @since 1.0.0 * @access public * * @return string The local template title. */ public function get_title() { return __( 'Local', 'elementor' ); } /** * Register local template data. * * Used to register custom template data like a post type, a taxonomy or any * other data. * * The local template class registers a new `elementor_library` post type * and an `elementor_library_type` taxonomy. They are used to store data for * local templates saved by the user on his site. * * @since 1.0.0 * @access public */ public function register_data() { $labels = [ 'name' => _x( 'My Templates', 'Template Library', 'elementor' ), 'singular_name' => _x( 'Template', 'Template Library', 'elementor' ), 'add_new' => _x( 'Add New', 'Template Library', 'elementor' ), 'add_new_item' => _x( 'Add New Template', 'Template Library', 'elementor' ), 'edit_item' => _x( 'Edit Template', 'Template Library', 'elementor' ), 'new_item' => _x( 'New Template', 'Template Library', 'elementor' ), 'all_items' => _x( 'All Templates', 'Template Library', 'elementor' ), 'view_item' => _x( 'View Template', 'Template Library', 'elementor' ), 'search_items' => _x( 'Search Template', 'Template Library', 'elementor' ), 'not_found' => _x( 'No Templates found', 'Template Library', 'elementor' ), 'not_found_in_trash' => _x( 'No Templates found in Trash', 'Template Library', 'elementor' ), 'parent_item_colon' => '', 'menu_name' => _x( 'Templates', 'Template Library', 'elementor' ), ]; $args = [ 'labels' => $labels, 'public' => true, 'rewrite' => false, 'menu_icon' => 'dashicons-admin-page', 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'exclude_from_search' => true, 'capability_type' => 'post', 'hierarchical' => false, 'supports' => [ 'title', 'thumbnail', 'author', 'elementor' ], ]; /** * Register template library post type args. * * Filters the post type arguments when registering elementor template library post type. * * @since 1.0.0 * * @param array $args Arguments for registering a post type. */ $args = apply_filters( 'elementor/template_library/sources/local/register_post_type_args', $args ); $this->post_type_object = register_post_type( self::CPT, $args ); $args = [ 'hierarchical' => false, 'show_ui' => false, 'show_in_nav_menus' => false, 'show_admin_column' => true, 'query_var' => is_admin(), 'rewrite' => false, 'public' => false, 'label' => _x( 'Type', 'Template Library', 'elementor' ), ]; /** * Register template library taxonomy args. * * Filters the taxonomy arguments when registering elementor template library taxonomy. * * @since 1.0.0 * * @param array $args Arguments for registering a taxonomy. */ $args = apply_filters( 'elementor/template_library/sources/local/register_taxonomy_args', $args ); register_taxonomy( self::TAXONOMY_TYPE_SLUG, self::CPT, $args ); /** * Categories */ $args = [ 'hierarchical' => true, 'show_ui' => true, 'show_in_nav_menus' => false, 'show_admin_column' => true, 'query_var' => is_admin(), 'rewrite' => false, 'public' => false, 'labels' => [ 'name' => _x( 'Categories', 'Template Library', 'elementor' ), 'singular_name' => _x( 'Category', 'Template Library', 'elementor' ), 'all_items' => _x( 'All Categories', 'Template Library', 'elementor' ), ], ]; /** * Register template library category args. * * Filters the category arguments when registering elementor template library category. * * @since 2.4.0 * * @param array $args Arguments for registering a category. */ $args = apply_filters( 'elementor/template_library/sources/local/register_category_args', $args ); register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT, $args ); } /** * Remove Add New item from admin menu. * * Fired by `admin_menu` action. * * @since 2.4.0 * @access public */ public function admin_menu_reorder() { global $submenu; if ( ! isset( $submenu[ self::ADMIN_MENU_SLUG ] ) ) { return; } $library_submenu = &$submenu[ self::ADMIN_MENU_SLUG ]; // Remove 'All Templates' menu. unset( $library_submenu[5] ); // If current use can 'Add New' - move the menu to end, and add the '#add_new' anchor. if ( isset( $library_submenu[10][2] ) ) { $library_submenu[700] = $library_submenu[10]; unset( $library_submenu[10] ); $library_submenu[700][2] = admin_url( self::ADMIN_MENU_SLUG . '#add_new' ); } // Move the 'Categories' menu to end. if ( isset( $library_submenu[15] ) ) { $library_submenu[800] = $library_submenu[15]; unset( $library_submenu[15] ); } if ( $this->is_current_screen() ) { $library_title = $this->get_library_title(); foreach ( $library_submenu as &$item ) { if ( $library_title === $item[0] ) { if ( ! isset( $item[4] ) ) { $item[4] = ''; } $item[4] .= ' current'; } } } } public function admin_menu() { add_submenu_page( self::ADMIN_MENU_SLUG, '', __( 'Saved Templates', 'elementor' ), Editor::EDITING_CAPABILITY, self::get_admin_url( true ) ); } public function admin_title( $admin_title, $title ) { $library_title = $this->get_library_title(); if ( $library_title ) { $admin_title = str_replace( $title, $library_title, $admin_title ); } return $admin_title; } public function replace_admin_heading() { $library_title = $this->get_library_title(); if ( $library_title ) { global $post_type_object; $post_type_object->labels->name = $library_title; } } /** * Get local templates. * * Retrieve local templates saved by the user on his site. * * @since 1.0.0 * @access public * * @param array $args Optional. Filter templates based on a set of * arguments. Default is an empty array. * * @return array Local templates. */ public function get_items( $args = [] ) { $template_types = array_values( self::$template_types ); if ( ! empty( $args['type'] ) ) { $template_types = $args['type']; } $templates_query = new \WP_Query( [ 'post_type' => self::CPT, 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => [ [ 'key' => Document::TYPE_META_KEY, 'value' => $template_types, ], ], ] ); $templates = []; if ( $templates_query->have_posts() ) { foreach ( $templates_query->get_posts() as $post ) { $templates[] = $this->get_item( $post->ID ); } } return $templates; } /** * Save local template. * * Save new or update existing template on the database. * * @since 1.0.0 * @access public * * @param array $template_data Local template data. * * @return \WP_Error|int The ID of the saved/updated template, `WP_Error` otherwise. */ public function save_item( $template_data ) { if ( ! current_user_can( $this->post_type_object->cap->edit_posts ) ) { return new \WP_Error( 'save_error', __( 'Access denied.', 'elementor' ) ); } $defaults = [ 'title' => __( '(no title)', 'elementor' ), 'page_settings' => [], 'status' => current_user_can( 'publish_posts' ) ? 'publish' : 'pending', ]; $template_data = wp_parse_args( $template_data, $defaults ); $document = Plugin::$instance->documents->create( $template_data['type'], [ 'post_title' => $template_data['title'], 'post_status' => $template_data['status'], 'post_type' => self::CPT, ] ); if ( is_wp_error( $document ) ) { /** * @var \WP_Error $document */ return $document; } if ( ! empty( $template_data['content'] ) ) { $template_data['content'] = $this->replace_elements_ids( $template_data['content'] ); } $document->save( [ 'elements' => $template_data['content'], 'settings' => $template_data['page_settings'], ] ); $template_id = $document->get_main_id(); /** * After template library save. * * Fires after Elementor template library was saved. * * @since 1.0.1 * * @param int $template_id The ID of the template. * @param array $template_data The template data. */ do_action( 'elementor/template-library/after_save_template', $template_id, $template_data ); /** * After template library update. * * Fires after Elementor template library was updated. * * @since 1.0.1 * * @param int $template_id The ID of the template. * @param array $template_data The template data. */ do_action( 'elementor/template-library/after_update_template', $template_id, $template_data ); return $template_id; } /** * Update local template. * * Update template on the database. * * @since 1.0.0 * @access public * * @param array $new_data New template data. * * @return \WP_Error|true True if template updated, `WP_Error` otherwise. */ public function update_item( $new_data ) { if ( ! current_user_can( $this->post_type_object->cap->edit_post, $new_data['id'] ) ) { return new \WP_Error( 'save_error', __( 'Access denied.', 'elementor' ) ); } $document = Plugin::$instance->documents->get( $new_data['id'] ); if ( ! $document ) { return new \WP_Error( 'save_error', __( 'Template not exist.', 'elementor' ) ); } $document->save( [ 'elements' => $new_data['content'], ] ); /** * After template library update. * * Fires after Elementor template library was updated. * * @since 1.0.0 * * @param int $new_data_id The ID of the new template. * @param array $new_data The new template data. */ do_action( 'elementor/template-library/after_update_template', $new_data['id'], $new_data ); return true; } /** * Get local template. * * Retrieve a single local template saved by the user on his site. * * @since 1.0.0 * @access public * * @param int $template_id The template ID. * * @return array Local template. */ public function get_item( $template_id ) { $post = get_post( $template_id ); $user = get_user_by( 'id', $post->post_author ); $page = SettingsManager::get_settings_managers( 'page' )->get_model( $template_id ); $page_settings = $page->get_data( 'settings' ); $date = strtotime( $post->post_date ); $data = [ 'template_id' => $post->ID, 'source' => $this->get_id(), 'type' => self::get_template_type( $post->ID ), 'title' => $post->post_title, 'thumbnail' => get_the_post_thumbnail_url( $post ), 'date' => $date, 'human_date' => date_i18n( get_option( 'date_format' ), $date ), 'author' => $user->display_name, 'hasPageSettings' => ! empty( $page_settings ), 'tags' => [], 'export_link' => $this->get_export_link( $template_id ), 'url' => get_permalink( $post->ID ), ]; /** * Get template library template. * * Filters the template data when retrieving a single template from the * template library. * * @since 1.0.0 * * @param array $data Template data. */ $data = apply_filters( 'elementor/template-library/get_template', $data ); return $data; } /** * Get template data. * * Retrieve the data of a single local template saved by the user on his site. * * @since 1.5.0 * @access public * * @param array $args Custom template arguments. * * @return array Local template data. */ public function get_data( array $args ) { $db = Plugin::$instance->db; $template_id = $args['template_id']; // TODO: Validate the data (in JS too!). if ( ! empty( $args['display'] ) ) { $content = $db->get_builder( $template_id ); } else { $document = Plugin::$instance->documents->get( $template_id ); $content = $document ? $document->get_elements_data() : []; } if ( ! empty( $content ) ) { $content = $this->replace_elements_ids( $content ); } $data = [ 'content' => $content, ]; if ( ! empty( $args['with_page_settings'] ) ) { $page = SettingsManager::get_settings_managers( 'page' )->get_model( $args['template_id'] ); $data['page_settings'] = $page->get_data( 'settings' ); } return $data; } /** * Delete local template. * * Delete template from the database. * * @since 1.0.0 * @access public * * @param int $template_id The template ID. * * @return \WP_Post|\WP_Error|false|null Post data on success, false or null * or 'WP_Error' on failure. */ public function delete_template( $template_id ) { if ( ! current_user_can( $this->post_type_object->cap->delete_post, $template_id ) ) { return new \WP_Error( 'template_error', __( 'Access denied.', 'elementor' ) ); } return wp_delete_post( $template_id, true ); } /** * Export local template. * * Export template to a file. * * @since 1.0.0 * @access public * * @param int $template_id The template ID. * * @return \WP_Error WordPress error if template export failed. */ public function export_template( $template_id ) { $file_data = $this->prepare_template_export( $template_id ); if ( is_wp_error( $file_data ) ) { return $file_data; } $this->send_file_headers( $file_data['name'], strlen( $file_data['content'] ) ); // Clear buffering just in case. @ob_end_clean(); flush(); // Output file contents. echo $file_data['content']; die; } /** * Export multiple local templates. * * Export multiple template to a ZIP file. * * @since 1.6.0 * @access public * * @param array $template_ids An array of template IDs. * * @return \WP_Error WordPress error if export failed. */ public function export_multiple_templates( array $template_ids ) { $files = []; $wp_upload_dir = wp_upload_dir(); $temp_path = $wp_upload_dir['basedir'] . '/' . self::TEMP_FILES_DIR; // Create temp path if it doesn't exist wp_mkdir_p( $temp_path ); // Create all json files foreach ( $template_ids as $template_id ) { $file_data = $this->prepare_template_export( $template_id ); if ( is_wp_error( $file_data ) ) { continue; } $complete_path = $temp_path . '/' . $file_data['name']; $put_contents = file_put_contents( $complete_path, $file_data['content'] ); if ( ! $put_contents ) { return new \WP_Error( '404', sprintf( 'Cannot create file "%s".', $file_data['name'] ) ); } $files[] = [ 'path' => $complete_path, 'name' => $file_data['name'], ]; } if ( ! $files ) { return new \WP_Error( 'empty_files', 'There is no files to export (probably all the requested templates are empty).' ); } // Create temporary .zip file $zip_archive_filename = 'elementor-templates-' . gmdate( 'Y-m-d' ) . '.zip'; $zip_archive = new \ZipArchive(); $zip_complete_path = $temp_path . '/' . $zip_archive_filename; $zip_archive->open( $zip_complete_path, \ZipArchive::CREATE ); foreach ( $files as $file ) { $zip_archive->addFile( $file['path'], $file['name'] ); } $zip_archive->close(); foreach ( $files as $file ) { unlink( $file['path'] ); } $this->send_file_headers( $zip_archive_filename, filesize( $zip_complete_path ) ); @ob_end_flush(); @readfile( $zip_complete_path ); unlink( $zip_complete_path ); die; } /** * Import local template. * * Import template from a file. * * @since 1.0.0 * @access public * * @param string $name - The file name * @param string $path - The file path * * @return \WP_Error|array An array of items on success, 'WP_Error' on failure. */ public function import_template( $name, $path ) { if ( empty( $path ) ) { return new \WP_Error( 'file_error', 'Please upload a file to import' ); } $items = []; $file_extension = pathinfo( $name, PATHINFO_EXTENSION ); if ( 'zip' === $file_extension ) { if ( ! class_exists( '\ZipArchive' ) ) { return new \WP_Error( 'zip_error', 'PHP Zip extension not loaded' ); } $zip = new \ZipArchive(); $wp_upload_dir = wp_upload_dir(); $temp_path = $wp_upload_dir['basedir'] . '/' . self::TEMP_FILES_DIR . '/' . uniqid(); $zip->open( $path ); $valid_entries = []; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase for ( $i = 0; $i < $zip->numFiles; $i++ ) { $zipped_file_name = $zip->getNameIndex( $i ); $zipped_extension = pathinfo( $zipped_file_name, PATHINFO_EXTENSION ); if ( 'json' === $zipped_extension ) { $valid_entries[] = $zipped_file_name; } } if ( ! empty( $valid_entries ) ) { $zip->extractTo( $temp_path, $valid_entries ); } $zip->close(); $file_names = array_diff( scandir( $temp_path ), [ '.', '..' ] ); foreach ( $file_names as $file_name ) { $full_file_name = $temp_path . '/' . $file_name; $import_result = $this->import_single_template( $full_file_name ); unlink( $full_file_name ); if ( is_wp_error( $import_result ) ) { return $import_result; } $items[] = $import_result; } rmdir( $temp_path ); } else { $import_result = $this->import_single_template( $path ); if ( is_wp_error( $import_result ) ) { return $import_result; } $items[] = $import_result; } return $items; } /** * Post row actions. * * Add an export link to the template library action links table list. * * Fired by `post_row_actions` filter. * * @since 1.0.0 * @access public * * @param array $actions An array of row action links. * @param \WP_Post $post The post object. * * @return array An updated array of row action links. */ public function post_row_actions( $actions, \WP_Post $post ) { if ( self::is_base_templates_screen() ) { if ( $this->is_template_supports_export( $post->ID ) ) { $actions['export-template'] = sprintf( '%2$s', $this->get_export_link( $post->ID ), __( 'Export Template', 'elementor' ) ); } } return $actions; } /** * Admin import template form. * * The import form displayed in "My Library" screen in WordPress dashboard. * * The form allows the user to import template in json/zip format to the site. * * Fired by `admin_footer` action. * * @since 1.0.0 * @access public */ public function admin_import_template_form() { if ( ! self::is_base_templates_screen() ) { return; } /** @var \Elementor\Core\Common\Modules\Ajax\Module $ajax */ $ajax = Plugin::$instance->common->get_component( 'ajax' ); ?>
post_type && isset( $post_states['elementor'] ) ) { unset( $post_states['elementor'] ); } return $post_states; } /** * Get template export link. * * Retrieve the link used to export a single template based on the template * ID. * * @since 2.0.0 * @access private * * @param int $template_id The template ID. * * @return string Template export URL. */ private function get_export_link( $template_id ) { // TODO: BC since 2.3.0 - Use `$ajax->create_nonce()` /** @var \Elementor\Core\Common\Modules\Ajax\Module $ajax */ // $ajax = Plugin::$instance->common->get_component( 'ajax' ); return add_query_arg( [ 'action' => 'elementor_library_direct_actions', 'library_action' => 'export_template', 'source' => $this->get_id(), '_nonce' => wp_create_nonce( 'elementor_ajax' ), 'template_id' => $template_id, ], admin_url( 'admin-ajax.php' ) ); } /** * On template save. * * Run this method when template is being saved. * * Fired by `save_post` action. * * @since 1.0.1 * @access public * * @param int $post_id Post ID. * @param \WP_Post $post The current post object. */ public function on_save_post( $post_id, \WP_Post $post ) { if ( self::CPT !== $post->post_type ) { return; } if ( self::get_template_type( $post_id ) ) { // It's already with a type return; } // Don't save type on import, the importer will do it. if ( did_action( 'import_start' ) ) { return; } $this->save_item_type( $post_id, 'page' ); } /** * Save item type. * * When saving/updating templates, this method is used to update the post * meta data and the taxonomy. * * @since 1.0.1 * @access private * * @param int $post_id Post ID. * @param string $type Item type. */ private function save_item_type( $post_id, $type ) { update_post_meta( $post_id, Document::TYPE_META_KEY, $type ); wp_set_object_terms( $post_id, $type, self::TAXONOMY_TYPE_SLUG ); } /** * Bulk export action. * * Adds an 'Export' action to the Bulk Actions drop-down in the template * library. * * Fired by `bulk_actions-edit-elementor_library` filter. * * @since 1.6.0 * @access public * * @param array $actions An array of the available bulk actions. * * @return array An array of the available bulk actions. */ public function admin_add_bulk_export_action( $actions ) { $actions[ self::BULK_EXPORT_ACTION ] = __( 'Export', 'elementor' ); return $actions; } /** * Add bulk export action. * * Handles the template library bulk export action. * * Fired by `handle_bulk_actions-edit-elementor_library` filter. * * @since 1.6.0 * @access public * * @param string $redirect_to The redirect URL. * @param string $action The action being taken. * @param array $post_ids The items to take the action on. */ public function admin_export_multiple_templates( $redirect_to, $action, $post_ids ) { if ( self::BULK_EXPORT_ACTION === $action ) { $result = $this->export_multiple_templates( $post_ids ); // If you reach this line, the export failed wp_die( $result->get_error_message() ); } } /** * Print admin tabs. * * Used to output the template library tabs with their labels. * * Fired by `views_edit-elementor_library` filter. * * @since 2.0.0 * @access public * * @param array $views An array of available list table views. * * @return array An updated array of available list table views. */ public function admin_print_tabs( $views ) { $current_type = ''; $active_class = ' nav-tab-active'; $current_tabs_group = $this->get_current_tab_group(); if ( ! empty( $_REQUEST[ self::TAXONOMY_TYPE_SLUG ] ) ) { $current_type = $_REQUEST[ self::TAXONOMY_TYPE_SLUG ]; $active_class = ''; } $url_args = [ 'post_type' => self::CPT, 'tabs_group' => $current_tabs_group, ]; $baseurl = add_query_arg( $url_args, admin_url( 'edit.php' ) ); $filter = [ 'admin_tab_group' => $current_tabs_group, ]; $operator = 'and'; if ( empty( $current_tabs_group ) ) { // Don't include 'not-supported' or other templates that don't set their `admin_tab_group`. $operator = 'NOT'; } $doc_types = Plugin::$instance->documents->get_document_types( $filter, $operator ); if ( 1 >= count( $doc_types ) ) { return $views; } ?> get_pagination_arg( 'total_items' ); if ( ! empty( $total_items ) || ! empty( $_REQUEST['s'] ) ) { return; } $inline_style = '#posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display:none;}'; $current_type = get_query_var( 'elementor_library_type' ); $document_types = Plugin::instance()->documents->get_document_types(); if ( empty( $document_types[ $current_type ] ) ) { return; } // TODO: Better way to exclude widget type. if ( 'widget' === $current_type ) { return; } if ( empty( $current_type ) ) { $counts = (array) wp_count_posts( self::CPT ); unset( $counts['auto-draft'] ); $count = array_sum( $counts ); if ( 0 < $count ) { return; } $current_type = 'template'; $inline_style .= '#elementor-template-library-tabs-wrapper {display: none;}'; } $current_type_label = $this->get_template_label_by_type( $current_type ); ?>

labels->all_items; $dropdown_options = array( 'show_option_all' => $all_items, 'show_option_none' => $all_items, 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'value_field' => 'slug', 'taxonomy' => self::TAXONOMY_CATEGORY_SLUG, 'name' => self::TAXONOMY_CATEGORY_SLUG, 'selected' => empty( $_GET[ self::TAXONOMY_CATEGORY_SLUG ] ) ? '' : $_GET[ self::TAXONOMY_CATEGORY_SLUG ], ); echo ''; wp_dropdown_categories( $dropdown_options ); } /** * Import single template. * * Import template from a file to the database. * * @since 1.6.0 * @access private * * @param string $file_name File name. * * @return \WP_Error|int|array Local template array, or template ID, or * `WP_Error`. */ private function import_single_template( $file_name ) { $data = json_decode( file_get_contents( $file_name ), true ); if ( empty( $data ) ) { return new \WP_Error( 'file_error', 'Invalid File' ); } $content = $data['content']; if ( ! is_array( $content ) ) { return new \WP_Error( 'file_error', 'Invalid File' ); } $content = $this->process_export_import_content( $content, 'on_import' ); $page_settings = []; if ( ! empty( $data['page_settings'] ) ) { $page = new Model( [ 'id' => 0, 'settings' => $data['page_settings'], ] ); $page_settings_data = $this->process_element_export_import_content( $page, 'on_import' ); if ( ! empty( $page_settings_data['settings'] ) ) { $page_settings = $page_settings_data['settings']; } } $template_id = $this->save_item( [ 'content' => $content, 'title' => $data['title'], 'type' => $data['type'], '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 ) { $template_data = $this->get_data( [ 'template_id' => $template_id, ] ); if ( empty( $template_data['content'] ) ) { return new \WP_Error( 'empty_template', 'The template is empty' ); } $template_data['content'] = $this->process_export_import_content( $template_data['content'], 'on_export' ); if ( get_post_meta( $template_id, '_elementor_page_settings', true ) ) { $page = SettingsManager::get_settings_managers( 'page' )->get_model( $template_id ); $page_settings_data = $this->process_element_export_import_content( $page, 'on_export' ); if ( ! empty( $page_settings_data['settings'] ) ) { $template_data['page_settings'] = $page_settings_data['settings']; } } $export_data = [ 'version' => DB::DB_VERSION, 'title' => get_the_title( $template_id ), 'type' => self::get_template_type( $template_id ), ]; $export_data += $template_data; 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( 'admin_menu', [ $this, 'admin_menu' ] ); add_action( 'admin_menu', [ $this, 'admin_menu_reorder' ], 800 ); 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' ] ); } /** * @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' => __( 'Type', 'elementor' ), ] + array_slice( $posts_columns, $offset, null, true ); return $posts_columns; } private function get_current_tab_group( $default = '' ) { $current_tabs_group = $default; if ( ! empty( $_REQUEST[ self::TAXONOMY_TYPE_SLUG ] ) ) { $doc_type = Plugin::$instance->documents->get_document_type( $_REQUEST[ self::TAXONOMY_TYPE_SLUG ], '' ); if ( $doc_type ) { $current_tabs_group = $doc_type::get_property( 'admin_tab_group' ); } } elseif ( ! empty( $_REQUEST['tabs_group'] ) ) { $current_tabs_group = $_REQUEST['tabs_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' => __( 'Saved Templates', 'elementor' ), 'theme' => __( 'Theme Builder', 'elementor' ), 'popup' => __( '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; } /** * 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(); } } PKǞ\VrARRclasses/class-import-images.phpnuW+APKǞ\@,== manager.phpnuW+APKǞ\X&!!Lsources/base.phpnuW+APKǞ\LQnsources/remote.phpnuW+APKǞ\_sources/local.phpnuW+APK/