Last active
November 7, 2022 14:26
-
-
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.
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 | |
// 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/