Skip to content

Instantly share code, notes, and snippets.

@tdrayson
Last active September 25, 2022 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdrayson/391573513bf54a6b2ab6ee2d57d7fadb to your computer and use it in GitHub Desktop.
Save tdrayson/391573513bf54a6b2ab6ee2d57d7fadb to your computer and use it in GitHub Desktop.
Automatically call custom functions in Generateblocks Dynamic Data
/*
* @function Automatically call custom functions in Generateblocks Dynamic Data
* @author Taylor Drayson
* @since 22/09/2022
*
* Replace $key with your unique prefix for all custom functions
*/
add_filter( 'generateblocks_dynamic_content_output', function( $content, $attributes ) {
if ( 'post-meta' === $attributes['dynamicContentType'] && isset( $attributes['metaFieldName'] ) ) {
$key = 'tct'; // Replace with your unique key
$match = preg_match('#^'.$key.'(.*)$#i', $attributes['metaFieldName']);
if($match){
return call_user_func($attributes['metaFieldName']);
}
}
return $content;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment