wp_localize_script escaping my url – fix or alternative

wp_localize_script() now uses json_encode() which means a multidimensional array will now work for the passed data. And, HTML entity decoding only applies to the first level of the array. Better is an way to use json and default js possibilities from WP. At first, i add the options from the database via script and json_encode … Read more

Headless WordPress – Issue with plugin path

I understand the question and answer are from more than a year ago, but I just wanted to add some additional information in hopes it might be useful for future visitors of this Question. Recently, while setting up a Headless WordPress CMS with Roots Bedrock, I came across the same issue and solved it with … Read more

External API to WP

I’d recommend writing a simple plugin. Read through the Plugin Development Handbook, but it’s pretty easy. The only thing necessary for a plugin is the header with the Plugin Name. In the plugin, create a function that gets and stores in a WordPress transient the result of an API request. <?php /** * Plugin Name: … Read more

creating shortcode to pull json array

As per documentation on wp_remote_get() it doesn’t return you just the body of requested resource. Its return will be either the array of data or WP_Error object on failure. The simplest snippet to get to the body would be: $json = wp_remote_retrieve_body( wp_remote_get( $url ) ); PS it’s kinda weird to be doing this in … Read more

Customizer, change preview url when a control changes

Gonna have a go… say you have a theme option themeoption[id]… instead of setting transport refresh, set it to postMessage instead, and then add this code to create a callback that first gets the page URL via AJAX then sends that back to the previewUrl as you mentioned before refreshing… add_action(‘customize_preview_init,’preview_override_loader’); function preview_override_loader() { add_action(‘wp_footer’,’preview_override_script’); … Read more

How Can I Create a List of Values to Be Iterated Through via WordPress Customization API?

Assuming you have an array $locations available, you can use this code to generate a dropdown in the customizer. It’s not that different from a single value. $section_name=”wpse213980_section_name”; // adapt to your naming system $section_title=”wpse213980_section_title”; // adapt to your naming system $setting_name=”wpse213980_setting_name”; // adapt to your naming system $setting_field_type=”select”; $setting_field_options = $locations; $sanitize_callback = ‘sanitize_text_field’; … Read more

Extending WordPress REST API

There are no answers here yet, but atleast we ended up using a combination of WP REST API and WP OAuth Server. The WP REST API was really easy to work with, as it provided a common framework to respond to HTTP requests. I found it similar to ASP.NET Web API, as that’s the framework … Read more

Using API to generate short link

You never need do_shortcode(), better said, almost never, there are a few cases where do_shortcode() could be appropiate. Note how you could do just: echo shorten_url( ‘http://mylink.com ‘ ); instead of: echo do_shortcode(‘[shorten]http://mylink.com[/shorten]’); Think about shortcodes as PHP functions placeholders; they are intended to be use where you can not execute PHP directly, like the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)