Using register_setting() and the REST API

Here is a comment I just requested be added to the bottom of the register_setting() page. If you plan to use your setting in the REST API, use both the rest_api_init and admin_init hooks when calling register_setting() instead of just admin_init. The show_in_rest argument is ineffective when hooked into admin_init alone. Corey Salzano Someday, when my comment is approved, you’ll be able to see it on… Continue reading Using register_setting() and the REST API

Published
Categorized as 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… Continue reading Editing Terms & Term Meta with the WordPress REST API

Published
Categorized as WordPress

Disable tooltips on The Events Calendar month view

Here is a file you could save in wp-content/your-theme/tribe-events/month/content.php that will disable tooltips on the month view calendar produced by The Events Calendar plugin. This is a template override for the month view that adds a few lines of JavaScript to remove some event handlers, and it removes a call loading the tooltip template. The… Continue reading Disable tooltips on The Events Calendar month view

Published
Categorized as WordPress

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… Continue reading What is $posted_data passed to Contact Form 7’s wpcf7_posted_data hook

Published
Categorized as WordPress

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… Continue reading Migrating a GravityView Without Losing Fields

Published
Categorized as WordPress

How to remove the “Go Back” link from GravityView single entry

The easiest way to remove the “Go Back” link from the single entry view of any GravityView is to enter a single space into the Back Link Label setting field under the view’s settings. I tried to find an appropriate hook for more than a handful of minutes and failed. If it’s stupid and it… Continue reading How to remove the “Go Back” link from GravityView single entry

Published
Categorized as WordPress

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… Continue reading Sometimes, an array is passed to the get_callback provided to register_rest_field() instead of an object

Published
Categorized as WordPress

How to sort by multiple fields in GFAPI::get_entries()

You can’t. It’s not possible in Gravity Forms 2.3. Do this instead. The third parameter to get_entries() is not designed to accept more than one sort field. Use array_multisort() to sort the array output of get_entries() like this: $entries = GFAPI::get_entries( 22, ”, null ); //form #22 Tournament team registration $sort = array(); foreach( $entries… Continue reading How to sort by multiple fields in GFAPI::get_entries()

Published
Categorized as WordPress

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… Continue reading WordPress REST API returns 500 error when updating serialized meta with an unchanged value

Published
Categorized as WordPress

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… Continue reading Setting post_parent with the WordPress REST API

Published
Categorized as WordPress