$template, 'description' => 'Template File: No Templates for condition', ] ); return $template; } if ( 'single' === $location || 'archive' === $location ) { $first_key = key( $location_documents ); $theme_document = $location_documents[ $first_key ]; if ( Module::is_preview() && $theme_document->get_autosave_id() ) { $theme_document = $theme_document->get_autosave(); } $document_page_template = $theme_document->get_settings( 'page_template' ); if ( $document_page_template ) { $page_template = $document_page_template; $this->inspector_log( [ 'document' => $theme_document, 'template' => $template, 'description' => 'Template File: Document Page Template', ] ); } } } /** * @var \Elementor\Modules\PageTemplates\Module $page_templates_module */ $page_templates_module = Plugin::elementor()->modules_manager->get_modules( 'page-templates' ); // If is a `content` document or the theme is not support the document location (top header/ sidebar and etc.). $location_exist = ! empty( $location_settings ); $is_header_footer = 'header' === $location || 'footer' === $location; $need_override_location = ! empty( $location_settings['overwrite'] ) && ! $is_header_footer; $need_override_location = apply_filters( 'elementor/theme/need_override_location', $need_override_location, $location, $this ); if ( $location && empty( $page_template ) && ( ! $location_exist || $need_override_location ) ) { $page_template = $page_templates_module::TEMPLATE_HEADER_FOOTER; } if ( ! empty( $page_template ) ) { $template_path = $page_templates_module->get_template_path( $page_template ); if ( $template_path ) { $page_templates_module->set_print_callback( function() use ( $location ) { Module::instance()->get_locations_manager()->do_location( $location ); } ); $this->inspector_log( [ 'location' => $location, 'template' => $template_path, 'description' => $location_exist ? 'Template File: Location Settings (Override)' : 'Template File: Location not exit', ] ); $template = $template_path; } } return $template; } /** * @param string $location * @param integer $document_id */ public function add_doc_to_location( $location, $document_id ) { if ( isset( $this->locations_skipped[ $location ][ $document_id ] ) ) { // Don't re-add skipped documents. return; } if ( ! isset( $this->locations_queue[ $location ] ) ) { $this->locations_queue[ $location ] = []; } $this->locations_queue[ $location ][ $document_id ] = $document_id; } public function remove_doc_from_location( $location, $document_id ) { unset( $this->locations_queue[ $location ][ $document_id ] ); } public function skip_doc_in_location( $location, $document_id ) { $this->remove_doc_from_location( $location, $document_id ); if ( ! isset( $this->locations_skipped[ $location ] ) ) { $this->locations_skipped[ $location ] = []; } $this->locations_skipped[ $location ][ $document_id ] = $document_id; } public function is_printed( $location, $document_id ) { return isset( $this->locations_printed[ $location ][ $document_id ] ); } public function set_is_printed( $location, $document_id ) { if ( ! isset( $this->locations_printed[ $location ] ) ) { $this->locations_printed[ $location ] = []; } $this->locations_printed[ $location ][ $document_id ] = $document_id; $this->remove_doc_from_location( $location, $document_id ); } public function do_location( $location ) { /** @var Theme_Document[] $documents_by_conditions */ $documents_by_conditions = Module::instance()->get_conditions_manager()->get_documents_for_location( $location ); foreach ( $documents_by_conditions as $document_id => $document ) { $this->add_doc_to_location( $location, $document_id ); } // Locations Queue can contain documents that added manually. if ( empty( $this->locations_queue[ $location ] ) ) { return false; } if ( is_singular() ) { Utils::set_global_authordata(); } /** * Before location content printed. * * Fires before Elementor location was printed. * * The dynamic portion of the hook name, `$location`, refers to the location name. * * @since 2.0.0 * * @param Locations_Manager $this An instance of locations manager. */ do_action( "elementor/theme/before_do_{$location}", $this ); while ( ! empty( $this->locations_queue[ $location ] ) ) { $document_id = key( $this->locations_queue[ $location ] ); $document = Module::instance()->get_document( $document_id ); if ( ! $document || $this->is_printed( $location, $document_id ) ) { $this->skip_doc_in_location( $location, $document_id ); continue; } // `$documents_by_conditions` can pe current post even if it's a draft. if ( empty( $documents_by_conditions[ $document_id ] ) ) { $post_status = get_post_status( $document_id ); if ( 'publish' !== $post_status ) { $this->inspector_log( [ 'location' => $location, 'document' => $document, 'description' => 'Added manually but skipped because is not Published', ] ); $this->skip_doc_in_location( $location, $document_id ); continue; } } $this->inspector_log( [ 'location' => $location, 'document' => $document, 'description' => isset( $documents_by_conditions[ $document_id ] ) ? 'Added By Condition' : 'Added Manually', ] ); $this->current_location = $location; $document->print_content(); $this->did_locations[] = $this->current_location; $this->current_location = null; $this->set_is_printed( $location, $document_id ); } /** * After location content printed. * * Fires after Elementor location was printed. * * The dynamic portion of the hook name, `$location`, refers to the location name. * * @since 2.0.0 * * @param Locations_Manager $this An instance of locations manager. */ do_action( "elementor/theme/after_do_{$location}", $this ); return true; } public function did_location( $location ) { return in_array( $location, $this->did_locations, true ); } public function get_current_location() { return $this->current_location; } public function builder_wrapper( $content ) { $post_id = get_the_ID(); if ( $post_id ) { $document = Module::instance()->get_document( $post_id ); if ( $document ) { $document_location = $document->get_location(); $location_settings = $this->get_location( $document_location ); // If is a `content` document or the theme is not support the document location (header/footer and etc.). if ( $location_settings && ! $location_settings['edit_in_content'] ) { $content = '