Last active
June 26, 2020 22:36
-
-
Save kimwhite/08a6fed19a4a840a4f93fed48c2fef54 to your computer and use it in GitHub Desktop.
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 | |
| /** | |
| * Sample for fields you can add to a business directory, includeding conditional business types | |
| * | |
| * 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/ | |
| */ | |
| //Now start placing your customization code below this line | |
| //we have to put everything in a function called on init, so we are sure Register Helper is loaded | |
| //Now start placing your customization code below this line | |
| function my_pmpro_rh_fields() { | |
| // Don't break if Register Helper is not loaded. | |
| if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
| return false; | |
| } | |
| // $fields array for Register Helper Example. | |
| $fields = array(); | |
| $fields[] = new PMProRH_Field( | |
| 'business_name', //meta key or name | |
| 'text', // feild type | |
| array( | |
| 'label' => 'Business Name', | |
| 'required' => true, | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'location', //meta key or name | |
| 'textarea', // feild type | |
| array( | |
| 'label' => 'Location', | |
| 'required' => true, | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'phone_number', //meta key or name | |
| 'text', // feild type | |
| array( | |
| 'label' => 'Phone Number', | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'biz_email', //meta key or name | |
| 'text', // feild type | |
| array( | |
| 'label' => 'Business Email', | |
| 'required' => true, | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'url', //meta key or name | |
| 'text', // feild type | |
| array( | |
| 'label' => 'Website', | |
| 'required' => true, | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'facebook_url', //meta key or name | |
| 'text', // feild type | |
| array( | |
| 'label' => 'Facebook URL', | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'twitter_url', //meta key or name | |
| 'text', // feild type | |
| array( | |
| 'label' => 'Twitter URL', | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| ) | |
| ); | |
| // Category Fields - conditional based on selection | |
| $fields[] = new PMProRH_Field( | |
| 'biz_category', | |
| 'select', | |
| array( | |
| 'options' => array( | |
| 'select' => 'select', | |
| 'Business & Professional Services' => 'Business & Professional Services', | |
| 'Home + Living' => 'Home + Living', | |
| 'Non-Profit + Government' => 'Non-Profit + Government', | |
| 'Shopping & Retail' => 'Shopping & Retail', | |
| ), | |
| 'required' => true, | |
| 'profile' => true, | |
| 'label' => 'Business Type', | |
| ) | |
| ); | |
| // Specifics dependent on Buisniess Category field. | |
| $fields[] = new PMProRH_Field( | |
| 'biz_category_business', | |
| 'checkbox_grouped', | |
| array( | |
| 'label' => 'Specific?', | |
| 'required' => false, | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| 'options' => array( // <option> elements for select field | |
| 'option_1' => 'Advertising & Media', // <option value=”option_1”>Option 1</option> | |
| 'option_2' => 'Computers & Telecommunication', // <option value=”option_2”>Option 2</option> | |
| 'option_3' => ' Construction & Building Services', // <option value=”option_3”>Option 3</option> | |
| 'option_4' => 'Finance & Insurance', // <option value=”option_4”>Option 4</option> | |
| 'option_5' => 'Ground Maintenance & Landscaping', // <option value=”option_4”>Option 5</option> | |
| 'option_6' => 'Lawyers, Health Practitioners', // <option value=”option_5”>Option 6</option> | |
| 'option_7' => 'Transportation', // <option value=”option_7”>Option 7</option> | |
| ), | |
| 'depends' => array( | |
| array( | |
| 'id' => 'biz_category', | |
| 'value' => 'Business & Professional Services', | |
| ), | |
| ), | |
| ) | |
| ); | |
| $fields[] = new PMProRH_Field( | |
| 'biz_category_homeliving', | |
| 'checkbox_grouped', | |
| array( | |
| 'label' => 'Specific?', | |
| 'required' => false, | |
| 'profile' => true, | |
| 'addmember' => true, // makes availble for admin adding member | |
| 'memberslistcsv' => true, // adds to your members export file | |
| 'options' => array( // <option> elements for select field | |
| 'option_1' => 'Auto & Motorcycle', // <option value=”option_1”>Option 1</option> | |
| 'option_2' => 'Health & Fitness', // <option value=”option_2”>Option 2</option> | |
| 'option_3' => 'Home & Garden', // <option value=”option_3”>Option 3</option> | |
| 'option_4' => 'Personal Services & Care', // <option value=”option_4”>Option 4</option> | |
| 'option_5' => ' Real Estate, Moving & Storage', // <option value=”option_5”>Option 5</option> | |
| ), | |
| 'depends' => array( | |
| array( | |
| 'id' => 'biz_category', | |
| 'value' => 'Home + Living', | |
| ), | |
| ), | |
| ) | |
| ); | |
| // 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_pmpro_rh_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment