0

I am using a page builder called King composer for wordpress, where i am trying to build some custom functions, like is intended.

My problem is, that the build-in background color picker is base64 encoding the background properties, So i need to decode it - But first i need to decode the 'my-css' json, so that i can access the different properties.

this is the return of what i get from the builder.

array (
    '_id' => '69391',
    'image' => '294,9,16',
    'gallery-text' => 'Dette er nærmest et galleri',
    'my-css' => '{
           `kc-css`:{
                  `any`:{
                       `typography`{`color|`:`#ffffff`},
                       `background`{`background|`:`longBase64StringHere`},
                       `box`:{`margin|`:`100px inherit inherit inherit`}
                       }
                    }
                 }',
      )

So far i have tried:

 $decodedBackground = base64_decode($atts['my-css']);

which returns as null

then i tried :

 $decodedJson = json_decode($atts['my-css']);

which returns : null

Also tried some other stuff that went horriably wrong

I don't really understand it, I can access the other properties fine, since it is just a part of an array, but the CSS part, I cannot comprehend. I think I need to go deeper in - but I can't get it to work.

Been stuck for about 1.5 hours now, so any help or pointers would be appreciated

/------ EDIT -----/

So this is how i am trying to inspect the decoded json afterwards - might be important.

 $decodedJson = json_decode($atts['my-css'], true);
 echo '<pre>' . var_export($decodedJson, true) . '</pre>';
4
  • that will also return null - tried it earlier while writing my question. Commented Apr 21, 2017 at 8:54
  • Sorry the content under my-css is not a valid json.. please make sure Commented Apr 21, 2017 at 9:00
  • The value of $atts['my-css'] doesn't use a standard encoding. It is not JSON and I cannot see anything encoded using base64 in the data you posted. Commented Apr 21, 2017 at 9:03
  • Is there a way of changing the encoding, or another way of accessing the singlular values in my-css? Commented Apr 21, 2017 at 9:04

1 Answer 1

2

This is maybe not the best way to do because the JSON in kc-css is not well formated, but this code works for your case:

// Refomating JSON
$atts['my-css'] = str_replace('`{', '`:{', $atts['my-css']);
$atts['my-css'] = str_replace('`', '"', $atts['my-css']);

$json = json_decode($atts['my-css'], true);
Sign up to request clarification or add additional context in comments.

1 Comment

This works for this time - but having to do this for everytime I need a css value will be a bother. Thank you - I managed to get to the string be going echo '<pre>' . var_export($json['kc-css']['any']['background']['background|'], true) . '</pre>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.