Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewlimaza/9d3585934e5a14bdc972bd13b0ab32c6 to your computer and use it in GitHub Desktop.
Save andrewlimaza/9d3585934e5a14bdc972bd13b0ab32c6 to your computer and use it in GitHub Desktop.
dynamic readonly example for Register Helper
<?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