Skip Navigation

[Closed] Error when editing Block Template in View since PHP 8.0

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 1 year, 11 months ago.

Author
Posts
#2550989

Trying to edit View "WO Shows with Month Separators"
When entering the Template Block Editor we get the following error:

Fatal error: Uncaught Error: date(): Argument #2 ($timestamp) must be of type ?int, string given
in \functions.php on line 118 which relates to custom date function:

// Add Shortcode
function convert_date2( $atts ) {

// Attributes
$atts = shortcode_atts(
array(
'timestamp' => '',
),
$atts
);

$date = date('D d M y \a\t g:ia',$atts['timestamp']); ***Error here

return $date;

}
add_shortcode( 'convert_date2', 'convert_date2' );

#2551149

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Ian

That looks like you added some custom code to your site to register a custom shortcode, and with PHP 8 it is enforcing the date function attribute types.

You can coerce the string to be an integer (as required) by simply adding (int) before the problem attributes, i.e.

// Add Shortcode
function convert_date2($atts)
{
    // Attributes
    $atts = shortcode_atts(
        array(
            'timestamp' => '',
        ),
        $atts
    );

    $date = date('D d M y \a\t g:ia', (int) $atts['timestamp']);

    return $date;

}
add_shortcode('convert_date2', 'convert_date2');

The topic ‘[Closed] Error when editing Block Template in View since PHP 8.0’ is closed to new replies.