From f8b4f34cd0093713e59f63ab397b76685939f39c Mon Sep 17 00:00:00 2001 From: yura_nalivaiko Date: Tue, 24 Oct 2017 17:20:03 +0300 Subject: [PATCH 1/4] - added template functions; --- includes/class-functions.php | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/includes/class-functions.php b/includes/class-functions.php index 8d4b2dd5..a840e3a8 100644 --- a/includes/class-functions.php +++ b/includes/class-functions.php @@ -187,6 +187,76 @@ if ( ! class_exists( 'UM_Functions' ) ) { return apply_filters( 'um_excluded_taxonomies', $taxes ); } + /** + * Output templates + * + * @access public + * @param string $template_name + * @param string $path (default: '') + * @param array $t_args (default: array()) + * @param bool $echo + * + * @return string|void + */ + function get_template( $template_name, $basename = '', $t_args = array(), $echo = false ) { + if ( ! empty( $t_args ) && is_array( $t_args ) ) { + extract( $t_args ); + } + + $path = ''; + if( $basename ) { + $array = explode( '/', trim( $basename, '/' ) ); + $path = $array[0]; + } + + $located = $this->locate_template( $template_name, $path ); + + if ( ! file_exists( $located ) ) { + _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' ); + return; + } + + $located = apply_filters( 'um_get_template', $located, $template_name, $path, $t_args ); + + ob_start(); + do_action( 'um_before_template_part', $template_name, $path, $located, $t_args ); + include( $located ); + do_action( 'um_after_template_part', $template_name, $path, $located, $t_args ); + $html = ob_get_clean(); + + if ( ! $echo ) { + return $html; + } else { + echo $html; + } + } + + + /** + * Locate a template and return the path for inclusion. + * + * @access public + * @param string $template_name + * @param string $path (default: '') + * @return string + */ + function locate_template( $template_name, $path = '' ) { + // check if there is template at theme folder + $template = locate_template( array( + trailingslashit( 'ultimate-member/' . $path ) . $template_name + ) ); + + if( !$template ) { + if( $path ) { + $template = trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . $path ) . $template_name; + } else { + $template = trailingslashit( um_path . 'templates' ) . $template_name; + } + } + // Return what we found. + return apply_filters( 'um_locate_template', $template, $template_name, $path ); + } + } } \ No newline at end of file From dee53eddd91d5b4ad704567080d01a5b798cb377 Mon Sep 17 00:00:00 2001 From: yura_nalivaiko Date: Wed, 25 Oct 2017 17:11:58 +0300 Subject: [PATCH 2/4] - fixed template function; --- includes/class-functions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/class-functions.php b/includes/class-functions.php index a840e3a8..019bb3c4 100644 --- a/includes/class-functions.php +++ b/includes/class-functions.php @@ -210,7 +210,7 @@ if ( ! class_exists( 'UM_Functions' ) ) { } $located = $this->locate_template( $template_name, $path ); - +var_dump($located); if ( ! file_exists( $located ) ) { _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' ); return; @@ -248,10 +248,11 @@ if ( ! class_exists( 'UM_Functions' ) ) { if( !$template ) { if( $path ) { - $template = trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . $path ) . $template_name; + $template = trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . $path ); } else { - $template = trailingslashit( um_path . 'templates' ) . $template_name; + $template = trailingslashit( um_path ); } + $template .= 'templates/' . $template_name; } // Return what we found. return apply_filters( 'um_locate_template', $template, $template_name, $path ); From b98bd1529c1a8e44c8620f2e72e41d37e1579da7 Mon Sep 17 00:00:00 2001 From: yura_nalivaiko Date: Wed, 25 Oct 2017 17:11:58 +0300 Subject: [PATCH 3/4] - fixed template function; --- includes/class-functions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/class-functions.php b/includes/class-functions.php index a840e3a8..35d0242c 100644 --- a/includes/class-functions.php +++ b/includes/class-functions.php @@ -248,10 +248,11 @@ if ( ! class_exists( 'UM_Functions' ) ) { if( !$template ) { if( $path ) { - $template = trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . $path ) . $template_name; + $template = trailingslashit( trailingslashit( WP_PLUGIN_DIR ) . $path ); } else { - $template = trailingslashit( um_path . 'templates' ) . $template_name; + $template = trailingslashit( um_path ); } + $template .= 'templates/' . $template_name; } // Return what we found. return apply_filters( 'um_locate_template', $template, $template_name, $path ); From 6befee20ca0979a485f7d2c9700dd39ef34db7c8 Mon Sep 17 00:00:00 2001 From: yura_nalivaiko Date: Wed, 25 Oct 2017 17:16:39 +0300 Subject: [PATCH 4/4] - fixed templates function; --- includes/class-functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/class-functions.php b/includes/class-functions.php index 019bb3c4..c3362c4d 100644 --- a/includes/class-functions.php +++ b/includes/class-functions.php @@ -210,7 +210,6 @@ if ( ! class_exists( 'UM_Functions' ) ) { } $located = $this->locate_template( $template_name, $path ); -var_dump($located); if ( ! file_exists( $located ) ) { _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' ); return;