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
<?php
function my_redirect_non_members_example() {
// Check if a non-member is trying to access any other page besides the above or home page.
if ( is_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.
exit;
}
}
<?php
/**
* add Register Helper
*/
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
@femiyb
femiyb / check_valid_date.php
Created February 14, 2020 12:30
Set default date and check valid date
<?php
/**
* PMPro Customization: Register Helper - Add date of birth date picker to checkout
*/
//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
<?php
/**
* Adds text after the level cost text.
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function add_text_before_submit() {
echo 'Add additional text here';
}
add_action( 'pmpro_checkout_after_level_cost', 'add_text_before_submit' );
<?php
function my_pmprorh_init() {
//don't break if Register Helper is not loaded
if(!function_exists( "pmprorh_add_registration_field" )) {
return false;
}
$fields = array();
$fields[] = new PMProRH_Field(
@femiyb
femiyb / add_new_role.php
Created February 21, 2020 10:42
Add new role on level change
<?php
function action_pmpro_after_change_membership_level( $level_id, $user_id, $cancel_level )
{
$user = get_userdata($user_id);
if($level_id == 1)
{
$user->add_role( 'editor' );
}
@femiyb
femiyb / remove-custom-trial-for-existing-members.php
Last active April 14, 2021 11:10 — forked from andrewlimaza/remove-custom-trial-for-existing-members.php
Remove trial limit for existing members. [Paid Memberships Pro]
<?php
/**
* Remove custom trial for existing members (when existing member changes levels/renews)
* Adjust the level ID on line 15 to match your needs.
* Add this code to your WordPress site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_level_adjustment( $level ) {
// Bail if the user currently doesn't have a membership level.
<?php
function action_pmpro_after_change_membership_level( $level_id, $user_id )
{
$user = get_userdata($user_id);
$role_levels = array(1,2,3);
if(in_array($level_id, $role_levels))
{
$user->add_role( 'subscriber' );
<?php // Do NOT copy this line
/* Copy from below this line */
function pmpro_remove_bfields( $pmpro_required_billing_fields ){
//remove field ID's from array to make fields required
$remove_field = array('bfirstname', 'blastname');
//loop through the $remove_field array and unset each billing field to make it optional.
@femiyb
femiyb / translate-pmpro.php
Last active July 27, 2020 19:12 — forked from andrewlimaza/translate-to-french.php
Translate PMPro
<?php
// Please add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
function my_pmpro_change_text($translated_text, $original_text, $domain) {
switch ( $translated_text ) {
case 'First Name' :
$translated_text = __( 'Change First Name.', 'paid-memberships-pro' );
break;