Skip to content

Instantly share code, notes, and snippets.

View nextab's full-sized avatar

nexTab - Oliver Gehrmann nextab

View GitHub Profile
#region Update CCT helper function
/**
*
* Helper function to update the row(s) of a CCT table
*
* @param array $values column names and value pairings
* @param array $where specify what to update
* @param $table_name slug of the CCT; global WPDB prefix and 'jet_cct_' will be appended; defaults to 'user_information'
*
* @return bool returns true on success; false on fail
#region Registration part 1 - Custom Action for JetFormBuilder
add_action( 'jet-form-builder/custom-action/user-activation-code', function( $request, $action_handler ) {
$cct_id = ! empty( $request['inserted_cct_user_information'] ) ? $request['inserted_cct_user_information'] : false;
$user_email = ! empty( $request['e_mail'] ) ? $request['e_mail'] : false;
if($cct_id <= 0) {
error_log("CCT for user information could not be created; CCT ID: {$cct_id};");
if($user_email !== false) {
error_log("Submitted e-mail for user: {$user_email};");
}
return;
#region Check Activation Code
/**
*
* @param $value mixed
* @param $context \Jet_Form_Builder\Request\Parser_Context
*
* @return bool
*/
function jet_fb_v_activation_code_check( $value, $context ): bool {
$user = wp_get_current_user();
#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
*
#region Enqueue Gutenberg Scripts
add_theme_support( 'custom-spacing' );
add_theme_support( 'border' );
add_theme_support( 'appearance-tools' );
#endregion Enqueue Gutenberg Scripts
#region Check if e-mail has already signed up for this event
function jet_fb_v_unique_mail_for_event( $value, $context ): bool {
$fields = $context->get_request();
$mails = get_mails_for_event($fields['event_id']);
// If mails list is empty or the email is not in the list, it's unique
return !in_array($value, $mails, true);
}
#endregion Check if e-mail has already signed up for this event
#region Get all e-mails for current event
@nextab
nextab / Zuweisung von CCT - Custom Content Types zu einem Benutzer nachdem eine bestimmte Seite aufgerufen wird (per Shortcode).php
Created September 20, 2023 06:46
/* Wenn Submissions über ein JetForm per Gast-Modus zugelassen werden, muss man dem Benutzer später noch die Form Submission zuweisen, damit er diese auch bearbeiten kann; um bei späterer Registrierung die Zuweisung zuzunehmen empfiehlt sich eine entsprechende Logik. Der Shortcode [sort_event_registrations] muss hier noch auf der zugehörigen My …
/* Wenn Submissions über ein JetForm per Gast-Modus zugelassen werden, muss man dem Benutzer später noch die Form Submission zuweisen, damit er diese auch bearbeiten kann; um bei späterer Registrierung die Zuweisung zuzunehmen empfiehlt sich eine entsprechende Logik.
Der Shortcode [sort_event_registrations] muss hier noch auf der zugehörigen My Account Page eingebunden werden. */
#region Assign signups to newly registered users
// Add the action to hook into the user_register event
function nxt_update_event_signups($user_id) {
// Get the newly created user's email
$new_user_email = get_user_data();
if($new_user_email === false) return;
#region Check e-mail regex
function jet_fb_v_nxt_check_email_regex( $value, $context ): bool {
$pattern = "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/";
if (preg_match($pattern, $value)) return true;
return false;
}
#endregion Check e-mail regex
#region Check if user e-mail is unique
function jet_fb_v_check_user_email($value, $context): bool {
if (!is_user_logged_in()) {
return !in_array($value, get_all_user_emails());
}
return get_user_data() === $value;
}
#endregion Check if user e-mail is unique
#region Get all user e-mails and return them as an array
/* Key-Name für E-Mail wäre "user_email" => entspricht den Bezeichnern des Standard WP User Objects
* user_email
* user_login
* user_nicename
* user_firstname
* user_lastname
* user_description
*/
#region Add new Macro Option for JetEngine