Created
January 18, 2023 15:43
-
-
Save ipokkel/0c7506db8bb830d767bb22ee952bc87f to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Example of extending a user field to add a depends | |
* | |
* This recipe assumes a checkbox field with the name my_checkbox was created. | |
* This recipe assumes a textarea field with the name my_textarea was created. | |
* | |
* 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_fields_add_depends() { | |
global $pmpro_user_fields; | |
// bail if Paid Memberships Pro is not active | |
if ( ! function_exists( 'pmpro_add_user_field' ) ) { | |
return; | |
} | |
// loop through the fields and add the depends | |
foreach ( $pmpro_user_fields as $field_group => $fields ) { | |
foreach ( $fields as $field ) { | |
if ( 'my_textarea' === $field->name ) { | |
$field->depends = array( | |
array( | |
'id' => 'my_checkbox', | |
'value' => true, | |
), | |
); | |
} | |
} | |
} | |
} | |
add_action( 'init', 'my_pmpro_user_fields_add_depends' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment