Last active
May 6, 2021 08:23
-
-
Save andrewlimaza/9d3585934e5a14bdc972bd13b0ab32c6 to your computer and use it in GitHub Desktop.
dynamic readonly example for Register Helper
This file contains hidden or 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 | |
/** | |
* Make read-only set to true for non-admins. | |
* This is a template, please copy code over that is needed for your own integrations. | |
* Follow this guide to add custom code to your membership site - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmprorh_init() { | |
// Don't break if Register Helper is not loaded. | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return false; | |
} | |
$read_only = true; | |
if ( current_user_can( 'manage_options' ) ) { // Adjust here for other capabilities | |
$read_only = false; | |
} | |
// Define the fields. | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'join_date', | |
'text', | |
array( | |
'label' => 'Join date example', | |
'profile' => 'only', | |
'readonly' => $read_only | |
) | |
); | |
// Add the fields into a new checkout_boxes are of the checkout page. | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( | |
'checkout_boxes', // location on checkout page | |
$field // PMProRH_Field object | |
); | |
} | |
// That's it. See the PMPro Register Helper readme for more information and examples. | |
} | |
add_action( 'init', 'my_pmprorh_init' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment