Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active July 30, 2020 10:45
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 ipokkel/0cbc807b3c5939bca63daf6db384b76f to your computer and use it in GitHub Desktop.
Save ipokkel/0cbc807b3c5939bca63daf6db384b76f to your computer and use it in GitHub Desktop.
Pause membership content access checkbox Register Helper example field.
<?php
/**
* This recipe creates a custom fields for membership registration.
*
* Pause content access checkbox for this article:
* @link https://www.paidmembershipspro.com/block-pause-members-access-restricted-content/
*
* @requires Register Helper Add On
* @link https://www.paidmembershipspro.com/add-ons/pmpro-register-helper-add-checkout-and-profile-fields/
*
* 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_pmprorh_init_pause_access() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// Bail if not in administrative area.
if ( ! is_admin() ) {
return;
}
pmprorh_add_checkout_box( 'pause_hasaccess', 'Access to Member Content' );
// Define the field.
$fields = array();
$fields[] = new PMProRH_Field(
'pmpro_paused_user',
'checkbox',
array(
'label' => 'Pause User',
'text' => 'Deny Access to Member Content',
'profile' => 'only_admin',
)
);
// Add the fields into the checkout_boxes are of the checkout page.
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'pause_hasaccess',
$field
);
}
}
add_action( 'init', 'my_pmprorh_init_pause_access', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment