Last active
September 25, 2022 11:21
-
-
Save tdrayson/391573513bf54a6b2ab6ee2d57d7fadb to your computer and use it in GitHub Desktop.
Automatically call custom functions in Generateblocks Dynamic Data
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
/* | |
* @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