Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Cannot save empty gradient

Open albertso opened this issue 9 years ago • 1 comments

Hi, I need to be able to save a page, WITHOUT putting anything in a gradient, only if user chooses to. When I save the page with no value in the gradient, it REVERTS to the default values, which are, oddly, #ff0000 and #0000ff

If I specify an empty default value the secondary input doesn't appear at all.

        'gradient' => array(
            'type'  => 'gradient',
            'value' => array(
                'primary'   => '',
                'secondary' => '',
            ),

What is the reason to not show the the secondary input here in gradient/view.php?

<?php if ( ! empty( $option['value']['secondary'] ) ): ?>

I have been doing the workaround of using a space ' ' as default value, so the input appears, but even then, the value cannot be saved empty, it saves the space ' '. I think this would resolve by simply removing the conditional, which I don't understand why is there.

I need this because I'm using post options to introduce changes to the default theme appearance, only if the user wants to. The default value has to be empty, or I cannot detect if the user intended to modify the page setting, or leave it alone. I'm parsing a whole bunch of options together, so I cannot do a special case for the gradient options.

BTW, if it is possible to save empty gradients, I propose changing the default values of the gradient to empty too. Red and blue are good as a demo for the option, but I don't think they should be the default. This last thing is just my opinion.

Cheers!

albertso avatar Jan 08 '17 05:01 albertso

What is the reason to not show the the secondary input here in gradient/view.php?

I don't know. This option-type was made by another developer long time ago.

ghost avatar Jan 09 '17 07:01 ghost