* @license GNU General Public License, version 3 * @copyright 2021-2022 WPthembay Core */ if( ! function_exists( 'wpthembay_get_widget_locate' ) ) { function wpthembay_get_widget_locate( $name, $plugin_dir = WPTHEMBAY_ELEMENTOR_DIR ) { $template = ''; // Child theme if ( ! $template && ! empty( $name ) && file_exists( get_stylesheet_directory() . "/widgets/{$name}" ) ) { $template = get_stylesheet_directory() . "/widgets/{$name}"; } // Original theme if ( ! $template && ! empty( $name ) && file_exists( get_template_directory() . "/widgets/{$name}" ) ) { $template = get_template_directory() . "/widgets/{$name}"; } // Plugin if ( ! $template && ! empty( $name ) && file_exists( $plugin_dir . "/templates/widgets/{$name}" ) ) { $template = $plugin_dir . "/templates/widgets/{$name}"; } // Nothing found if ( empty( $template ) ) { throw new Exception( "Template /templates/widgets/{$name} in plugin dir {$plugin_dir} not found." ); } return $template; } } if( ! function_exists( 'wpthembay_prefix_theme_template' ) ) { function wpthembay_prefix_theme_template(){ $output = strtolower(preg_replace('#[^a-zA-Z]#', '', get_template())); return $output; } } if( ! function_exists( 'wpthembay_single_template' ) ) { add_filter( 'single_template', 'wpthembay_single_template' ); function wpthembay_single_template( $single_template ){ global $post; if( is_singular( 'tb_portfolio' ) ) { $file = dirname(__FILE__) .'/classes/post-types/tb-portfolio/single-'. $post->post_type .'.php'; if( file_exists( $file ) ) $single_template = $file; } return $single_template; } } if( ! function_exists( 'wpthembay_archive_template' ) ) { add_filter( 'archive_template', 'wpthembay_archive_template' ); function wpthembay_archive_template( $single_template ){ global $post; if( is_post_type_archive( 'tb_portfolio' ) ) { $file = dirname(__FILE__) .'/classes/post-types/tb-portfolio/archive-'. $post->post_type .'.php'; if( file_exists( $file ) ) $single_template = $file; } return $single_template; } } if( ! function_exists( 'wpthembay_portfolio_locate_template' ) ) { function wpthembay_portfolio_locate_template( $path, $var = null ) { $template_path = 'tb-portfolio/' . $path; $plugin_path = WPTHEMBAY_ELEMENTOR_DIR . 'classes/post-types/tb-portfolio/' . $path; $located = locate_template( array( $template_path, // Search in /. ) ); if ( ! $located && file_exists( $plugin_path ) ) { return apply_filters( 'wpthembay_portfolio_locate_template', $plugin_path, $path ); } /** * APPLY_FILTERS: wpthembay_portfolio_locate_template * * Filter the location of the templates. * * @param string $located Template found * @param string $path Template path * * @return string */ return apply_filters( 'wpthembay_portfolio_locate_template', $located, $path ); } } if( ! function_exists( 'wpthembay_portfolio_get_template' ) ) { function wpthembay_portfolio_get_template( $path, $var = null, $return = false ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.varFound, Universal.NamingConventions.NoReservedKeywordParameterNames.returnFound $located = wpthembay_portfolio_locate_template( $path, $var ); if ( $var && is_array( $var ) ) { $atts = $var; extract( $var ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract } if ( $return ) { ob_start(); } // include file located. include $located; if ( $return ) { return ob_get_clean(); } } }