Last active
December 3, 2020 19:00
-
-
Save elliottmangham/dc2ee90a8342a48fe2527531741757de to your computer and use it in GitHub Desktop.
WordPress (PHP) / Utilities / Get flexible content builder
This file contains 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
/*************** | |
* Includes the page builder file | |
* @param string $sFilePath The builder to include | |
* @param string $sFieldName ACF field name | |
* @param array $aScopeVariables An array of variables to make available in the component | |
***************/ | |
function get_builder( $sFilePath, $sFieldName = 'blocks', $aScopeVariables = [] ) { | |
ob_start(); | |
extract( $aScopeVariables, EXTR_OVERWRITE ); | |
$sTemplateSlug = sprintf( '/templates/_builders/%s.php', $sFilePath ); | |
$sTemplateLocation = locate_template( $sTemplateSlug ); | |
if ( ! is_readable( $sTemplateLocation ) ) { | |
throw new \Exception( sprintf( "Missing page builder: %s", $sFilePath ) ); | |
} | |
include $sTemplateLocation; | |
$sBuilder = ob_get_clean(); | |
echo $sBuilder; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment