Skip to content

Instantly share code, notes, and snippets.

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

Ronald Huereca ronalfy

🏠
Working from home
View GitHub Profile
@ronalfy
ronalfy / pmpro-archive-redirect.php
Created February 26, 2020 16:15
Paid Memberships Pro Archive Redirect Based on Member Level
<?php
function pmpro_archive_redirect() {
$levels_to_check = array(
1,
2,
3,
);
if ( ( is_tax() || is_archive() || is_search() ) && function_exists( 'pmpro_hasMembershipLevel' ) ) {
if ( ! pmpro_hasMembershipLevel( $levels_to_check ) ) {
wp_redirect( pmpro_url( 'levels' ) );
@ronalfy
ronalfy / pmpro-directory-sort-last-name.php
Last active November 12, 2021 16:21
Paid Memberships Pro Directory Sort by Last Name and First Name
<?php
/**
* Sort the membership directory by lastname first, then first name.
*
* 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 pmpro_custom_directory_sql_parts( $parts ) {
@ronalfy
ronalfy / directory.php
Created March 2, 2020 14:07
Paid Memberships Pro Directory Customization
<?php
/*
This shortcode will display the members list and additional content based on the defined attributes.
*/
function pmpromd_shortcode($atts, $content=null, $code="")
{
// $atts ::= array of attributes
// $content ::= text within enclosing form of shortcode element
// $code ::= the shortcode found, when == callback name
// examples: [pmpro_member_directory show_avatar="false" show_email="false" levels="1,2"]
@ronalfy
ronalfy / pmpro-learndash-course-visibility.php
Last active April 3, 2021 03:30
Paid Membership Pro Course Visibility With Learndash
<?php
global $pmpro_learndash_level_courses, $pmpro_learndash_my_courses;
function pmpro_learndash_course_visibility() {
global $pmpro_learndash_level_courses, $pmpro_learndash_my_courses;
if ( is_user_logged_in() && function_exists( 'pmpro_getMembershipLevelForUser' ) && class_exists( 'Learndash_Paidmemberships' ) && function_exists( 'learndash_user_get_enrolled_courses' ) ) {
global $current_user;
$levels = pmpro_getMembershipLevelForUser( $current_user->ID );
if ( $levels ) {
$level_id = $levels->ID;
$pmpro_learndash_level_courses = Learndash_Paidmemberships::get_level_courses( $level_id );
@ronalfy
ronalfy / pmpro-list-child-accounts-directory-listing.php
Created March 3, 2020 20:12
Paid Memberships Pro - List Sponsored (Child) Accounts in Directory Listing
<td>
<?php
// For use in a custom directory.php template after $auser has been defined.
$user_ids = pmprosm_getChildren( $auser->ID );
if ( ! empty( $user_ids ) ) {
$user_list = new WP_User_Query( array(
'include' => $user_ids,
'orderby' => 'name',
'order' => 'ASC'
) );
@ronalfy
ronalfy / pmpro-prorated-expiration.php
Created March 4, 2020 18:53
Paid Memberships Pro: Prorated Amount Based on Current Time and Beginning of Next Year
<?php
function pmpro_prorated_checkout_level( $level ) {
// 5 is the membership level ID.
if ( 5 === absint( $level->id ) ) {
$price_per_day = $level->initial_payment / 365.2425; // 365.2425 is the days in a year
// Get timestamp for end of year and current timestamp.
$end_date_timestamp = strtotime( 'first day of january next year' );
$current_date_timestamp = time();
@ronalfy
ronalfy / pmpro-hide-invite-code-with-approvals-add-on.php
Created March 5, 2020 15:08
Paid Memberships Pro - Hide Membership Invite Code with Approvals Add On
<?php
function pmpro_invite_approval_message() {
if ( is_user_logged_in() ) {
global $current_user;
$user_id = $current_user->ID;
if ( ! PMPro_Approvals::isApproved( $user_id, 1 ) ) { // 1 is the membership level.
remove_filter( "pmpro_confirmation_message", "pmproio_pmpro_confirmation_message" );
remove_filter('the_content', 'pmproio_the_content_account_page', 20, 1);
}
}
@ronalfy
ronalfy / My_PMPro_Directory_Widget.php
Last active March 23, 2020 14:41 — forked from dparker1005/My_PMPro_Directory_Widget.php
Add widget to Member Directory page to filter results.
<?php
/**
* Plugin Name: My PMPro Directory Widget
* Description: Add widget to Member Directory page to filter results.
*/
class My_PMPro_Directory_Widget extends WP_Widget {
/**
* Sets up the widget
*/
@ronalfy
ronalfy / pmpro-rh-ec-fields.php
Created March 5, 2020 23:34
Paid Memberships Pro Register Helper Adding Emergency Contact Fields
<?php
// We have to put everything in a function called on init, so we are sure Register Helper is loaded.
function pmpro_register_field_peakbagger_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
pmprorh_add_checkout_box( 'contact', 'Contact Information' );
pmprorh_add_checkout_box( 'emergency', 'Emergency Contact Information' );
@ronalfy
ronalfy / pmpro-rh-ci-fields.php
Created March 6, 2020 00:01
Paid Memberships Pro Register Helper Company Information Fields
<?php
// We have to put everything in a function called on init, so we are sure Register Helper is loaded.
function pmpro_register_field_trialsofg_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
pmprorh_add_checkout_box( 'company', 'Company Information' );
// Define the fields.