PATH:
home
/
centosnipponia
/
public_html
/
BAK_doohannl
/
wp-content
/
themes
/
sydney-pro-ii
/
inc
/
templates-builder
<?php /** * Custom templates * * @package Sydney */ if ( !class_exists( 'Sydney_Templates' ) ) : Class Sydney_Templates { /** * Instance */ private static $instance; /** * Initiator */ public static function get_instance() { if ( ! isset( self::$instance ) ) { self::$instance = new self; } return self::$instance; } /** * Constructor */ public function __construct() { add_action( 'template_redirect', array( $this, 'render_custom_content' ) ); add_action( 'template_redirect', array( $this, 'render_custom_header' ) ); add_action( 'template_redirect', array( $this, 'render_custom_footer' ) ); add_action( 'template_redirect', array( $this, 'render_custom_archive' ) ); add_action( 'template_redirect', array( $this, 'render_custom_single' ) ); add_action( 'template_redirect', array( $this, 'render_404_page' ) ); add_action( 'template_redirect', array( $this, 'redirect_single_ahf' ) ); add_action( 'single_template', array( $this, 'load_canvas_template' ) ); //Assets add_action( 'elementor/frontend/after_register_styles', array( $this, 'register_assets' ) ); add_action( 'wp_head', array( $this, 'add_css_archive_item' ) ); //Flush rewrite rules add_action( 'init', array( $this, 'flush_rules' ), 999 ); } /** * Render the custom content into the selected action hook */ public function render_custom_content() { $ids = $this->get_template_id( 'content' ); if ( empty( $ids ) ) { return; } foreach ( $ids as $id ) { $hook = get_post_meta( $id, '_ahf_hook_type', true); $priority = get_post_meta( $id, '_ahf_hook_priority', true); if ( !$priority ) { $priority = 10; } if ( $this->is_built_with_elementor( $id ) ) { add_action( $hook, function() use ( $id ) { echo '<div class="sydney-custom-content">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $id ) . '</div>'; }, $priority ); } else { add_action( $hook, function() use ( $id ) { $thepost = get_post( $id ); echo '<div class="sydney-custom-content">' . do_blocks( $thepost->post_content ) . '</div>'; }, $priority ); } if ( 'sydney_404_content' === $hook ) { remove_action( 'sydney_404_content', 'sydney_404_page_content' ); } } } /** * Render custom header */ public function render_custom_header() { $ids = $this->get_template_id( 'header' ); $sticky_ids = $this->get_template_id( 'sticky-header' ); if ( empty( $ids ) && empty( $sticky_ids ) ) { return; } $id = end( $ids ); $sticky_id = end( $sticky_ids ); remove_action( 'sydney_header', array( Sydney_Header::get_instance(), 'header_markup' ) ); remove_action( 'sydney_header', array( Sydney_Header::get_instance(), 'header_mobile_markup' ) ); if ( $this->is_built_with_elementor( $id ) ) { $static_header_class = 'custom-static-header'; //Merged $merge_header = get_post_meta( $id, '_ahf_merge_header', true ); if ( isset( $merge_header ) && $merge_header ) { $static_header_class .= ' custom-merged-header'; } add_action( 'sydney_header', function() use ( $id, $sticky_id, $static_header_class ) { echo '<header class="sydney-custom-header">'; echo '<div class="' . esc_attr( $static_header_class ) . '">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $id ) . '</div>'; if ( $sticky_id ) { echo '<div class="custom-sticky-header">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $sticky_id ) . '</div>'; } echo '</header>'; } ); } else { add_action( 'sydney_header', function() use ( $id ) { $thepost = get_post( $id ); echo '<header class="custom-site-header">' . do_blocks( $thepost->post_content ) . '</header>'; } ); } } /** * Render custom archive */ public function render_custom_archive() { $ids = $this->get_template_id( 'archive' ); if ( !$ids || empty( $ids ) ) { return; } $id = end( $ids ); remove_action( 'sydney_archive_content', 'sydney_archive_template' ); remove_action( 'sydney_get_sidebar', 'sydney_get_sidebar' ); if ( $this->is_built_with_elementor( $id ) ) { add_action( 'sydney_archive_content', function() use ( $id ) { echo '<div class="sydney-custom-archive">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $id ) . '</div>'; } ); } else { add_action( 'sydney_archive_content', function() use ( $id ) { $thepost = get_post( $id ); echo '<div class="custom-archive">' . do_blocks( $thepost->post_content ) . '</div>'; } ); } } /** * Render custom single */ public function render_custom_single() { $ids = $this->get_template_id( 'single' ); if ( !$ids || empty( $ids ) ) { return; } $id = end( $ids ); remove_action( 'sydney_single_content', 'sydney_single_template' ); remove_action( 'sydney_get_sidebar', 'sydney_get_sidebar' ); if ( $this->is_built_with_elementor( $id ) ) { add_action( 'sydney_single_content', function() use ( $id ) { echo '<div class="sydney-custom-single">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $id ) . '</div>'; } ); } else { add_action( 'sydney_single_content', function() use ( $id ) { $thepost = get_post( $id ); echo '<div class="custom-single">' . do_blocks( $thepost->post_content ) . '</div>'; } ); } } /** * Render custom footer */ public function render_custom_footer() { $ids = $this->get_template_id( 'footer' ); if ( empty( $ids ) ) { return; } $id = end( $ids ); remove_action( 'sydney_footer', array( Sydney_Footer::get_instance(), 'footer_markup' ) ); if ( $this->is_built_with_elementor( $id ) ) { add_action( 'sydney_footer', function() use ( $id ) { echo '<footer class="sydney-custom-footer">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $id ) . '</footer>'; } ); } else { add_action( 'sydney_footer', function() use ( $id ) { $thepost = get_post( $id ); echo '<footer class="custom-site-footer">' . do_blocks( $thepost->post_content ) . '</footer>'; } ); } } /** * Render 404 page */ public function render_404_page() { $args = array( 'numberposts' => -1, 'meta_key' => '_ahf_template_type', 'meta_value' => 'page404', 'post_type' => 'athemes_hf', ); $templates = get_posts( $args ); $ids = array(); foreach ( $templates as $template ) { $ids[] = $template->ID; } if ( empty( $ids ) ) { return; } $id = end( $ids ); remove_action( 'sydney_404_content', 'sydney_404_page_content' ); if ( $this->is_built_with_elementor( $id ) ) { add_action( 'sydney_404_content', function() use ( $id ) { echo '<div class="sydney-custom-404">' . Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $id ) . '</div>'; } ); } else { add_action( 'sydney_404_content', function() use ( $id ) { $thepost = get_post( $id ); echo '<div class="sydney-custom-404">' . do_blocks( $thepost->post_content ) . '</div>'; } ); } } /** * Template ID */ public function get_template_id( $template_type ) { $meta_query_args = array( array( 'key' => '_ahf_template_type', 'value' => $template_type, ), ); //For sticky headers if ( 'sticky-header' === $template_type ) { $meta_query_args = array( array( 'key' => '_ahf_sticky_header', 'value' => 1, ), ); } //Get templates CPT $args = array( 'numberposts' => -1, 'post_type' => 'athemes_hf', 'meta_query' => $meta_query_args ); $templates = get_posts( $args ); $ids = array(); foreach ( $templates as $template ) { $metas = get_post_meta( $template->ID, 'ahf_display_rules', true); //Get current post type $current_type = ''; if ( is_singular() || is_date() ) { $current_type = get_post_type(); } elseif ( is_post_type_archive() ) { $current_type = get_queried_object()->name; } elseif ( is_tax() || is_category() || is_tag() ) { $current_type = get_taxonomy( get_queried_object()->taxonomy )->object_type[0]; $taxonomies = get_object_taxonomies( $current_type ); } if ( empty( $metas ) || '' === $metas ) { return; } foreach ( $metas as $meta ) { switch ( $meta['select'] ) { case 'website': $ids[] = $template->ID; break; case 'homepage': if ( is_front_page() ) { $ids[] = $template->ID; } break; case is_int( intval( $meta['select'] ) ) && 0 !== intval( $meta['select'] ): if ( intval( $meta['select'] ) === get_the_id() && is_singular() ) { $ids[] = $template->ID; } break; case $current_type; if ( is_singular( $current_type ) ) { $ids[] = $template->ID; } break; case $current_type . '-archives'; if ( 'post' === $current_type ) { if ( is_category() || is_tag() || is_date() ) { $ids[] = $template->ID; } } elseif ( is_post_type_archive( $current_type ) ) { $ids[] = $template->ID; } elseif ( is_tax() ) { foreach ( $taxonomies as $taxonomy ) { if ( is_tax( $taxonomy ) ) { $ids[] = $template->ID; } } } break; case 'search': if ( is_search() ) { $ids[] = $template->ID; } break; case 'blog': if ( is_home() ) { $ids[] = $template->ID; } break; case 'shop': if ( function_exists( 'is_shop' ) && is_shop() ) { $ids[] = $template->ID; } break; case 'page-404': if ( is_404() ) { $ids[] = $template->ID; } break; } } } return $ids; } /** * Check if template is built with Elementor */ public function is_built_with_elementor( $id ) { if ( class_exists( 'Elementor\Plugin' ) && Elementor\Plugin::$instance->documents->get( $id )->is_built_with_elementor() ) { return true; } return false; } /** * Redirect single template view to home */ public function redirect_single_ahf() { if ( is_singular( 'athemes_hf' ) && ! current_user_can( 'edit_posts' ) ) { wp_redirect( site_url(), 301 ); die; } } /** * Add CSS for archive item view to reduce width */ public function add_css_archive_item() { if ( is_singular( 'athemes_hf' ) ) { $type = get_post_meta( get_the_id(), '_ahf_template_type', true ); if ( 'archive-item' === $type ) { echo '<style>.elementor-section.elementor-section-boxed > .elementor-container { max-width:600px; }</style>'; } } } /** * Load Elementor canvas template */ function load_canvas_template( $single_template ) { if ( !class_exists( 'Elementor\Plugin' ) ) { return $single_template; } global $post; if ( 'athemes_hf' == $post->post_type ) { $elementor_2_0_canvas = ELEMENTOR_PATH . '/modules/page-templates/templates/canvas.php'; if ( file_exists( $elementor_2_0_canvas ) ) { return $elementor_2_0_canvas; } else { return ELEMENTOR_PATH . '/includes/page-templates/canvas.php'; } } return $single_template; } /** * Enqueue assets */ public function register_assets() { wp_register_style( 'sydney-builder-widgets-styles', get_template_directory_uri() . '/inc/templates-builder/assets/css/builder-widgets.min.css' ); } /** * Flush rewrite rules */ public function flush_rules() { if ( !get_transient( 'sydney_templates_flushed_rules') ) { flush_rewrite_rules(); set_transient( 'sydney_templates_flushed_rules', true, 0 ); } } } /** * Initialize class */ if ( !is_admin() ) { Sydney_Templates::get_instance(); } endif;
[+]
..
[+]
assets
[+]
components
[-] class-sydney-patterns.php
[edit]
[-] class-sydney-templates-display.php
[edit]
[-] class-sydney-templates.php
[edit]
[-] sydney-templates-cpt.php
[edit]
[-] .htaccess.disabled
[edit]