soflyy / oxygen-bugs-and-features

Bug Reports & Feature Requests for Oxygen
https://oxygenbuilder.com/
315 stars 30 forks source link

Fix for no support for square brackets and wordpress shortcodes (outside of oxygen-specific) inside custom attributes #2726

Open skogowskinetfactory opened 2 years ago

skogowskinetfactory commented 2 years ago

Description: Inside custom attributes of elements inside oxygen builder: Putting empty square brackets or anything that is not oxygen specific short codes makes the whole structural element to fail and not be shown on oxygen anymore.

This makes impossible to use those attributes with javascript frameworks like Vue - if one would require square brackets inside the attribute.

From my inspection it shows that this bug is specifically related to the fact that because those brackets are not hidden from wordpress - wordpress mistakingly takes the ending bracket as the end of oxygen structural element and then whole shortcode parsing gets broken. Oxygen hides brackets of only it's own shortcodes and nothing else.

Here are fixes that I found to fix this bug: public_html/wp-content/plugins/oxygen/component-framework/includes/tree-shortcodes.php Line 190 - hide any brackets from attributes from being saved into page content :

    if( $array_key == "custom-attributes") {
        $item['options'][$key][$array_key] =  oxygen_vsb_base64_encode(json_encode($array_value));
    }

Line 657 - decode everything so that we can edit page:

    if($array_key == "custom-attributes" && is_string($array_value)) {
        $array[$array_key] =  json_decode(oxygen_vsb_base64_decode($array_value), true);
    }

public_html/wp-content/plugins/oxygen/component-framework/component-init.php Line 5880: Replace the first conditional return with:

    if ( !isset( $options["custom_attributes"] ) || (!is_array( $options["custom_attributes"] ) && !is_string( $options["custom_attributes"])) ) {
        return "";
    }
    if(is_string( $options["custom_attributes"])) {
        $options["custom_attributes"] = json_decode(oxygen_vsb_base64_decode($options["custom_attributes"]), true);
    }

public_html/wp-content/plugins/oxygen/component-framework/components/component.class.php Line 2416 - mark custom-attributes as non-css property:

        $fake_properties = array(
                'custom-attributes',

This patch was tested on oxygen plugin version 3.8, it is also backwards compatible (it will not try to decode attributes that weren't previously encoded this way).

maltmann-muc commented 2 years ago

+1

oxyplugins commented 2 years ago

Facebook thread: https://www.facebook.com/groups/1626639680763454/posts/4784873711606686/.

skogowskinetfactory commented 2 years ago

If the above patch is applied, then this patch below from a feature request will also make possible to use wider range of characters and signs in attribute names and values :) https://github.com/soflyy/oxygen-bugs-and-features/issues/2731