Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active November 7, 2022 14:26
Show Gist options
  • Save ipokkel/071023ff88736f7fbe2e1e860865ea9d to your computer and use it in GitHub Desktop.
Save ipokkel/071023ff88736f7fbe2e1e860865ea9d to your computer and use it in GitHub Desktop.
Basic example of using a custom callback function for a PMPro User Field created with code.
<?php
// Create a registration form field with a custom callback
function my_pmpro_user_field_example_save_function() {
// Don't break if PMPro is out of date or not loaded.
if ( ! function_exists( 'pmpro_add_user_field' ) ) {
return false;
}
// define the fields
$fields = array();
// Basic Text Field Example
$fields[] = new PMPro_Field(
'my_field_name', // input field name, used as meta key
'text', // field type
array(
'label' => 'My Field Label', // field label
'profile' => true, // display on user profile
'save_function' => 'my_custom_callback_function', // use a custom callback function
)
);
foreach ( $fields as $field ) {
pmpro_add_user_field(
'checkout_boxes', // location on checkout page
$field // PMPro_Field object
);
}
}
add_action( 'init', 'my_pmpro_user_field_example_save_function' );
// Custom callback function
function my_custom_callback_function( $field_value ) {
// Do something
}
@laurenhagan0306
Copy link

This recipe is included in the blog post on "How to Use a Custom Callback Function For User Profile or Registration Fields" at Paid Memberships Pro here: https://www.paidmembershipspro.com/custom-callback-function-save-user-registration-profile-fields/

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