Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Disable Caldera Forms form output based on some function's result.
*/
add_filter( 'caldera_forms_pre_render_form', function( $html, $entry_id, $form ){
//change to your form ID here!
if( 'CF123456789' == $form[ 'ID' ] ){
$result = some_function_that_returns_false_if_form_shouldnt_be_shown( $entry_id );
if( false == $result ){
return '<div class="alert alert-warning">Not allowed.</div>';
}
return $html;
}, 10, 3 );
<?php
/**
* When editing an entry -- switch to login if user isn't logged in.
*/
add_filter( 'caldera_forms_pre_render_form', function($html, $entry_id, $form ){
//change to your form ID here!
//check if on that form and if editing an entry
if( 'CF123456789' == $form[ 'ID' ] && ( ! is_null( $entry_id ) || isset( $_GET[ 'cf_ee' ] ) ){
//check if user is not logged in
if( ! is_user_logged_in() ){
//load a different form, say one with a login form powered by the users add-on :)
return Caldera_Forms::render_form( 'CF0987654321');
//or redirect to standard WordPress login form
auth_redirect();
}
}
return null;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.