<?php
/*
Plugin Name: PMPro Customizations
Plugin URI: https://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Customizations for my Paid Memberships Pro Setup
Version: .1
Author: Paid Memberships Pro
Author URI: https://www.paidmembershipspro.com
*/
//Now start placing your customization code below this line
function my_pmpro_email_headers_admin_emails( $headers, $email ) {
//bcc checkout emails
if ( strpos( $email->template, 'invoice' ) !== false || strpos( $email->template, 'admin_notification_approval' ) !== false ) {
//add bcc
$headers[] = 'Bcc:' . 'ecsca.membership@gmail.com';
}
return $headers;
}
add_filter( 'pmpro_email_headers', 'my_pmpro_email_headers_admin_emails', 10, 2 );
/*
PMPro Additional Fields for Register Helper:
Description: Add Telephone field to Registration form.
*/
function pmpro_add_fields_to_checkout() {
//don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
$fields = array();
// $fields[] = new PMPro_Field(
// 'phone', // input name, will also be used as meta key
// 'text', // type of field
// array(
// 'label' => 'Telephone', // custom field label
// 'profile' => true, // show in user profile
// 'memberslistcsv' => true, // include when using export members to csv
// 'addmember' => true, // include when using add member from admin
// 'required' => true, // make field required
// )
// );
// $fields[] = new PMPro_Field(
// 'kennel_name', // input name, will also be used as meta key
// 'text', // type of field
// array(
// 'label' => 'Kennel Name', // custom field label
// 'profile' => true, // show in user profile
// 'memberslistcsv' => true, // include when using export members to csv
// 'addmember' => true, // include when using add member from admin
//
// )
// );
// $fields[] = new PMPro_Field(
// 'additional_info', // input name, will also be used as meta key
// 'textarea', // type of field
// array(
// 'label' => 'Volunteer Interests', // custom field label
// 'profile' => true, // show in user profile
// 'memberslistcsv' => true, // include when using export members to csv
// 'addmember' => true, // include when using add member from admin
//
// )
// );
// // SELECT
// $fields[] = new PMPro_Field(
// 'member_type_by_admin', // input field name, used as meta key
// 'select', // field type
// array(
// 'label' => 'Select Member Type',
// 'profile' => 'only_admin',
// 'memberslistcsv' => true,
// 'addmember' => true,
// 'required' => false,
// 'options' => array(
// '' => 'Please Select',
// 'regular' => 'Regular',
// 'junior' => 'Junior',
// 'associate' => 'Associate',
// 'life' => 'Life',
// ),
// )
// );
// // SELECT
// $fields[] = new PMPro_Field(
// 'member_type', // input field name, used as meta key
// 'select', // field type
// array(
// 'label' => 'Newsletters & ECSCA Info Delivery Method',
// 'options' => array(
// '' => '', // blank option displayed first
// 'Email' => 'Email',
// 'USPS' => 'USPS',
//
// ),
// 'profile' => true,
// 'memberslistcsv' => true,
// 'addmember' => true,
// 'required' => false,
// )
// );
// // SELECT
// $fields[] = new PMPro_Field(
// 'member_type', // input field name, used as meta key
// 'select', // field type
// array(
// 'label' => 'Voting Ballot Delivery Method',
// 'options' => array(
// '' => '', // blank option displayed first
// 'Email' => 'Email',
// 'USPS' => 'USPS',
//
// ),
// 'profile' => true,
// 'memberslistcsv' => true,
// 'addmember' => true,
// 'required' => false,
// )
// );
//add the fields to default forms
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
}
}
add_action( 'init', 'pmpro_add_fields_to_checkout' );
/**
* This recipe is an example of how to change localized text strings
* for PMPro Member Directory Add On.
*
* 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/
*/
/**
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function change_start_date_for_member_directory_and_profile_pages( $translated_text, $text, $domain ) {
if ( 'pmpromd' === $domain || 'pmpro-member-directory' === $domain || 'paid-memberships-pro' === $domain ) {
switch ( $text ) {
case 'Start Date':
$translated_text = __( 'Online Membership Enrollment Date', 'pmpro-member-directory' );
break;
}
}
return $translated_text;
}
add_filter( 'gettext', 'change_start_date_for_member_directory_and_profile_pages', 20, 3 );
/**
* This recipe creates custom fields for membership registration.
*
* @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_initial_memberships_start_date() {
// don't break if Register Helper is not loaded
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// define the fields
$fields = array();
// // TEXT FIELD
// $fields[] = new PMPro_Field(
// 'club_membership_start_year', // input field name, used as meta key
// 'number', // field type
// array(
// 'label' => 'Initial Club Membership Start Year', // display custom label, if not used field name will be used
// 'required' => true, // make field required
// 'html_attributes' => array(
// 'placeholder' => 'e.g., 2001',
// 'size' => 10, // field width
// 'required' => 'required',
// ), // add valid html input field attributes
// 'profile' => true, // show on profile, set to 'only' to show on the profile edit page only.
// 'memberslistcsv' => true, // include when using export members to csv
// 'addmember' => true, // include when using add member from admin
// )
// );
// SELECT
// $fields[] = new PMPro_Field(
// 'member_likes_primary', // input field name, used as meta key
// 'select', // field type
// array(
// 'label' => 'Primary Volunteer Event Types',
// 'options' => array(
// '' => '', // blank option displayed first
// 'obedience' => 'Rally & Obedience',
// 'confirmation' => 'Confirmation & Stewarding',
// 'tracking' => 'Tracking & Scent Work',
// 'field' => 'Field',
// 'agility' => 'Agility',
// 'natcommittee' => 'National Specialty Committee',
// 'healthcommittee' => 'Health Committee',
// 'juniors' => 'Juniors',
// ),
// 'profile' => true,
// 'memberslistcsv' => true,
// 'addmember' => true,
// 'required' => false,
// )
// );
//SELECT
// $fields[] = new PMPro_Field(
// 'member_likes_secondary', // input field name, used as meta key
// 'select', // field type
// array(
// 'label' => 'Seccondary Volunteer Event Types',
// 'options' => array(
// '' => '', // blank option displayed first
// 'obedience' => 'Rally & Obedience',
// 'confirmation' => 'Confirmation & Stewarding',
// 'tracking' => 'Tracking & Scent Work',
// 'field' => 'Field',
// 'agility' => 'Agility',
// 'natcommittee' => 'National Specialty Committee',
// 'healthcommittee' => 'Health Committee',
// 'juniors' => 'Juniors',
// ),
// 'profile' => true,
// 'memberslistcsv' => true,
// 'addmember' => true,
// 'required' => false,
// )
// );
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes', // location on checkout page
$field // PMProRH_Field object
);
}
unset( $field );
// that's it. see the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_initial_memberships_start_date' );
/*
* Allow large JOIN operations in the Member Directory and Profiles Add On for Paid Memberships Pro.
*
* 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 pmpromd_set_db_option() {
global $wpdb;
$wpdb->query( "SET SESSION SQL_BIG_SELECTS=1" );
}
add_action( 'init', 'pmpromd_set_db_option', 5 );
/*
* Allow members to upload their avatar using a Register Helper field during checkout or on the Member Profile Edit page.
*
* Requires: Paid Memberships Pro, Register Helper Add On.
*
* 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/
*/
// Filter the saved or updated User Avatar meta field value and add the image to the Media Library.
function my_updated_user_avatar_user_meta( $meta_id, $user_id, $meta_key, $meta_value ) {
// Change user_avatar to your Register Helper file upload name.
if ( 'user_avatar' === $meta_key ) {
$user_info = get_userdata( $user_id );
$filename = $meta_value['fullpath'];
$filetype = wp_check_filetype( basename( $filename ), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'post_mime_type' => $filetype['type'],
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
'post_status' => 'inherit',
);
$attach_id = wp_insert_attachment( $attachment, $filename );
// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
require_once ABSPATH . 'wp-admin/includes/image.php';
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
update_user_meta( $user_id, 'wp_user_avatar', $attach_id );
}
}
add_action( 'added_user_meta', 'my_updated_user_avatar_user_meta', 10, 4 );
add_action( 'updated_user_meta', 'my_updated_user_avatar_user_meta', 10, 4 );
// Filter the display of the the get_avatar function to use our local avatar.
function my_user_avatar_filter( $avatar, $id_or_email, $size, $default, $alt ) {
$my_user = get_userdata( $id_or_email );
if ( ! empty( $my_user ) ) {
$avatar_id = get_user_meta( $my_user->ID, 'wp_user_avatar', true );
if ( ! empty( $avatar_id ) ) {
$avatar = wp_get_attachment_image_src( $avatar_id, array( $size, $size) );
$avatar = "<img alt='{$alt}' src='{$avatar[0]}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
}
return $avatar;
}
add_filter( 'get_avatar', 'my_user_avatar_filter', 20, 5 );
// Add the User Avatar field at checkout and on the profile edit forms.
function my_pmprorh_init_user_avatar() {
//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(
'user_avatar', // input name, will also be used as meta key
'file', // type of field
array(
'label' => 'Avatar',
'hint' => 'Recommended size is 100px X 100px',
'profile' => true, // show in user profile
'preview' => true, // show a preview-sized version of the image
'addmember' => true,
'allow_delete' => true,
)
);
//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
);
}
}
add_action( 'init', 'my_pmprorh_init_user_avatar' );