Last active
August 16, 2021 12:56
-
-
Save MaryOJob/bfa0d8e623a66ff1bd5d595fe6179da7 to your computer and use it in GitHub Desktop.
Add a Register Field TextArea field type which limits the number of characters Members can fill in
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 | |
/** | |
* See the PMPro Register Helper readme for more information and examples: https://www.paidmembershipspro.com/documentation/register-helper-documentation/adding-fields/ | |
* Please add the below code to your custom plugin or Code Snippets Plugin by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
// We have to put everything in a function called on init, so we are sure Register Helper is loaded. | |
// Define the fields. | |
function my_pmprorh_init() { | |
//don't break if Register Helper is not loaded | |
if(!function_exists( "pmprorh_add_registration_field" )) { | |
return false; | |
} | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'samplefield', // input name, will also be used as meta key | |
'textarea', // type of field | |
array( | |
'label' => 'Type in your Memo', // custom field label to be displayed on the frontend | |
'profile' => true, // show in front-end member profile | |
'memberslistcsv' => false, // add to export CSV file from Members List or not | |
'rows' => 3, // number of rows | |
'html_attributes' => array( 'maxlength' => '200'), // input the number of characters you want members to be able to type in | |
// 'html_attributes' => array( 'minlength' => '20'), // Set a max character limit or a minimun character limit | |
) | |
); | |
// 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','pmprorh_add_registration_field'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment