Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideadude/7fa6e560f48a89f7ce7795b9b7e21121 to your computer and use it in GitHub Desktop.
Save ideadude/7fa6e560f48a89f7ce7795b9b7e21121 to your computer and use it in GitHub Desktop.
Swap a PMPro user field to the checkbox_grouped type.
<?php
/**
* Currently, the PMPro user fields GUI does not allow you to choose
* the checkbox_grouped field type.
*
* These fields can be added via custom code though. If you want to manage some
* aspects of the field in the GUI, you can create a multiselect field,
* then swap it to the checkbox group using this code.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_user_field_swap_to_checkbox_grouped( $field, $where ) {
// Match our field name (used user_options for my example)
if ( 'user_options' === $field->name ) {
// Swap to a checkbox_grouped
$field->type = 'checkbox_grouped';
}
return $field;
}
add_filter( 'pmpro_add_user_field', 'my_pmpro_user_field_swap_to_checkbox_grouped', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment