Last active
February 7, 2024 18:00
-
-
Save xnau/aaa669e0cf9ea1e1478beb2cda0f2199 to your computer and use it in GitHub Desktop.
Shows how to update dynamic fields after a signup is submitted
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 | |
/** | |
* Plugin Name: PDB Dynamic Field Updater | |
* Description: updates dynamic fields automatically after a signup submission | |
* Version: 1.0 | |
*/ | |
class PDb_Dynamicfield_Update | |
{ | |
/** | |
* sets up the action | |
*/ | |
public function __construct() | |
{ | |
add_action( 'pdb-after_submit_signup', [$this,'update_new_record'], 100 ); | |
} | |
/** | |
* updates a new record | |
* | |
* @param array $record the new record submission values | |
*/ | |
public function update_new_record( $record ) | |
{ | |
// convert any null values to empty string so they will be updated | |
array_walk( $record, function( &$value, $key ) { $value = is_null( $value ) ? '' : $value; } ); | |
// update the dynamic values in the record | |
$updated_record = apply_filters( 'pdb-dynamic_db_field_update', $record ); | |
// filter out any values that did not change | |
$post = array_diff_assoc( $updated_record, $record ); | |
if ( ! empty( $post ) ) | |
{ | |
// if we have changed values, write them to the database | |
Participants_Db::write_participant( $post, $record['id'] ); | |
} | |
} | |
} | |
new PDb_Dynamicfield_Update(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This needs to be installed as a plugin.
How to Install a WordPress Plugin from a Gist