Created
December 20, 2021 19:59
-
-
Save ekandreas/0f750af15745baf7826cb2dd4d32cb56 to your computer and use it in GitHub Desktop.
Bladerunner View Plugin with BladeOne
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Bladerunner View | |
Description: Replace Bladerunner with new blade view compiler | |
Version: 1.0.0 | |
Author: EkAndreas | |
License: MIT License | |
*/ | |
function bladeViewPaths() | |
{ | |
$bladePaths = apply_filters('bladerunner/template/bladepath', get_stylesheet_directory()); | |
if (!is_array($bladePaths)) { | |
$bladePaths = [$bladePaths]; | |
} | |
$stylesheetPath = get_stylesheet_directory(); | |
$templatePath = get_template_directory(); | |
$bladePaths[] = $stylesheetPath . DIRECTORY_SEPARATOR . 'views'; | |
$bladePaths[] = $stylesheetPath . DIRECTORY_SEPARATOR . 'views'; | |
$themePaths = [ | |
$stylesheetPath, | |
$stylesheetPath . DIRECTORY_SEPARATOR . 'templates', | |
$templatePath, | |
$templatePath . DIRECTORY_SEPARATOR . 'templates', | |
STYLESHEETPATH, // compability | |
STYLESHEETPATH . DIRECTORY_SEPARATOR . 'templates', | |
TEMPLATEPATH, // compability | |
TEMPLATEPATH . DIRECTORY_SEPARATOR . 'templates', | |
]; | |
$bladePaths = array_merge($bladePaths, $themePaths); | |
$result = preg_replace('%[\/]?(templates)?[\/.]*?$%', '', $bladePaths); | |
$result = array_unique($result); | |
return $result; | |
} | |
function view($templatePath, $data = []) | |
{ | |
$views = bladeViewPaths(); | |
$cache = realpath(wp_upload_dir()['basedir'] . '/.cache'); | |
$blade = new \eftec\bladeone\BladeOne($views, $cache, \eftec\bladeone\BladeOne::MODE_AUTO); // MODE_DEBUG allows to pinpoint troubles. | |
$result = $blade->run($templatePath, $data); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just call for "view" inside your code.
This plugin should be placed within MU-pugins.