Saltar navegación

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

This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Nigel 3 years, 4 months ago.

Autor
Mensajes
#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
Colaborador

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+01: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');

El debate ‘[Cerrado] Error when editing Block Template in View since PHP 8.0’ está cerrado y no admite más respuestas.