spivurno
7/2/2015 - 7:53 PM

Gravity Wiz // Gravity Forms // Exclude Forms from Form List

Gravity Wiz // Gravity Forms // Exclude Forms from Form List

<?php
/**
 * Gravity Wiz // Gravity Forms // Exclude Forms from Form List
 * http://gravitywiz.com
 */
add_filter( 'query', function( $query ) {

	if( rgget( 'page' ) != 'gf_edit_forms' ) {
		return $query;
	}

	if( strpos( $query, 'SELECT f.id, f.title, f.date_created, f.is_active, 0 as lead_count, 0 view_count' ) === 0 ) {
		$search  = 'ORDER BY';
		$replace = sprintf( "AND f.id NOT IN( %s )\nORDER BY", implode( ', ', range( 0, 870 ) ) );
		$query   = str_replace( $search, $replace, $query );
	}

	$form_table_name = GFFormsModel::get_form_table_name();
	$sql             = "SELECT(SELECTcount(0)FROMwp_rg_formWHEREis_trash=0)astotal,(SELECTcount(0)FROMwp_rg_formWHEREis_active=1ANDis_trash=0)asactive,(SELECTcount(0)FROMwp_rg_formWHEREis_active=0ANDis_trash=0)asinactive,(SELECTcount(0)FROMwp_rg_formWHEREis_trash=1)astrash";

	if( strpos( preg_replace( '/\s+/', '', $query ), $sql ) === 0 ) {
		$replace = sprintf( "\nAND id NOT IN( %s )", implode( ', ', range( 0, 870 ) ) );
		$searches = array(
			'WHERE is_trash = 0',
			'WHERE is_active=1 AND is_trash = 0',
			'WHERE is_active=0 AND is_trash = 0',
			'WHERE is_trash=1'
		);
		foreach( $searches as $search ) {
			$query = str_replace( $search, $search . $replace, $query );
		}
	}

	return $query;
} );