I have just upgraded to php8 and my error log has a lot of warnings about an undefined array key in code that sets up a custom post type.
A snippet from this CPT code is:
function create_custom( $cpt = array() ) {
register_post_type($cpt['post_type'], array(
'label' => __($cpt['label'], 'kbo'),
'description' => __($cpt['description'], 'kbo'),
'public' => true,
'show_ui' => true,
'show_in_menu' => $cpt['show_in_menu'],
'capability_type' => 'post',
The line causing the warning is 'show_in_menu'
How can I define this so that the warning stops?
CodePudding user response:
You can check $cpt array, but print_r($cpt) if $cpt array dont have show_in_menu then you can directly place true or false depending on your output.