Created
December 26, 2019 15:00
-
-
Save renventura/5daeb800caffff25b7019d2fe8531c59 to your computer and use it in GitHub Desktop.
Creates a dynamic tag for using in MemberPress custom fields.
This file contains hidden or 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_filter( 'mepr_fetch_options', 'mp_filter_custom_fields' ); | |
/** | |
* Filter the MemberPress options to set a dynamic value for custom fields. | |
* | |
* @param object $options MeprOptions | |
* | |
* @return object MeprOptions | |
*/ | |
function mp_filter_custom_fields( $options ) { | |
// Make sure we have custom registration fields | |
if ( empty( $options->custom_fields ) ) { | |
return $options; | |
} | |
foreach ( $options->custom_fields as $key => $field ) { | |
// Replace the dynamic "%%date%%" date tag with the current date | |
if ( '%%date%%' === $field->default_value ) { | |
$options->custom_fields[$key]->default_value = date( 'Y-m-d' ); | |
} | |
} | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment