Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active February 11, 2017 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/7a5a7aa1a865e60140355cfcb8087e8c to your computer and use it in GitHub Desktop.
Save Shelob9/7a5a7aa1a865e60140355cfcb8087e8c to your computer and use it in GitHub Desktop.
Prevent a field from being returned by Caldera Forms REST API See: https://calderaforms.com/doc/caldera_forms_api_show_field/
<?php
/**
* Don't return email fields in Caldera Forms REST API responses.
*
* Will affect front-end entry viewer
*/
add_filter( 'caldera_forms_api_show_field', function( $show, $field_id, $field, $form ){
if( 'email' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$show = false;
}
return $show;
}, 10, 4 );
<?php
/**
* Don't return a field, with a given ID, in Caldera Forms REST API responses.
*
* Will affect front-end entry viewer
*/
add_filter( 'caldera_forms_api_show_field', function( $show, $field_id ){
if( 'fld_9970286' ==$field_id ){
return false;
}
return true;
}, 10, 2 );
<?php
/**
* Don't show any fields in API requests for forms
*
* Will probably break front-end entry viewer
*/
add_filter( 'caldera_forms_api_show_field', function( $show, $field_id, $field, $form, WP_REST_Request $request ){
if( 0 === strpos( $request->get_route(), '/cf-api/v2/forms/' ) ){
return false;
}
return $show;
}, 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment