Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active February 7, 2024 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/aaa669e0cf9ea1e1478beb2cda0f2199 to your computer and use it in GitHub Desktop.
Save xnau/aaa669e0cf9ea1e1478beb2cda0f2199 to your computer and use it in GitHub Desktop.
Shows how to update dynamic fields after a signup is submitted
<?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();
@xnau
Copy link
Author

xnau commented Feb 5, 2024

This needs to be installed as a plugin.

How to Install a WordPress Plugin from a Gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment