Skip to content

[develop] Fix shortcode attributes not being parsed due to WordPress auto-lowercasing#1759

Open
KMchaudhary wants to merge 1 commit intodevelopfrom
fix/godam-video-shortcode
Open

[develop] Fix shortcode attributes not being parsed due to WordPress auto-lowercasing#1759
KMchaudhary wants to merge 1 commit intodevelopfrom
fix/godam-video-shortcode

Conversation

@KMchaudhary
Copy link
Copy Markdown
Collaborator

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.

  • 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

…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
Copilot AI review requested due to automatic review settings March 26, 2026 11:07
@KMchaudhary KMchaudhary changed the title Fix shortcode attributes not being parsed due to WordPress auto-lowercasing [develop] Fix shortcode attributes not being parsed due to WordPress auto-lowercasing Mar 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ratio instead of aspectRatio.
  • 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.

Comment on lines +185 to 205
// 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'];
}
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_key_exists() can be used to fix this

Comment on lines +185 to 205
// 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'];
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_key_exists() can be used to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants