Assets.php
2 days ago
Cache.php
3 weeks ago
Date.php
2 days ago
Debug.php
2 days ago
FeedReader.php
2 days ago
HTML.php
2 days ago
Helper.php
3 weeks ago
JSON.php
3 weeks ago
Nonce.php
3 weeks ago
Notice.php
2 days ago
Number.php
3 weeks ago
NumberConverter.php
2 days ago
Param.php
3 weeks ago
Sanitizing.php
2 days ago
Strip.php
3 weeks ago
Templates.php
3 weeks ago
User.php
3 weeks ago
Validating.php
3 weeks ago
WooCommerce.php
3 weeks ago
WordPress.php
2 days ago
Templates.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPParsidate\Helper; |
| 4 | |
| 5 | class Templates { |
| 6 | /** |
| 7 | * Load template file |
| 8 | * |
| 9 | * @param string $file Path to template file |
| 10 | * @param array $args array of args pass to template file |
| 11 | * @param bool $loadOnce Load once |
| 12 | * @param bool $echo Print template output |
| 13 | * |
| 14 | * @return false|string|void |
| 15 | */ |
| 16 | public static function load( string $file, array $args = [], bool $loadOnce = false, bool $echo = true ) { |
| 17 | if ( ! $echo ) { |
| 18 | ob_start(); |
| 19 | } |
| 20 | |
| 21 | if ( file_exists( $file ) ) { |
| 22 | load_template( $file, $loadOnce, $args ); |
| 23 | } |
| 24 | |
| 25 | if ( ! $echo ) { |
| 26 | return ob_get_clean(); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Get path of template file |
| 32 | * |
| 33 | * @param string $template |
| 34 | * @param string $dir |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | public static function getPath( $template, $dir = 'plugin' ): string { |
| 39 | $path = self::pathCorrection( WP_PARSI_DIR . '/inc/Templates/' . $dir . '/' . $template ); |
| 40 | |
| 41 | return apply_filters( 'wp_parsidate_template_path', $path, $template, $dir ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Fix template path |
| 46 | * |
| 47 | * @param string $path Path of template |
| 48 | * |
| 49 | * @return string Fixed path |
| 50 | */ |
| 51 | public static function pathCorrection( $path ): string { |
| 52 | return str_replace( [ '/', '\\' ], DIRECTORY_SEPARATOR, $path ); |
| 53 | } |
| 54 | } |
| 55 |