Created
October 27, 2018 20:00
-
-
Save mikeschinkel/696960c5d24a44ff015b131dd99ee4c7 to your computer and use it in GitHub Desktop.
Proposal for GravityForms to add a 'gform_custom_field_name_clauses' filter.
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 | |
class GFFormsModel { | |
public static function get_custom_field_names() { | |
global $wpdb; | |
$clauses = apply_filters( 'gform_custom_field_name_clauses', array( | |
'found_rows' => '', | |
'distinct' => 'DISTINCT', | |
'fields' => 'meta_key', | |
'join' => '', | |
'where' => "AND meta_key NOT BETWEEN '_' AND '_z'", | |
'groupby' => '', | |
'having' => 'HAVING meta_key NOT LIKE %s', | |
'orderby' => 'ORDER BY meta_key', | |
'order' => 'ASC', | |
'limit' => '' | |
)); | |
$sql = "SELECT {$clauses[ 'found_rows' ]} {$clauses[ 'distinct' ]} | |
{$clauses[ 'fields' ]} | |
FROM $wpdb->postmeta {$clauses[ 'join' ]} | |
WHERE 1=1 {$clauses[ 'where' ]} | |
{$clauses[ 'groupby' ]} | |
{$clauses[ 'having' ]} | |
{$clauses[ 'orderby' ]} {$clauses[ 'order' ]} | |
{$clauses[ 'limits' ]}"; | |
$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%' ) ); | |
return $keys; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment