Skip to content

Instantly share code, notes, and snippets.

@ouija
Last active October 22, 2021 07:34
Show Gist options
  • Save ouija/2c47fe614cfbbf1ee08a39b769baa3de to your computer and use it in GitHub Desktop.
Save ouija/2c47fe614cfbbf1ee08a39b769baa3de to your computer and use it in GitHub Desktop.
// Override Ninja Forms v3.6.1+ submissions page and make select list to redirect to post editor
function override_nf_submissions() {
if (is_admin() && !defined( 'DOING_AJAX' ) && $_GET['page'] == "nf-submissions") {
if (is_numeric($_GET['form_id'])) header("Location: edit.php?post_status=all&post_type=nf_sub&form_id=".$_GET['form_id']."&nf_form_filter&paged=1");
?>
<script>
jQuery(function($) {
$('#inspector-select-control-0').replaceWith($('#inspector-select-control-0').clone());
$('#nf-submissions-element > div > div.tablenav.top > div > div.nf_form_filter_container').remove();
$(document).on('change','#inspector-select-control-0', function(e) {
if (this.value !== '0') {
$('#the-list > tr > td').html('Loading submissions for <b>'+$.trim($(this).find("option:selected").text())+'</b>, please wait...');
window.location.href = 'edit.php?post_status=all&post_type=nf_sub&form_id='+$(this).val()+'&nf_form_filter&paged=1';
}
});
});
</script>
<?php
}
}
add_action( 'admin_head', 'override_nf_submissions' );
// Fix Ninja Forms v3.6.1+ 'nf_sub' post type filter for 'form_id'
add_filter( 'pre_get_posts', 'custom_ninjaforms_submission_filter' );
function custom_ninjaforms_submission_filter( $query ){
global $pagenow;
if( isset($_GET['post_type']) && $_GET['post_type'] == "nf_sub" && is_admin() && !defined( 'DOING_AJAX' ) && $pagenow=='edit.php' && isset($_GET['form_id']) && $_GET['form_id'] != '' && $query->is_main_query()) {
$value = $_GET['form_id'];
$query->query_vars['meta_key'] = '_form_id';
$query->query_vars['meta_value'] = $value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment