Skip to content

Instantly share code, notes, and snippets.

View femiyb's full-sized avatar
🏠
Working from home

Femi YB femiyb

🏠
Working from home
View GitHub Profile
@femiyb
femiyb / pmpro-send-approval-emails-to-membership-approvers.php
Last active February 12, 2021 13:40
Send approval e-mails to pmpro approver role
<?php
function my_pmpro_email_headers_approval_emails($headers, $email)
{
$args = array('role' => 'pmpro_approver');
$pmpro_approvers = get_users($args);
$pmpro_approvers_emails = array();
foreach($pmpro_approvers as $pmpro_approver)
{
$pmpro_approvers_emails[] = $pmpro_approver->user_email;
<?php
function my_pmpro_members_list_csv_heading($csv_header)
{
$heading = explode(',', $csv_header);
$remove = array('billing firstname', 'billing lastname', 'address1', 'address2', 'city', 'state', 'zipcode', 'country', 'phone');
foreach($heading as $key => $title)
{
if(in_array($title, $remove))
<?php
function my_pmpro_translate_mailchimp($translated_text, $original_text, $domain) {
switch ( $translated_text ) {
case 'Join our mailing list.' :
$translated_text = __( 'Your Changed Text Here', 'pmpro-mailchimp' );
break;
}
return $translated_text;
<?php
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
@femiyb
femiyb / pmpro_changeMembershipLevel.php
Created January 16, 2020 11:25
When users cancel (are changed to membership level 0) we give them another "cancelled" level.
<?php
/**
* When users cancel (are changed to membership level 0) we give them another "cancelled" level.
* Can be used to downgrade someone to a free level when they cancel.
* Will allow members to the "cancel level" to cancel from that though.
*/
function pmpro_after_expiration_change_membership_levels( $level_id, $user_id ) {
// set this to the id of the level you want to give members when they cancel
$last_level_4 = 4;
$level_4_cancel_id = 3;
@femiyb
femiyb / redirect-member-away-from-page.php
Last active February 6, 2020 08:49 — forked from andrewlimaza/redirect-member-away-from-page.php
redirect user away from the page if they do not have a specific membership level.
<?php
/**
* This will redirect members with level 1 from site.com/page-slug to the home page.
* Please adjust accordingly and add to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function redirect_member_from_page_x() {
if ( is_page( 'shop' ) && ! pmpro_hasMembershipLevel() ) {
wp_redirect( home_url('login') ); //redirect to home page. Change home_url() to home_url( '/page-slug' ) to redirect to specific page.
@femiyb
femiyb / rhfield.php
Created January 22, 2020 12:14
Register Helper
<?php
function my_pmprorh_init()
{
//don’t break if Register Helper is not loaded
if(!function_exists("pmprorh_add_registration_field"))
{
return false;
}
@femiyb
femiyb / only_one_discount_code.php
Created January 22, 2020 13:39 — forked from dparker1005/only_one_discount_code.php
Only allows each user to use one discount code.
<?php
/*
Each user can only use one discount code.
Add this to your active theme's functions.php or a custom plugin.
*/
function my_pmpro_check_discount_code($okay, $dbcode, $level_id, $code)
{
global $wpdb, $current_user;
$codes_used = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->pmpro_discount_codes_uses WHERE user_id = '" . $current_user->ID . "'" );
@femiyb
femiyb / my-template-redirect-example.php
Last active January 22, 2020 16:36 — forked from andrewlimaza/my-template-redirect-example.php
Redirect non-members to homepage but allow access to PMPro checkout pages.
<?php
/**
* Redirect non-members (including logged-in non-members) away from restricted pages and to home page.
* This allows non-members to access Paid Memberships Pro checkout/levels pages as well as the default WordPress login page.
*
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_redirect_non_members_example() {
@femiyb
femiyb / no_confirm_email_passwordname_email_only_signup.php
Created January 24, 2020 10:36
no_confirm_email_passwordname_email_only_signup.php
<?php
/**
* Only require First Name, Last Name and Email address to create user.
* This recipe requires Paid Memberships Pro and the Register Helper Add On.
*/
/**
* Hide the Account Information Section
*/