How to syntax Json output for translation?

Technically, and this is highly discouraged do to it’s unfriendly and unpredictable nature, you can do this: <?php _e( $data[‘hair’][‘type’] ); ?> However, you’ll need to have all the possible values for that (“brown hair”, “blond hair”, etc.), listed in a .POT file (a translation template) so that translators know what to translate. You’ll need … Read more

Creating a Multi-Level Associative Object Using AJAX

If you want to pass a complex value, your best path is probably to jsonify it. Something like $.post( MyAjax.ajaxurl, { action: ‘my_action’, someValue: JSON.stringify({ one: ‘Some Value One’, two: ‘Some Value Two’, three: ‘Some Value Three’, four: ‘Some Value Four’, }) } ); and then on the server side you decode the value with … Read more

Populating main menu from external JSON API

I would not bother creating a nav menu for this, I would just write a code that takes JSON as input and spits out menu markup with the data. WP’s menu data structures are quite unwieldy and aren’t too convenient to work with. There are also issues of persistence and performance (network request is usually … Read more

WordPress – Sync wordpress post with JSON feed

The important step is to assign a unique ID to every item you get from the source. Hopefully the JSON feed already includes one, but otherwise you will have to somehow create one yourself based on the JSON content. Once you have the value, you store it as a meta value of the post being … Read more

Base64 & JSON Encode array in PHP, use as HTML data attribute, decode and parse in JavaScript …. with proper Escaping

The possible output of base64_encode() contains a-zA-Z0-9+/ and possibly = or == appended. Testing with $str=”abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=”; we find that: esc_attr( $str ) === $str is true, so it looks like esc_attr() preserves base64 encoded strings. There are possible regexes to help with validation, but according to this answer by @BoltClock, we could check it with … Read more

CMB2 Repeatable Group & JSON API

Consider using the CMB2 API. <SITE_URL>/wp-json/cmb2/v1/boxes/<METABOX_ID>/fields/PhotoGalleryGroup?object_id=<POST_ID>&object_type=post You will need to enable the API feature for your box/fields. Documentation for that is in the wiki.

How to display Unicode correctly?

I’m not sure whether you are using a plugin, or you are coding it yourself. Either way, you can use server side or client side to decode or encode your content. PHP offers the utf8_decode(); and utf8_encode(); functions, that can be used to decode or encode your content before sending it to the browser, or … Read more

How can I get my options in json response?

You shouldn’t save your theme’s options one by one. In that case, you should call each of them separately, or store them in an array and then run a loop to get their values: $options = array( ‘option1’, ‘option2’, ‘option3’); foreach( $options as $option ){ // The rest of your code } But the proper … Read more