Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PMPRO wiping out profile's first and last name for members paying via PayPal Express
<?php
/*
Plugin Name: Paid Memberships Pro
Plugin URI: http://www.paidmembershipspro.com
Description: Plugin to Handle Memberships
Version: 1.8.6.8.1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
Copyright 2011 Stranger Studios (email : jason@strangerstudios.com)
GPLv2 Full license details in license.txt
*/
//version constant
define("PMPRO_VERSION", "1.8.6.8.1");
define("PMPRO_USER_AGENT", "Paid Memberships Pro v" . PMPRO_VERSION . "; " . site_url());
//if the session has been started yet, start it (ignore if running from command line)
if(defined('STDIN') )
{
//command line
}
else
{
if (version_compare(phpversion(), '5.4.0', '>=')) {
if (session_status() == PHP_SESSION_NONE)
session_start();
}
else {
if(!session_id())
session_start();
}
}
/*
Includes
*/
define("PMPRO_DIR", dirname(__FILE__));
require_once(PMPRO_DIR . "/includes/localization.php"); //localization functions
require_once(PMPRO_DIR . "/includes/lib/name-parser.php"); //parses "Jason Coleman" into firstname=>Jason, lastname=>Coleman
require_once(PMPRO_DIR . "/includes/functions.php"); //misc functions used by the plugin
require_once(PMPRO_DIR . "/includes/upgradecheck.php"); //database and other updates
if(!defined('PMPRO_LICENSE_SERVER'))
require_once(PMPRO_DIR . "/includes/license.php"); //defines location of addons data and licenses
require_once(PMPRO_DIR . "/scheduled/crons.php"); //crons for expiring members, sending expiration emails, etc
require_once(PMPRO_DIR . "/classes/class.memberorder.php"); //class to process and save orders
require_once(PMPRO_DIR . "/classes/class.pmproemail.php"); //setup and filter emails sent by PMPro
require_once(PMPRO_DIR . "/includes/filters.php"); //filters, hacks, etc, moved into the plugin
require_once(PMPRO_DIR . "/includes/reports.php"); //load reports for admin (reports may also include tracking code, etc)
require_once(PMPRO_DIR . "/includes/adminpages.php"); //dashboard pages
require_once(PMPRO_DIR . "/includes/services.php"); //services loaded by AJAX and via webhook, etc
require_once(PMPRO_DIR . "/includes/metaboxes.php"); //metaboxes for dashboard
require_once(PMPRO_DIR . "/includes/profile.php"); //edit user/profile fields
require_once(PMPRO_DIR . "/includes/https.php"); //code related to HTTPS/SSL
require_once(PMPRO_DIR . "/includes/notifications.php"); //check for notifications at PMPro, shown in PMPro settings
require_once(PMPRO_DIR . "/includes/init.php"); //code run during init, set_current_user, and wp hooks
require_once(PMPRO_DIR . "/includes/content.php"); //code to check for memebrship and protect content
require_once(PMPRO_DIR . "/includes/email.php"); //code related to email
require_once(PMPRO_DIR . "/includes/recaptcha.php"); //load recaptcha files if needed
require_once(PMPRO_DIR . "/includes/cleanup.php"); //clean things up when deletes happen, etc.
require_once(PMPRO_DIR . "/includes/login.php"); //code to redirect away from login/register page
require_once(PMPRO_DIR . "/includes/xmlrpc.php"); //xmlrpc methods
require_once(PMPRO_DIR . "/shortcodes/checkout_button.php"); //[checkout_button] shortcode to show link to checkout for a level
require_once(PMPRO_DIR . "/shortcodes/membership.php"); //[membership] shortcode to hide/show member content
require_once(PMPRO_DIR . "/shortcodes/pmpro_account.php"); //[pmpro_account] shortcode to show account information
//load gateway
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway.php"); //loaded by memberorder class when needed
//load payment gateway class
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_authorizenet.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_braintree.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_check.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_cybersource.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_payflowpro.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_paypal.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_paypalexpress.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_paypalstandard.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_stripe.php");
require_once(PMPRO_DIR . "/classes/gateways/class.pmprogateway_twocheckout.php");
/*
Setup the DB and check for upgrades
*/
global $wpdb;
//check if the DB needs to be upgraded
if(is_admin())
pmpro_checkForUpgrades();
//load plugin updater
if(is_admin())
require_once(PMPRO_DIR . "/includes/addons.php");
/*
Definitions
*/
define("SITENAME", str_replace("&#039;", "'", get_bloginfo("name")));
$urlparts = explode("//", home_url());
define("SITEURL", $urlparts[1]);
define("SECUREURL", str_replace("http://", "https://", get_bloginfo("wpurl")));
define("PMPRO_URL", WP_PLUGIN_URL . "/paid-memberships-pro");
define("PMPRO_DOMAIN", pmpro_getDomainFromURL(site_url()));
define("PAYPAL_BN_CODE", "PaidMembershipsPro_SP");
/*
Globals
*/
global $gateway_environment;
$gateway_environment = pmpro_getOption("gateway_environment");
// Returns a list of all available gateway
function pmpro_gateways(){
$pmpro_gateways = array(
'' => __('Testing Only', 'pmpro'),
'check' => __('Pay by Check', 'pmpro'),
'stripe' => __('Stripe', 'pmpro'),
'paypalexpress' => __('PayPal Express', 'pmpro'),
'paypal' => __('PayPal Website Payments Pro', 'pmpro'),
'payflowpro' => __('PayPal Payflow Pro/PayPal Pro', 'pmpro'),
'paypalstandard' => __('PayPal Standard', 'pmpro'),
'authorizenet' => __('Authorize.net', 'pmpro'),
'braintree' => __('Braintree Payments', 'pmpro'),
'twocheckout' => __('2Checkout', 'pmpro'),
'cybersource' => __('Cybersource', 'pmpro')
);
return apply_filters( 'pmpro_gateways', $pmpro_gateways );
}
//when checking levels for users, we save the info here for caching. each key is a user id for level object for that user.
global $all_membership_levels;
//we sometimes refer to this array of levels
global $membership_levels;
$membership_levels = $wpdb->get_results( "SELECT * FROM {$wpdb->pmpro_membership_levels}", OBJECT );
/*
Activation/Deactivation
*/
function pmpro_activation()
{
//schedule crons
wp_schedule_event(current_time('timestamp'), 'daily', 'pmpro_cron_expire_memberships');
wp_schedule_event(current_time('timestamp')+1, 'daily', 'pmpro_cron_expiration_warnings');
//wp_schedule_event(current_time('timestamp')(), 'daily', 'pmpro_cron_trial_ending_warnings'); //this warning has been deprecated since 1.7.2
wp_schedule_event(current_time('timestamp'), 'monthly', 'pmpro_cron_credit_card_expiring_warnings');
//add caps to admin role
$role = get_role( 'administrator' );
$role->add_cap( 'pmpro_memberships_menu' );
$role->add_cap( 'pmpro_membershiplevels' );
$role->add_cap( 'pmpro_edit_memberships' );
$role->add_cap( 'pmpro_pagesettings' );
$role->add_cap( 'pmpro_paymentsettings' );
$role->add_cap( 'pmpro_emailsettings' );
$role->add_cap( 'pmpro_advancedsettings' );
$role->add_cap( 'pmpro_addons' );
$role->add_cap( 'pmpro_memberslist' );
$role->add_cap( 'pmpro_memberslistcsv' );
$role->add_cap( 'pmpro_reports' );
$role->add_cap( 'pmpro_orders' );
$role->add_cap( 'pmpro_orderscsv' );
$role->add_cap( 'pmpro_discountcodes' );
do_action('pmpro_activation');
}
function pmpro_deactivation()
{
//remove crons
wp_clear_scheduled_hook('pmpro_cron_expiration_warnings');
wp_clear_scheduled_hook('pmpro_cron_trial_ending_warnings');
wp_clear_scheduled_hook('pmpro_cron_expire_memberships');
wp_clear_scheduled_hook('pmpro_cron_credit_card_expiring_warnings');
//remove caps from admin role
$role = get_role( 'administrator' );
$role->remove_cap( 'pmpro_memberships_menu' );
$role->remove_cap( 'pmpro_membershiplevels' );
$role->remove_cap( 'pmpro_edit_memberships' );
$role->remove_cap( 'pmpro_pagesettings' );
$role->remove_cap( 'pmpro_paymentsettings' );
$role->remove_cap( 'pmpro_emailsettings' );
$role->remove_cap( 'pmpro_advancedsettings' );
$role->remove_cap( 'pmpro_addons' );
$role->remove_cap( 'pmpro_memberslist' );
$role->remove_cap( 'pmpro_memberslistcsv' );
$role->remove_cap( 'pmpro_reports' );
$role->remove_cap( 'pmpro_orders' );
$role->remove_cap( 'pmpro_orderscsv' );
$role->remove_cap( 'pmpro_discountcodes' );
do_action('pmpro_deactivation');
}
register_activation_hook(__FILE__, 'pmpro_activation');
register_deactivation_hook(__FILE__, 'pmpro_deactivation');
<?php
/*
Plugin Name: SolAR Member Register Helper
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Register Helper Initialization for SoLAR Site
Version: .1
Author: Stranger Studios / Mods by cogdog
Author URI: http://www.strangerstudios.com
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists("pmprorh_add_registration_field"))
{
return false;
}
//Check to see if user is logged in. If they are than ignore these requirements
global $current_user;
// check to see if it is a new user or if the user has admin access, if so it will proceed to require fields and allow admin to generate member csv with the below fields as columns
if(empty($current_user->ID)|| function_exists("current_user_can")) {
//define the fields
$fields = array();
//dropdown, includes a blank option
//$dropdown = new PMProRH_Field("gender", "select", array("options"=>array("" => "", "male"=>"Male", "female"=>"Female")));
// field for Institution Name
$fields[] = new PMProRH_Field(
"institution", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Institution Name", // label name
"hint"=>"Name of institution where you work",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"institution", // custom class
"profile"=>true, // show in user profile
"levels"=>array(1,3),
"required"=>true // make this field required
));
// field for Institution Name
$fields[] = new PMProRH_Field(
"institution", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Institution Name", // label name
"hint"=>"Name of Institutional University member",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"institution", // custom class
"profile"=>true, // show in user profile
"levels"=>array(4),
"required"=>true // make this field required
));
// field for Institution Name
$fields[] = new PMProRH_Field(
"institution", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Institution Name", // label name
"hint"=>"Name of Corporate Organization Member",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"institution", // custom class
"profile"=>true, // show in user profile
"levels"=>array(5),
"required"=>true // make this field required
));
// Institution Type field
$fields[] = new PMProRH_Field(
"institutionType", // input name, will also be used as meta key
"select", // type of field
array(
"label"=>"Institution Type", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
//"size"=>40, // input size
"class"=>"institutionType", // custom class
"profile"=>true, // show in user profile
"required"=>true, // make this field required
"options"=>array("university"=>"University", "k12"=>"K-12","industry"=>"Industry",
"government"=>"Government", "nonProfit"=>"Non-Profit")
));
// Position field
$fields[] = new PMProRH_Field(
"position", // input name, will also be used as meta key
"select", // type of field
array(
"label"=>"Position", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"position", // custom class
"profile"=>true, // show in user profile
"required"=>true, // make this field required
"levels"=>array(1,3),
"options"=>array("faculty"=>"Faculty", "staff"=>"Staff","student"=>"Student",
"researcher"=>"Researcher", "analyst"=>"Analyst","designer"=>"Designer","administrator"=>"Administrator")
));
// City field
$fields[] = new PMProRH_Field(
"city", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"City", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"city", // custom class
"profile"=>true, // show in user profile
"required"=>true, // make this field required
"levels"=>array(1,3),
));
// Country field
$fields[] = new PMProRH_Field(
"country", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Country", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"country", // custom class
"profile"=>true, // show in user profile
"required"=>true, // make this field required
"levels"=>array(1,3)
));
// field for Primary contact
$fields[] = new PMProRH_Field(
"primary_first_name", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Primary Contact First Name", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"primary_first_name", // custom class
"profile"=>true, // show in user profile
"levels"=>array(4,5),
"required"=>true // make this field required
));
// field for Primary contact
$fields[] = new PMProRH_Field(
"primary_last_name", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Primary Contact Last Name", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"primary_last_name", // custom class
"profile"=>true, // show in user profile
"levels"=>array(4,5),
"required"=>true // make this field required
));
// field for Financial contact
$fields[] = new PMProRH_Field(
"financial_first_name", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Financial Contact First Name", // label name
"hint"=>"(if not the same as Primary Contact)",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"financial_first_name", // custom class
"profile"=>true, // show in user profile
"levels"=>array(4,5),
"required"=>false
));
// field for Financial contact
$fields[] = new PMProRH_Field(
"financial_last_name", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Financial Contact Last Name", // label name
"hint"=>"(if not the same as Primary Contact)",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"financial_last_name", // custom class
"profile"=>true, // show in user profile
"levels"=>array(4,5),
"required"=>false
));
//$fields[] = new PMProRH_Field("Primary Field of Interest", "html", array("html"=>"","levels"=>array(1,3)));
$fields[]= new PMProRH_Field("primaryInterest", "radio", array("label"=>"Primary Field of Interest","levels"=>array(1,3),"options"=>array("research"=>"Research", "practice"=>"Practice","policy"=>"Policy")));
/*$fields[] = new PMProRH_Field("research", "checkbox", array("profile"=>true,"levels"=>array(1,3)));
$fields[] = new PMProRH_Field("practice", "checkbox", array("profile"=>true,"levels"=>array(1,3)));
$fields[] = new PMProRH_Field("policy", "checkbox", array("profile"=>true,"levels"=>array(1,3)));
*/
//$radio = new PMProRH_Field("gender", "radio", array("options"=>array("male"=>"Male", "female"=>"Female")));
// Department field (make optional)
$fields[] = new PMProRH_Field(
"areaofintrest", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Primary Area of Interest", // Primary Area of Interest
"hint"=>"Enter your primary area of interest in learning analytics",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"areaofintrest", // custom class
"profile"=>true, // show in user profile
"levels"=>array(1,3),
"required"=>false // make this field required
));
//add the fields after the email field of the check out page
foreach($fields as $field)
pmprorh_add_registration_field(
"before_submit_button", // "after_email", location on checkout page
$field // PMProRH_Field object
);
//that's it. see the PMPro Register Helper readme for more information and examples.
} //User does not need need to be logged in from here out
}
add_action("init", "my_pmprorh_init");
function pmproan2c_pmpro_checkout_after_username()
{
//Check to see if user is logged in. If they are than ignore these requirements
global $current_user;
// check to see if it is a new user or if the user has admin access, if so it will proceed to require fields and allow admin to generate member csv with the below fields as columns
if(empty($current_user->ID)|| function_exists("current_user_can")) {
// field for Institution
$fields = array();
$fields[] = new PMProRH_Field(
"first_name", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"First Name", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"first_name", // custom class
"profile"=>true, // show in user profile
"levels"=>array(1,3),
"required"=>true // make this field required
));
// field for Institution
$fields[] = new PMProRH_Field(
"last_name", // input name, will also be used as meta key
"text", // type of field
array(
"label"=>"Last Name", // label name
"hint"=>"",
"memberslistcsv"=>true, // add to CSV export
"size"=>40, // input size
"class"=>"last_name", // custom class
"profile"=>true, // show in user profile
"levels"=>array(1,3),
"required"=>true // make this field required
));
foreach($fields as $field)
pmprorh_add_registration_field(
"after_password", //location on checkout page
$field // PMProRH_Field object
);
/*$first_name = $_REQUEST['first_name'];
$last_name = $_REQUEST['last_name'];
?>
<div>
<label for="first_name">First Name</label>
<input id="first_name" name="first_name" type="text" class="input pmpro_required" size="30" value="<?=$first_name?>" />
</div>
<div>
<label for="last_name">Last Name</label>
<input id="last_name" name="last_name" type="text" class="input pmpro_required" size="30" value="<?=$last_name?>" />
</div>
<?php*/
}
}
add_action('pmpro_checkout_after_username', 'pmproan2c_pmpro_checkout_after_username');
//require the fields
/*
function pmproan2c_pmpro_registration_checks()
{
global $pmpro_msg, $pmpro_msgt, $current_user;
if(!empty($_REQUEST['first_name']))
$first_name = $_REQUEST['first_name'];
elseif(!empty($_SESSION['first_name']))
$first_name = $_SESSION['first_name'];
else
$first_name = "";
if(!empty($_REQUEST['last_name']))
$last_name = $_REQUEST['last_name'];
elseif(!empty($_SESSION['last_name']))
$last_name = $_SESSION['last_name'];
else
$last_name = "";
if($first_name && $last_name || $current_user->ID)
{
//all good
return true;
}
else
{
$pmpro_msg = "The first and last name fields are required.";
$pmpro_msgt = "pmpro_error";
return false;
}
}
add_filter("pmpro_registration_checks", "pmproan2c_pmpro_registration_checks");*/
//update the user after checkout
function pmproan2c_update_first_and_last_name_after_checkout($user_id)
{
global $current_user;
if(empty($current_user->ID)) {
if(!empty($_REQUEST['first_name']))
$first_name = $_REQUEST['first_name'];
elseif(!empty($_SESSION['first_name']))
$first_name = $_SESSION['first_name'];
else
$first_name = "";
if(!empty($_REQUEST['last_name']))
$last_name = $_REQUEST['last_name'];
elseif(!empty($_SESSION['last_name']))
$last_name = $_SESSION['last_name'];
else
$last_name = "";
update_user_meta($user_id, "first_name", $first_name);
update_user_meta($user_id, "last_name", $last_name);
}
}
add_action('pmpro_after_checkout', 'pmproan2c_update_first_and_last_name_after_checkout');
function pmproan2c_pmpro_paypalexpress_session_vars()
{
global $current_user;
if(empty($current_user->ID)) {
//save our added fields in session while the user goes off to PayPal
$_SESSION['first_name'] = $_REQUEST['first_name'];
$_SESSION['last_name'] = $_REQUEST['last_name'];
}
}
add_action("pmpro_paypalexpress_session_vars", "pmproan2c_pmpro_paypalexpress_session_vars");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.