Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created October 26, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andrewlimaza/d4d15dec7ec4dd7be9d3f8b8f64f1849 to your computer and use it in GitHub Desktop.
Save andrewlimaza/d4d15dec7ec4dd7be9d3f8b8f64f1849 to your computer and use it in GitHub Desktop.
PMPro Register Helper Upload File Example
<?php
//Copy lines 5 onwards into your PMPro Customizations plugin - http://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;
}
//define the fields
$fields = array();
$fields[] = new PMProRH_Field(
"my_image", // input name, will also be used as meta key
"file", // type of field
array(
"label"=>"My Image",
"hint"=>"Recommended size is 100px X 100px",
"profile"=>true, // show in user profile
));
$fields[] = new PMProRH_Field(
"my_pdf", // input name, will also be used as meta key
"file", // type of field
array(
"label"=>"Upload PDF",
"hint"=>"Please upload only .PDF files",
"profile"=>true, // show in user profile
));
//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");
@sharazghouri
Copy link

Are you able to remove the file after adding once?

@andrewlimaza
Copy link
Author

@sharazghouri, you are able to use other conditional logic to hide this field if the user already has uploaded it. You can check against the user meta value of "my_image". If it's not empty, then don't display the field.

@tejasbusiness
Copy link

How to restrict maximum upload file size? for example, file should not be more than 2MB

@andrewlimaza
Copy link
Author

To restrict the upload file size, you can set this inside your PHP settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment