plugins – Shortcode cannot parse attributes within double quotes. ” is becoming ” breaking my shortcode

Question

I made a plugin that creates a shortcode to calculate the time since a particular date in the past. It has two attributes, a date string and units:

function timesince_shortcode($atts) {
    $atts = shortcode_atts(array(
        'date' => '',
        'units' => 'years',
    ), $atts);
    
    if (empty($atts['date'])) {
        return '';
    }
    
    // Convert date string to DateTime object
    try {
        $date = DateTime::createFromFormat('d/m/Y', $atts['date']);
    } catch (Exception $e) {
        // Display warning if the date format is incorrect
        trigger_error('Invalid date format. Please use the format dd/mm/yyyy.', E_USER_WARNING);
        return '';
    }

I use the shortcode like so: [timesince date="1/1/2003" units="years"]

I place it inside a text paragraph and it gives me the years since that date. The shortcode was working perfectly fine for a couple of weeks until now, where my website gave me a critical error.

I can provide the full stack trace if needed but the error in WordPress’ email was:

Uncaught Exception: DateTime::__construct(): Failed to parse time string (13/04/2023) at position 0 (1): Unexpected character in /home2/REDACTED/public_html/wp-content/plugins/time-since-date/timesince-plugin.php:37

I deactivated the plugin and noticed that the double quotes in the shortcode were messed up. I typed it as [timesince date="1/1/2003" units="years"] but it ended up as [timesince date=”1/1/2003″ units=”years”] (see screenshot here).

I think this is the problem. How or why is this happening? Why now, and can I fix it?

(I’m using Elementor 3.12.1/Pro 3.12.2).

0
Sidewinder 2 months 2023-04-13T15:45:26-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse