Skip to content

fix: Remove redundant location parameter check in SVG icon shortcode#131

Open
kausaralm wants to merge 1 commit intooceanwp:masterfrom
kausaralm:fix/issue-116-svg-location-parameter
Open

fix: Remove redundant location parameter check in SVG icon shortcode#131
kausaralm wants to merge 1 commit intooceanwp:masterfrom
kausaralm:fix/issue-116-svg-location-parameter

Conversation

@kausaralm
Copy link

Summary

This PR fixes #116 by removing redundant conditional logic in the SVG icon shortcode that was causing the location parameter to behave unexpectedly.

Problem

In Ocean Extra v2.4.7, the location attribute handling was refactored to use filter_var() for boolean conversion. However, the code retained an unnecessary if/else block that was checking string values instead of booleans:

// filter_var already converts to boolean
$attr['location'] = filter_var( $attr['location'], FILTER_VALIDATE_BOOLEAN );

// This block was redundant - just re-assigning the same boolean value
if ( isset($attr['location']) && $attr['location'] === true ) {
    $location = true;
} else if ( isset($attr['location']) && $attr['location'] === false ) {
    $location = false;
}

The conditional block served no purpose since filter_var() already returns a boolean value.

Solution

Remove the redundant conditional block and directly assign the converted value:

$attr['location'] = filter_var( $attr['location'], FILTER_VALIDATE_BOOLEAN );
$location = $attr['location'];

Code Changes

Before (11 lines)

$attr['location']    = filter_var( $attr['location'], FILTER_VALIDATE_BOOLEAN );
$attr['area_hidden'] = filter_var( $attr['area_hidden'], FILTER_VALIDATE_BOOLEAN );
$attr['fallback']    = filter_var( $attr['fallback'], FILTER_VALIDATE_BOOLEAN );

if ( isset($attr['location']) && $attr['location'] === true ) {
    $location = true;
} else if ( isset($attr['location']) && $attr['location'] === false ) {
    $location = false;
}

if ( true === $location ) {

After (7 lines)

$attr['location']    = filter_var( $attr['location'], FILTER_VALIDATE_BOOLEAN );
$attr['area_hidden'] = filter_var( $attr['area_hidden'], FILTER_VALIDATE_BOOLEAN );
$attr['fallback']    = filter_var( $attr['fallback'], FILTER_VALIDATE_BOOLEAN );

$location = $attr['location'];

if ( true === $location ) {

Why This Helps Users

Non-technical users rely on shortcodes working as documented. When the location parameter is ignored or always returns true, users cannot control whether the shortcode uses ocean_svg() or oceanwp_icon() functions. This fix restores the expected behavior:

  • [oceanwp_icon icon="example" location="true"] - Uses ocean_svg()
  • [oceanwp_icon icon="example" location="false"] - Uses oceanwp_icon()

Testing

  1. Use [oceanwp_icon icon="icon-class" location="true"] - Verify it calls ocean_svg()
  2. Use [oceanwp_icon icon="icon-class" location="false"] - Verify it calls oceanwp_icon()
  3. Use [oceanwp_icon icon="icon-class"] without location - Verify it defaults to ocean_svg() (location=true)

Checklist

  • Minimal code change (removed 5 redundant lines, added 1 assignment)
  • No new dependencies
  • Follows existing code style
  • Backward compatible

Fixes oceanwp#116 - The filter_var() already converts the location attribute
to a boolean, making the subsequent if/else block unnecessary. This
simplification removes 5 redundant lines and directly assigns the
already-converted boolean value.
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.

After the 2.4.7 update, the SVG icon shortcode location parameter is always true

1 participant