Getting error with $callback function using the WP code lite plugin
- This topic has 1 reply, 2 voices, and was last updated 1 year, 3 months ago by
Peter.
-
AuthorPosts
-
February 1, 2024 at 6:42 PM #44451
Gene Teigland
ParticipantHi Support,
I have created the qubely block using the meta box custom field group and under the 'Block Render Settings' I used the PHP callback function with 'hero_get_data' and for rendering the value of this block I am using the WP code lite plugin to create the function hero_get_data ().It was working fine before updating the WP code lite plugin with 'Version 2.1.2'but after updating this plugin, metabox gave an error for the callback function, and the site is not working.
Here is the error text:
PHP Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, function "hero_get_data" not found or invalid function name in /disk2/thechicagoschool.edu/dev.thechicagoschool.edu/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-blocks/src/Block.php:144Also, it is working fine if I use the functions.php file to render the block value.
Here is my php code:
<?php
function hero_get_data( $attributes, $is_preview = false, $post_id = null ) {
$background_image = '';
$title = '';
$subtitle = '';
$button_title = '';
$button_url = '';if ( isset( $attributes['data']['background_image'] ) && ( $attributes['data']['background_image'] ) !=''){
$background_image = wp_get_attachment_image_url( $attributes['data']['background_image'], 'full' );
}if ( isset( $attributes['data']['hero_title'] ) && ( $attributes['data']['hero_title'] ) !=''){
$title = $attributes['data']['hero_title'];
}if ( isset( $attributes['data']['hero_subtitle'] ) && ( $attributes['data']['hero_subtitle'] ) !=''){
$subtitle = $attributes['data']['hero_subtitle'];
}if ( isset( $attributes['data']['button_title'] ) && ( $attributes['data']['button_title'] ) !=''){
$button_title = $attributes['data']['button_title'];
}if ( isset( $attributes['data']['button_url'] ) && ( $attributes['data']['button_url'] ) !=''){
$button_url = $attributes['data']['button_url'];}
if ($button_url != '' && $button_title != ''){
$button_div = ''.$button_title.'';
}else{
$button_div = '';
}
$breadcrumb = do_shortcode('[mbv name="page-breadcrumb"]');
$output='';
$output.='<div class="hero-banner" style="background-image:url('.$background_image.');">
<div class="container">
'.$breadcrumb.'
<div class="row">
<div class="col-lg-8 col-md-12 col-sm-12">
<h1>'.$title.'</h1>
<p>'.$subtitle.'</p>'.$button_div.' </div>
</div>
</div>
</div>';echo $output;
}So meta box is not supporting the latest version of the WP code lite plugin.
Please provide the solution for this.
Thank you
February 1, 2024 at 9:28 PM #44453Peter
ModeratorHello,
Meta Box functions are executed at
init
hook with priority 20. If you use a code editor plugin, you can try to run the snippet at theinit
hook with a priority later than 20 and recheck the issue.
Otherwise, please contact that plugin support to get further assistance. -
AuthorPosts
- You must be logged in to reply to this topic.