Search code examples
phparrayswordpressoffsetphp-8.1

Trying to access array offset on value of type bool - PHP 8.1 - Wordpress - Mulivendorx plugin


I get this error when this code is run as a Wordpress code snippet using WP Code plugin. I'm sure it has to do with the code provided by the plugin developer being out of date, not in-line with current PHP version but I don't have the skills on how to update the code and haven't heard back from plugin developer.

--> Trying to access array offset on value of type bool

There are two parts to the code doing different things, but the error is in the second. The line of code its highlighting as the problem is where it says:

<input type="text" name="custom_text_field" class="form-control" value= <?php print_r($hh[0]) ?> />

Can anyone assist in how to update this to get avoid the error?



/** * Add Custom Tab in add product page.   
* @author WC Marketplace    * @Version 3.3.0    
*/  
function add_custom_product_data_tabs( $tabs ) 
{      
$tabs['advanced'] = array
('label'=> __( 'Delivery Time', 'your-text-domain' ),          
'target'   => 'custom_tab_product_data',
'class'=> array(),
'priority' => 100,     
);     
return $tabs;   
}   
add_filter( 'mvx_product_data_tabs', 'add_custom_product_data_tabs' );


/*** Add Custom Tab content in add product page.    
* @author WC Marketplace    
* @Version 3.3.0    
*/  
function add_custom_product_data_content( $pro_class_obj, $product, $post ) 
{     
$hh = get_post_meta($product->get_id() , '_custom_text_field' );        
?>     
<div role="tabpanel" class="tab-pane fade" id="custom_tab_product_data"><!-- just make sure tabpanel id should replace with your added tab target -->          
<div class="row-padding">              
<div class="form-group">                   
<label class="control-label col-sm-3 col-md-3">Estimated Delivery time</label>                 <div class="col-md-6 col-sm-9">                     
**<input type="text" name="custom_text_field" class="form-control" value= <?php print_r($hh[0]) ?> />**                
</div>             
</div>         
</div>     
</div>     
<?php   
}   
add_action( 'mvx_product_tabs_content', 'add_custom_product_data_content', 10, 3 );

I've tried to look up how to change this and get an idea but as I don't have the skills to change I hope someone can help :-)


Solution

  • Thank you - this gave me some good thoughts and could approach the developer confidently. I was advised to use "echo esc_attr " which seems to have resolved the issue.

     <input type="text" name="image_dimensions" class="form-control" value="<?php echo esc_attr( $image_dimensions ); ?>" />