[develop] Fix shortcode attributes not being parsed due to WordPress auto-lowercasing#1759
[develop] Fix shortcode attributes not being parsed due to WordPress auto-lowercasing#1759KMchaudhary wants to merge 1 commit intodevelopfrom
Conversation
…casing WordPress lowercases all shortcode attribute names via strtolower(), so camelCase keys like aspectRatio, hoverSelect, showShareButton in shortcode_atts() defaults never matched the incoming attributes. - Use snake_case as the primary shortcode attribute format - Add lowercased keys (aspectratio, hoverselect, showsharebutton) for backward compatibility with existing camelCase usage - Map both forms to camelCase for internal template/JS consumption - Update shortcode strings in Fluent Forms and Gravity Forms integrations
There was a problem hiding this comment.
Pull request overview
This PR fixes GoDAM’s [godam_video] shortcode attribute parsing when users provide camelCase attributes, which WordPress auto-lowercases, by standardizing on snake_case while keeping backward compatibility and normalizing values for internal template/JS usage.
Changes:
- Updates
[godam_video]default attributes to use snake_case, adds lowercased legacy keys, and maps both to internal camelCase keys. - Updates Gravity Forms and Fluent Forms integrations to emit
aspect_ratioinstead ofaspectRatio. - Preserves backward compatibility for previously used camelCase attributes by supporting their lowercased equivalents.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
inc/classes/shortcodes/class-godam-player.php |
Adds legacy lowercased defaults and maps legacy/snake_case attributes into internal camelCase keys used by templates/JS. |
inc/classes/gravity-forms/class-gf-field-godam-video.php |
Switches shortcode output to use aspect_ratio attribute name. |
inc/classes/fluentforms/fields/class-recorder-field.php |
Switches shortcode output to use aspect_ratio attribute name. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Map shortcode attributes to camelCase for internal/JS use. | ||
| // WordPress lowercases all shortcode attribute names, so camelCase attributes like | ||
| // aspectRatio become 'aspectratio'. We keep both the lowercased form (backward compat) | ||
| // and the snake_case form (preferred), with the old form taking priority when set. | ||
| if ( '' !== $attributes['aspectratio'] ) { | ||
| $attributes['aspectRatio'] = $attributes['aspectratio']; | ||
| } else { | ||
| $attributes['aspectRatio'] = $attributes['aspect_ratio']; | ||
| } | ||
| if ( isset( $attributes['hover_select'] ) && '' !== $attributes['hover_select'] && ( ! isset( $attributes['hoverSelect'] ) || 'none' === $attributes['hoverSelect'] ) ) { | ||
|
|
||
| if ( 'none' !== $attributes['hoverselect'] ) { | ||
| $attributes['hoverSelect'] = $attributes['hoverselect']; | ||
| } else { | ||
| $attributes['hoverSelect'] = $attributes['hover_select']; | ||
| } | ||
| if ( isset( $attributes['show_share_button'] ) && '' !== $attributes['show_share_button'] && ( ! isset( $attributes['showShareButton'] ) || false === $attributes['showShareButton'] ) ) { | ||
|
|
||
| if ( false !== $attributes['showsharebutton'] ) { | ||
| $attributes['showShareButton'] = $attributes['showsharebutton']; | ||
| } else { | ||
| $attributes['showShareButton'] = $attributes['show_share_button']; | ||
| } |
There was a problem hiding this comment.
The mapping logic uses default-value comparisons (e.g. '' !== $attributes['aspectratio'], 'none' !== $attributes['hoverselect'], false !== $attributes['showsharebutton']) to decide which attribute variant should take precedence. Because shortcode_atts() merges defaults, this can’t distinguish “user explicitly passed the old key with the default value” from “key not provided”, so the preferred/snake_case key may incorrectly override an explicitly provided backward-compat key (e.g. hoverSelect="none" + hover_select="start-preview" ends up as start-preview). Consider basing precedence on the original $atts presence (e.g. array_key_exists('hoverselect', $atts) / array_key_exists('hover_select', $atts)) rather than comparing against defaults, so “old form takes priority when set” is always honored.
There was a problem hiding this comment.
array_key_exists() can be used to fix this
| // Map shortcode attributes to camelCase for internal/JS use. | ||
| // WordPress lowercases all shortcode attribute names, so camelCase attributes like | ||
| // aspectRatio become 'aspectratio'. We keep both the lowercased form (backward compat) | ||
| // and the snake_case form (preferred), with the old form taking priority when set. | ||
| if ( '' !== $attributes['aspectratio'] ) { | ||
| $attributes['aspectRatio'] = $attributes['aspectratio']; | ||
| } else { | ||
| $attributes['aspectRatio'] = $attributes['aspect_ratio']; | ||
| } | ||
| if ( isset( $attributes['hover_select'] ) && '' !== $attributes['hover_select'] && ( ! isset( $attributes['hoverSelect'] ) || 'none' === $attributes['hoverSelect'] ) ) { | ||
|
|
||
| if ( 'none' !== $attributes['hoverselect'] ) { | ||
| $attributes['hoverSelect'] = $attributes['hoverselect']; | ||
| } else { | ||
| $attributes['hoverSelect'] = $attributes['hover_select']; | ||
| } | ||
| if ( isset( $attributes['show_share_button'] ) && '' !== $attributes['show_share_button'] && ( ! isset( $attributes['showShareButton'] ) || false === $attributes['showShareButton'] ) ) { | ||
|
|
||
| if ( false !== $attributes['showsharebutton'] ) { | ||
| $attributes['showShareButton'] = $attributes['showsharebutton']; | ||
| } else { | ||
| $attributes['showShareButton'] = $attributes['show_share_button']; | ||
| } |
There was a problem hiding this comment.
array_key_exists() can be used to fix this
Fix shortcode attributes not being parsed due to WordPress auto-lowercasing
WordPress lowercases all shortcode attribute names via strtolower(), so camelCase keys like aspectRatio, hoverSelect, and showShareButton in shortcode_atts() defaults never matched the incoming attributes.