dmin_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() { $current_tabs_group = Utils::get_super_global_value( $_GET, 'tabs_group' ) ?? ''; $type_slug = Utils::get_super_global_value( $_GET, 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; } private function avoid_rest_access_for_non_admins(): void { add_filter( 'rest_pre_dispatch', function ( $value, \WP_REST_Server $server, \WP_REST_Request $request ) { if ( strpos( $request->get_route(), self::CPT ) !== false ) { if ( ! current_user_can( 'manage_options' ) ) { return new \WP_Error( 'rest_forbidden', esc_html__( 'Sorry, you are not allowed to do that.', 'elementor' ), [ 'status' => rest_authorization_required_code() ] ); } } return $value; }, 10, 3 ); } public function save_bulk_items( array $args = [] ) { $items = []; foreach ( $args as $item ) { $items[] = $this->save_item( [ 'content' => $item['content'], 'title' => $item['title'], 'type' => $item['type'], 'page_settings' => $item['page_settings'], ] ); } return $items; } /** * 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(); } public function format_args_for_bulk_action( $args ) { $bulk_args = []; foreach ( $args['from_template_id'] as $from_template_id ) { if ( ! $this->is_allowed_to_read_template( [ 'template_id' => $from_template_id, ] ) ) { continue; } $document = Plugin::$instance->documents->get( $from_template_id ); if ( ! $document ) { continue; } $page = SettingsManager::get_settings_managers( 'page' )->get_model( $from_template_id ); $bulk_args[] = array_merge( $args, [ 'title' => $document->get_post()->post_title, 'type' => $document::get_type(), 'content' => $document->get_elements_data(), 'page_settings' => $page->get_data( 'settings' ), ] ); } return $bulk_args; } public function format_args_for_single_action( $args ) { if ( ! $this->is_allowed_to_read_template( [ 'template_id' => $args['from_template_id'], ] ) ) { return new \WP_Error( 'template_error', esc_html__( 'You do not have permission to access this template.', 'elementor' ) ); } $document = Plugin::$instance->documents->get( $args['from_template_id'] ); if ( ! $document ) { return new \WP_Error( 'template_error', 'Document not found.' ); } $args['content'] = $document->get_elements_data(); $page = SettingsManager::get_settings_managers( 'page' )->get_model( $args['from_template_id'] ); $args['page_settings'] = $page->get_data( 'settings' ); return $args; } public function is_allowed_to_read_template( array $args ): bool { if ( null === $this->wordpress_adapter ) { $this->set_wordpress_adapter( new WordPress_Adapter() ); } $post_id = intval( $args['template_id'] ); $post_status = $this->wordpress_adapter->get_post_status( $post_id ); if ( 'publish' === $post_status && ! post_password_required( $post_id ) ) { return true; } $can_read_template = $this->wordpress_adapter->current_user_can( 'edit_post', $post_id ); return apply_filters( 'elementor/template-library/is_allowed_to_read_template', $can_read_template, $args ); } public function set_wordpress_adapter( Wordpress_Adapter_Interface $wordpress_adapter ) { $this->wordpress_adapter = $wordpress_adapter; } public function set_elementor_adapter( Elementor_Adapter_Interface $elementor_adapter ): void { $this->elementor_adapter = $elementor_adapter; } }