Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nextab/a71819790583e0f642f57b43d820d835 to your computer and use it in GitHub Desktop.
Save nextab/a71819790583e0f642f57b43d820d835 to your computer and use it in GitHub Desktop.
#region CCT Lookup - Get (single) field in CCT from JetEngine table
/**
*
* @param string $find_column column name to find
* @param string $needle - value that needs to be checked against
* @param string $lookup_column - column name to check $needle against
* @param string $table - slug of the CCT; global WPDB prefix and 'jet_cct_' will be appended; defaults to 'user_information'
*
* @return string|null returns the value of the $find_column if the $lookup_column matches the $needle; null if no match is found
*
* Example:
* $activation_code = get_jet_field('activation_code', $user_email);
*
* Example 2:
* $hdt_membership_no = get_jet_field('hdt_membership_id', $user_email, 'user_email', 'user_information');
*
*/
function get_jet_field($find_column, $needle, $lookup_column = 'user_email', $table = 'user_information'): string|null {
global $wpdb;
$table_name = $wpdb->prefix . 'jet_cct_' . sanitize_text_field($table);
$lookup_column = sanitize_text_field($lookup_column);
$find_column = sanitize_text_field($find_column);
// You should ensure that the column names are safe since they cannot be parameterized
$query = $wpdb->prepare(
"SELECT $find_column FROM $table_name WHERE $lookup_column = %s",
$needle
);
// Execute the query
$result = $wpdb->get_var($query);
// Return the result if available
return $result;
}
#endregion CCT Lookup - Get field in CCT from JetEngine table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment