WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 8 months ago

#46412 new enhancement

Make shortcode attributes case-insensitive? shortcode_parse_atts

Reported by: michael.ecklund Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.1
Component: Shortcodes Keywords:
Focuses: Cc:
PR Number:

Description

When specifying default attributes in the callback function of my registered shortcode:

<?php
function some_shortcode_callback( $user_attributes = array() ) {

        $default_attributes = array(
                'someShortcodeAttribute'  => null,
        );
        
        $attributes = shortcode_atts( $default_attributes, $user_attributes );

        print_r($default_attributes);
        print_r($user_attributes);
        print_r($attributes);

        // ....

}

If the user requested this:

[some_shortcode someShortcodeAttribute="test"]

I would expect this:

Array
(
    [someShortcodeAttribute] => 
)

Array
(
    [someShortcodeAttribute] => test
)

Array
(
    [someShortcodeAttribute] => test
)

but instead, I'm getting this:

Array
(
    [someShortcodeAttribute] => 
)

Array
(
    [someshortcodeattribute] => test
)

Array
(
    [someShortcodeAttribute] => 
)

This would always produce the default shortcode attribute and never honor the user specified shortcode attribute.

Which, in my opinion, is wrong. The user requested a camel-case shortcode attribute and the shortcode was built to accept camel-case shortcode attributes. The result should be a parsed camel-case array key and respective value pair.

Can we remove the strtolower calls on the shortcode attributes?

Change History (1)

#1 @joyously
8 months ago

At this late date, it would break more sites to remove it than it would to "fix" something.
Besides, it's documented on https://codex.wordpress.org/Shortcode_API
"Attribute names are always converted to lowercase before they are passed into the handler function. Values are untouched."
so your expectation as stated is incorrect.

Note: See TracTickets for help on using tickets.