Category: WordPress
-
Editing Terms & Term Meta with the WordPress REST API
Here are some JavaScript snippets to manipulate WP_Term objects in WordPress using the REST API and the Backbone JavaScript client library. Insert a term Delete a term This next example assumes you’ve used wp_localize_script() to make the REST API endpoint and a nonce available in an object myplugin. If you need help doing this, please…
-
What is $posted_data passed to Contact Form 7’s wpcf7_posted_data hook
For a ContactForm7 form that has this source: <div class=”wpcf7-lead-widget”>[text* contact-name maxlength:50 placeholder “Your Name (required)”] [email* email maxlength:50 placeholder “Email (required)”] [text phone maxlength:15 placeholder “Phone”] [vehicle_form_field] [textarea comments x3 placeholder “Questions and Comments”] [submit class:_button class:_button-small “Check Availability”] [hidden context id:context “contact”] [hidden do-not-send-mail]</div> The $posted_data that is passed via the wpcf7_posted_data hook…
-
Migrating a GravityView Without Losing Fields
Exporting a GravityView and importing it into a different site is easy, and there are official instructions right here. This process works very smoothly when the Gravity Forms and GravityViews on both sites are identical. That’s usually not the world I live in, however. I’m a back-end developer in sites that sometimes have multiple teams…
-
Sometimes, an array is passed to the get_callback provided to register_rest_field() instead of an object
When using register_rest_field() to add fields to terms in the WordPress REST API, the $object sent to your get_callback function will be an array instead of an object like the documentation describes. An object will still be passed, sometimes, too. Here is an example of how I work around this problem: function add_api_term_fields() { //location-phone-hours…
-
How to add an additional webhook to an Elementor Form
Elementor Pro includes a form builder widget, complete with a webhook to which all form data can be sent and a redirect URL to send users after successful submissions. I have been tasked with adding a second webhook to a form because the first was being used for an integration with Zapier. We need to…
-
WordPress REST API returns 500 error when updating serialized meta with an unchanged value
Take care when updating posts via the WordPress REST API to not send unchanged serialized meta values. The entire update will fail and return a 500 error. The JSON response looks like this: { “code”: “rest_meta_database_error”, “message”: “Could not update meta value in database.”, “data”: { “key”: “meta_key_name”, “status”: 500 } } This error comes…
-
Setting post_parent with the WordPress REST API
WordPress 4.9.4 does not support the post_parent attribute in the REST API, so I wrote a plugin that does. Download here: https://github.com/csalzano/wp-api-add-post-parent Someday, WordPress core will allow the manipulation of the post_parent attribute, and I look forward to deleting this plugin and this blog post when they become obsolete. Until then, I believe this implementation resembles…
-
Spinners and loading animations built into WooCommerce
WooCommerce is a big plugin that ships with several JavaScript loading animations. There is no reason to roll your own when you need one. This week, I am hacking on WooCommerce to convert “Add to Cart” buttons to prevent redirecting users to different pages. Here’s a great tutorial I used to accomplish this goal. Without…
-
Thickbox.js: a modal API hidden in WordPress core
Yesterday, I needed to create a modal, but I didn’t want to create a modal. “Surely, this is already in WordPress.”Corey Salzano So, I went looking for a modal in WordPress core, and I was delighted when I found one. Thickbox is JavaScript library that was created more than one decade ago and began shipping with…
-
WPEngine caches WordPress REST API GET responses
Logged out users of a website hosted at WPEngine may receive cached responses to REST API calls via the GET method. API calls work correctly while logged in, but paths in the /wp-json/ directory are cached like much like the rest of the front-end. How to prevent cached REST API responses As of June 2017,…
-
Presenting at the October Philly #burbswp meetup
I am presenting at the October Philly ‘burbs meetup @ Michael’s Deli in King of Prussia, PA. More details
-
When renaming your WP admin user, don’t neglect your comments
A few months ago, popular people in the WordPress community (including Matt) made a push to stop using the user name “admin.” A considerably-sized brute force attack targeted this user name specifically since so many users never change or create an administrator with another name. I followed the wisdom of the crowd and this post…