Last active
August 29, 2015 14:02
-
-
Save stephywells/fb60fc55adb212cb0dd8 to your computer and use it in GitHub Desktop.
Formidable snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
// Add this to your theme functions.php or a new plugin | |
// to add a list of predefined choices on the bulk options popup. | |
add_filter('frm_bulk_field_choices', 'add_custom_frm_options'); | |
function add_custom_frm_options($opts){ | |
// change 'Set Name' to whatever label you want shown on the left side of the bulk field options popup | |
// add each option to the array | |
$opts['Set Name'] = array('Option 1', 'Option 2', 'Option 3'); | |
return $opts; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
// Add this to your theme functions.php or a new plugin | |
// to automatically delete files when an entry is deleted. | |
add_action('frm_before_destroy_entry', 'delete_entry_uploads', 10, 2); | |
function delete_entry_uploads( $entry_id, $entry = false ) { | |
if ( empty( $entry ) ) { | |
$entry = FrmEntry::getOne( $entry_id ); | |
} | |
if ( empty( $entry ) ) { | |
// If there is no entry, don't continue checking for files | |
return; | |
} | |
$upload_fields = FrmField::getAll(array('fi.type' => 'file', 'fi.form_id' => $entry->form_id)); | |
foreach ( $upload_fields as $upload_field ) { | |
$media_id = FrmEntryMeta::get_entry_meta_by_field($entry->id, $upload_field->id); | |
if ( !$media_id && $entry->post_id ) { //if this is a post field, get the value | |
if ( !isset($upload_field->field_options['post_field']) ) { | |
$upload_field->field_options['post_field'] = ''; | |
} | |
if ( !isset($upload_field->field_options['custom_field']) ) { | |
$upload_field->field_options['custom_field'] = ''; | |
} | |
if ( $upload_field->field_options['post_field'] ) { | |
$media_id = FrmProEntryMetaHelper::get_post_value( | |
$entry->post_id, $upload_field->field_options['post_field'], | |
$upload_field->field_options['custom_field'], array('type' => 'file') | |
); | |
} | |
} | |
if ( !$media_id ) { | |
continue; | |
} | |
$media_id = maybe_unserialize($media_id); | |
if ( is_numeric($media_id) ) { | |
wp_delete_attachment($media_id, true); | |
} else if ( is_array($media_id) ) { | |
foreach ( $media_id as $m ) { | |
if ( is_numeric($m) ) { | |
wp_delete_attachment($m, true); | |
} | |
} | |
} | |
unset($upload_field, $media_id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Since 1.07.02, the preview form links have been formatted differently | |
* for better performance. But if those old links must still be used, | |
* you can add a bit of old code to your theme functions.php, a new plugin, | |
* or in the Code Snippets plugin. | |
*/ | |
add_action('init', 'parse_standalone_request', 40); | |
function parse_standalone_request(){ | |
$plugin = FrmAppHelper::get_param('plugin'); | |
$action = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; | |
$action = FrmAppHelper::get_param($action); | |
$controller = FrmAppHelper::get_param('controller'); | |
if( !empty($plugin) and $plugin == 'formidable' and !empty($controller) ){ | |
if($controller == 'forms') | |
FrmFormsController::preview(FrmAppHelper::get_param('form')); | |
else | |
do_action('frm_standalone_route', $controller, $action); | |
do_action('frm_ajax_'. $controller .'_'. $action); | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment