Last active
March 1, 2017 08:02
-
-
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
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 | |
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