Skip to content

Instantly share code, notes, and snippets.

@renventura
Created December 26, 2019 15:00
Show Gist options
  • Save renventura/5daeb800caffff25b7019d2fe8531c59 to your computer and use it in GitHub Desktop.
Save renventura/5daeb800caffff25b7019d2fe8531c59 to your computer and use it in GitHub Desktop.
Creates a dynamic tag for using in MemberPress custom fields.
<?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