Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active March 1, 2017 08:02
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/f731328b5322ea2fd947f9eb8bb5aef4 to your computer and use it in GitHub Desktop.
Save xnau/f731328b5322ea2fd947f9eb8bb5aef4 to your computer and use it in GitHub Desktop.
demonstrates a simple filter for capturing a dynamic value on the admin side in Participants database
<?php
add_action( 'pdb-form_element_build_text-line', 'xnau_place_dynamic_value' );
/**
* sets the value of a dynamic hidden field in the backend
*
* @param object $field
*/
function xnau_place_dynamic_value( $field )
{
/*
* the field must be a regular pdb field and we must be in the backend
*/
if ( isset( Participants_Db::$fields[$field->name] ) && is_admin() ) {
$default_value = Participants_Db::$fields[$field->name]->default;
/*
* don't change the value if it's already set
* check that it's a dynamic field
*/
if ( empty( $field->value ) && Participants_Db::is_dynamic_value( $default_value ) ) {
$field->value = Participants_Db::get_dynamic_value( $default_value ); // set the value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment