Support Forum
Having a bit of trouble creating a new custom block in WPGB that wraps a 'mailto link' around the MetaBox email string. This is so that the Card in WPGB has an active hyperlink for the email string coming from MB.
https://docs.wpgridbuilder.com/resources/filter-blocks/#email-block has some code where I can build a filter but this code is causing fatal error
add_filter( 'wp_grid_builder/blocks', 'register_custom_field_email_block' );
function render_custom_field_email_block() {
// Object can be a post, term or user.
$object = wpgb_get_object();
// If this is not a post (you may change this condition for user or term).
if ( ! isset( $object->post_type ) ) {
return;
}
// You have to change "custom_field_name" by yours.
$email = get_post_meta( $object->ID, 'email_2pj4peaeikf', true );
if ( empty( $email ) ) {
return;
}
$email = antispambot( $email );
printf(
'<a href="%s">%s</a>',
esc_url( 'mailto:' . $email ),
esc_html( $email )
);
}
Any help would be appreciated & thanks in advance
Hi Clinton,
Can you please share the fatal error message on your site?
Hello there Long,
I don't think it would be a factor, but, the website is on a roots.io stack. You will see the directory structure and the file I am running in the WinSCP FTP client.
The code Metabox.io supplied in https://metabox.io/create-simple-listing-meta-box-wp-grid-builder/ for the Image block worked for me.
In fact, any solution here would add value to your post https://metabox.io/create-simple-listing-meta-box-wp-grid-builder/ as the cards may have an email address end-users may want to click on.
Thank you,
Clint
Hi,
You can enable WP Debug to get the error log and share it here https://wordpress.org/support/article/debugging-in-wordpress/
It will help us to know what's wrong with your site.
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "register_custom_field_email_block" not found or invalid function name in /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php:307 Stack trace: #0 /var/www/intranetpreview/html/site/web/wp/wp-includes/plugin.php(191): WP_Hook->apply_filters(Array, Array) #1 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/blocks/base.php(719): apply_filters('wp_grid_builder...', Array) #2 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(515): wpgb_custom_block(Array, Array) #3 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(474): WP_Grid_Builder\FrontEnd\Cards->do_blocks(Array) #4 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(448): WP_Grid_Builder\FrontEnd\Cards->do_layer(Array, 'body') #5 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(473): WP_Grid_Builder\FrontEnd\Cards->do_layers(Array) #6 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(448): WP_Grid_Builder\FrontEnd\Cards->do_layer(Array, 'content') #7 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(473): WP_Grid_Builder\FrontEnd\Cards->do_layers(Array) #8 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(448): WP_Grid_Builder\FrontEnd\Cards->do_layer(Array, 'inner') #9 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(413): WP_Grid_Builder\FrontEnd\Cards->do_layers(Array) #10 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(388): WP_Grid_Builder\FrontEnd\Cards->do_card(Array) #11 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-cards.php(230): WP_Grid_Builder\FrontEnd\Cards->process(Array) #12 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-loop.php(123): WP_Grid_Builder\FrontEnd\Cards->render(Array, 'masonry') #13 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/functions/layout.php(25): WP_Grid_Builder\FrontEnd\Loop->run() #14 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php(307): wpgb_layout_do_loop('') #15 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array) #16 /var/www/intranetpreview/html/site/web/wp/wp-includes/plugin.php(476): WP_Hook->do_action(Array) #17 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/templates/layout/layout.php(29): do_action('wp_grid_builder...') #18 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/includes/class-helpers.php(1237): require('/var/www/intran...') #19 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-layout.php(159): WP_Grid_Builder\Includes\Helpers::get_template('/templates/layo...') #20 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/class-layout.php(74): WP_Grid_Builder\FrontEnd\Layout->do_templates() #21 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/frontend/functions/grids.php(93): WP_Grid_Builder\FrontEnd\Layout->render() #22 /var/www/intranetpreview/html/site/web/app/plugins/wp-grid-builder/includes/class-gutenberg.php(239): wpgb_render_grid(Array) #23 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-block.php(255): WP_Grid_Builder\Includes\Gutenberg->render_grid(Array, '', Object(WP_Block)) #24 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-block.php(241): WP_Block->render() #25 /var/www/intranetpreview/html/site/web/wp/wp-includes/blocks.php(901): WP_Block->render() #26 /var/www/intranetpreview/html/site/web/wp/wp-includes/blocks.php(939): render_block(Array) #27 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php(307): do_blocks('<!-- wp:group -...') #28 /var/www/intranetpreview/html/site/web/wp/wp-includes/plugin.php(191): WP_Hook->apply_filters('<!-- wp:group -...', Array) #29 /var/www/intranetpreview/html/site/web/wp/wp-includes/post-template.php(253): apply_filters('the_content', '<!-- wp:group -...') #30 /var/www/intranetpreview/html/site/web/app/uploads/cache/5d5ec0d5b53c4710105326d6417927254ac47daf.php(1): the_content() #31 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/var/www/intran...') #32 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/intran...', Array) #33 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/var/www/intran...', Array) #34 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents() #35 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents() #36 /var/www/intranetpreview/html/site/web/app/uploads/cache/8297a03cbdd25cdc1a8439f56c4db3d3462e6026.php(3): Illuminate\View\View->render() #37 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/var/www/intran...') #38 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/intran...', Array) #39 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/var/www/intran...', Array) #40 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents() #41 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents() #42 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/roots/sage-lib/Template/Blade.php(58): Illuminate\View\View->render() #43 /var/www/intranetpreview/html/site/web/app/themes/efwp/app/helpers.php(55): Roots\Sage\Template\Blade->render('/var/www/intran...', Array) #44 /var/www/intranetpreview/html/site/web/app/themes/efwp/app/filters.php(108): App\template('/var/www/intran...', Array) #45 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php(307): App\{closure}('/var/www/intran...') #46 /var/www/intranetpreview/html/site/web/wp/wp-includes/plugin.php(191): WP_Hook->apply_filters('/var/www/intran...', Array) #47 /var/www/intranetpreview/html/site/web/wp/wp-includes/template-loader.php(104): apply_filters('template_includ...', '/var/www/intran...') #48 /var/www/intranetpreview/html/site/web/wp/wp-blog-header.php(19): require_once('/var/www/intran...') #49 /var/www/intranetpreview/html/site/web/index.php(5): require('/var/www/intran...') #50 {main} Next ErrorException: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "register_custom_field_email_block" not found or invalid function name (View: /var/www/intranetpreview/html/site/web/app/themes/efwp/resources/views/partials/content-page.blade.php) in /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php:307 Stack trace: #0 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/PhpEngine.php(47): Illuminate\View\Engines\CompilerEngine->handleViewException(Object(Symfony\Component\Debug\Exception\FatalThrowableError), 3) #1 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/intran...', Array) #2 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/var/www/intran...', Array) #3 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents() #4 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents() #5 /var/www/intranetpreview/html/site/web/app/uploads/cache/8297a03cbdd25cdc1a8439f56c4db3d3462e6026.php(3): Illuminate\View\View->render() #6 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/PhpEngine.php(43): include('/var/www/intran...') #7 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/intran...', Array) #8 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/var/www/intran...', Array) #9 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents() #10 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents() #11 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/roots/sage-lib/Template/Blade.php(58): Illuminate\View\View->render() #12 /var/www/intranetpreview/html/site/web/app/themes/efwp/app/helpers.php(55): Roots\Sage\Template\Blade->render('/var/www/intran...', Array) #13 /var/www/intranetpreview/html/site/web/app/themes/efwp/app/filters.php(108): App\template('/var/www/intran...', Array) #14 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php(307): App\{closure}('/var/www/intran...') #15 /var/www/intranetpreview/html/site/web/wp/wp-includes/plugin.php(191): WP_Hook->apply_filters('/var/www/intran...', Array) #16 /var/www/intranetpreview/html/site/web/wp/wp-includes/template-loader.php(104): apply_filters('template_includ...', '/var/www/intran...') #17 /var/www/intranetpreview/html/site/web/wp/wp-blog-header.php(19): require_once('/var/www/intran...') #18 /var/www/intranetpreview/html/site/web/index.php(5): require('/var/www/intran...') #19 {main} Next ErrorException: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "register_custom_field_email_block" not found or invalid function name (View: /var/www/intranetpreview/html/site/web/app/themes/efwp/resources/views/partials/content-page.blade.php) (View: /var/www/intranetpreview/html/site/web/app/themes/efwp/resources/views/partials/content-page.blade.php) in /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php:307 Stack trace: #0 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/PhpEngine.php(45): Illuminate\View\Engines\CompilerEngine->handleViewException(Object(ErrorException), 1) #1 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/var/www/intran...', Array) #2 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/var/www/intran...', Array) #3 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents() #4 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents() #5 /var/www/intranetpreview/html/site/web/app/themes/efwp/vendor/roots/sage-lib/Template/Blade.php(58): Illuminate\View\View->render() #6 /var/www/intranetpreview/html/site/web/app/themes/efwp/app/helpers.php(55): Roots\Sage\Template\Blade->render('/var/www/intran...', Array) #7 /var/www/intranetpreview/html/site/web/app/themes/efwp/app/filters.php(108): App\template('/var/www/intran...', Array) #8 /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php(307): App\{closure}('/var/www/intran...') #9 /var/www/intranetpreview/html/site/web/wp/wp-includes/plugin.php(191): WP_Hook->apply_filters('/var/www/intran...', Array) #10 /var/www/intranetpreview/html/site/web/wp/wp-includes/template-loader.php(104): apply_filters('template_includ...', '/var/www/intran...') #11 /var/www/intranetpreview/html/site/web/wp/wp-blog-header.php(19): require_once('/var/www/intran...') #12 /var/www/intranetpreview/html/site/web/index.php(5): require('/var/www/intran...') #13 {main} thrown in /var/www/intranetpreview/html/site/web/wp/wp-includes/class-wp-hook.php on line 307
Cheers Long!
Hi,
The callback function is not valid, you need to change it from render_custom_field_email_block()
to register_custom_field_email_block()
Thanks heaps Long 🙂