> $document, 'description' => 'Current Edited Template', ] ); return [ $current_post_id => 1, ]; } $templates = $this->get_location_templates( $location ); return $templates; } /** * @param Condition_Base $condition_instance * @param Condition_Base $sub_condition_instance * @param int $sub_id * * @return mixed * @throws \Exception */ private function get_condition_priority( $condition_instance, $sub_condition_instance, $sub_id ) { $priority = $condition_instance::get_priority(); if ( $sub_condition_instance ) { if ( $sub_condition_instance::get_priority() < $priority ) { $priority = $sub_condition_instance::get_priority(); } $priority -= 10; if ( $sub_id ) { $priority -= 10; } elseif ( 0 === count( $sub_condition_instance->get_sub_conditions() ) ) { // if no sub conditions - it's more specific. $priority -= 5; } } return $priority; } /** * @param Theme_Document $document * * @return array */ public function get_document_conditions( $document ) { $saved_conditions = $document->get_main_meta( '_elementor_conditions' ); $conditions = []; if ( is_array( $saved_conditions ) ) { foreach ( $saved_conditions as $condition ) { $conditions[] = $this->parse_condition( $condition ); } } return $conditions; } protected function parse_condition( $condition ) { list ( $type, $name, $sub_name, $sub_id ) = array_pad( explode( '/', $condition ), 4, '' ); return compact( 'type', 'name', 'sub_name', 'sub_id' ); } /** * @param $location * * @return Theme_Document[] */ public function get_documents_for_location( $location ) { if ( isset( $this->location_cache[ $location ] ) ) { return $this->location_cache[ $location ]; } $theme_templates_ids = $this->get_theme_templates_ids( $location ); /** @var Module $theme_builder_module */ $theme_builder_module = Module::instance(); $location_settings = $theme_builder_module->get_locations_manager()->get_location( $location ); $documents = []; foreach ( $theme_templates_ids as $theme_template_id => $priority ) { $document = $theme_builder_module->get_document( $theme_template_id ); if ( $document ) { $documents[ $theme_template_id ] = $document; } if ( empty( $location_settings['multiple'] ) ) { break; } } $this->location_cache[ $location ] = $documents; return $documents; } public function purge_post_from_cache( $post_id ) { return $this->cache->remove( $post_id )->save(); } public function get_cache() { return $this->cache; } public function clear_cache() { $this->cache->clear(); } public function clear_location_cache() { $this->location_cache = []; } }