wp_remote_get adding backslashes

wp_remote_get() returns an array containing the response headers and the response body. When you json_encode() the response, which you appear to have done, then the body is going to be escaped so that it doesn’t break the JSON it thinks you’re trying to create. You’re adding the slashes when you do this. To get the … Read more

REST : how do you handle the rest_no_route error?

I dug in the codex and found some interesting functions. This is how I finally did it : function api_request($api_url = null, $params=null,$method = ‘GET’){ if (!$api_url){ return new WP_Error(‘no_api_url’,”Missing API URL”); } //Create request $request = WP_REST_Request::from_url( $api_url ); //Method $request->set_method( $method ); //params switch($method){ case ‘GET’: $request->set_query_params($params); break; case ‘POST’: $request->set_body_params($params); break; } … Read more

Unable to parse JSON response from wp_send_json_success [closed]

In short, you should use response.data.messages. And that’s because wp_send_json_success() will send a JSON response (an object) with the property data set to whatever that you passed to the function. wp_send_json_success( 123 ); // In JS, response.data would be an integer. I.e. response.data = 123 wp_send_json_success( array( ‘foo’ => ‘bar’ ) ); // In JS, … Read more

woocommerce registration form with klaviyo(don’t work with current user)

Hey guys there are just a few changes in the above code. Check this out it works for me. Note: Please change the LIST_ID to your klaviyo’s list id, and get one private key from your klaviyo account and add it at PRIVATE_API_KEY function send_coupon_to_freshly_registered_user($user_id) { $user = get_user_by(‘id’,$user_id); //new line $user_email = stripslashes($user->user_email); //changed … Read more

Vagrantpress + composer

Unfortunately you can’t use Vagrantpress and Composer directly together easily. Half of Vagrantpress is the WordPress setup itself which isn’t compatible. If you still wanted to leverage the base work Vagrantpress has done with PHP, Apache, MySQL etc, you could fork it and modify their WP module found here: https://github.com/chad-thompson/vagrantpress/blob/master/puppet/modules/wordpress/manifests/init.pp It would still require a … Read more