Skip to content

Instantly share code, notes, and snippets.

View ipokkel's full-sized avatar

Theuns Coetzee ipokkel

View GitHub Profile
@ipokkel
ipokkel / gettext-with-context-example.php
Created January 9, 2020 07:03
Translate text that has contexts - This filter hook is applied to the translated text by the internationalization function that handle contexts (_x(), _ex(), esc_attr_x() and esc_html_x()).
<?php // do NOT copy this line, copy from below this line
// Add this code below to your PMPro Customizations plugin
// http://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
/**
* This filter hook is applied to the translated text by the internationalization function that handle contexts (_x(), _ex(), esc_attr_x() and esc_html_x()).
*
* @param string $translated
* @param string $text
@andrewlimaza
andrewlimaza / free-downloadable-members-product.php
Created January 8, 2020 08:55
Give members a free WooCommerce downloadable Product [Paid Memberships Pro Snippet]
<?php
/**
* Give certain downloadable products to Paid Memberships Pro members for free.
* Adjust the code to your needs and to match your WooCommerce Product IDs and Membership Level IDs.
* Follow this guide to add the code to your WordPress website - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function free_download_product_for_members( $discount_price, $level_id, $original_price, $product ) {
$allowed_free_products = array( 58, 59, 100, 300, 501); // Adjust this with the WooCommerce Product ID's that are allowed to be discounted.
@dparker1005
dparker1005 / my_pmpro_custom_level_description_add_username.php
Last active January 30, 2020 14:09
Add username to PayPal order description. Equivalent for Authorize.net also included, but commented out.
<?php
// Copy from below here...
/**
* Add username to PayPal order description.
* Equivalent for Authorize.net also included, but commented out.
*/
function my_pmpro_custom_level_description_add_username( $description, $level_name, $order, $site_name ) {
//Initialize $username
@dparker1005
dparker1005 / my_pmpro_redirect_places.php
Last active November 3, 2021 18:20
Will redirect users without a $required_levels away from pages where the request uri begins with '/places/'. Useful to lock down the archive page and CPTs of GeoDirectory plugin.
<?php
// Copy from below here
/**
* Will redirect users without a $required_levels away from pages where the request uri begins with '/places/'.
* Useful to lock down the archive page and CPTs of GeoDirectory plugin.
*/
function my_pmpro_redirect_places() {
$request_uri_to_redirect = '/places/';
@dparker1005
dparker1005 / my_pmpro_disable_incorrect_cancellation_emails.php
Created December 16, 2019 12:05
Prevents a cancellation email from being set if the user was assigned a new membership level during the cancellation process.
<?php
// Copy from below here
/*
* Prevents a cancellation email from being set if the user
* was assigned a new membership level during the cancellation
* process.
*/
function my_pmpro_disable_incorrect_cancellation_emails($recipient, $email)
@kimcoleman
kimcoleman / my_pmpro_members_list_add_company_column.php
Last active March 27, 2020 14:28
Add a custom column to the Memberships > Members admin page for a user field added via Register Helper using a WP List Table filter (PMPro v2.2+).
<?php
/**
* Add a custom column to the Memberships > Members admin page for a user field
* added via Register Helper using a WP List Table filter (PMPro v2.2+).
*
* 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/
*/
@dparker1005
dparker1005 / my_pmpro_bp_give_admins_access.php
Created October 23, 2019 21:29
Give site admins access to PMPro BuddyPress content, even without membership level
<?php
// Copy from below here
/**
* Give site admins access to PMPro BuddyPress content, even without membership level
*/
function my_pmpro_bp_give_admins_access( $can, $check, $user_id ) {
if( current_user_can( 'manage_options' ) ){
@ideadude
ideadude / my_send_pmpro_confirmation_emails_from_dashboard.php
Last active October 24, 2024 15:31
Always send the checkout_free confirmation email in PMPro when changing a user's level in the admin dashboard.
<?php
/**
* Always send the checkout_free confirmation email
* when changing a user's level in the admin dashboard.
*/
function my_send_pmpro_confirmation_emails_from_dashboard( $level_id, $user_id, $cancel_level_id ) {
// If we're not in the dashboard, this is probably a checkout on the frontend
if ( ! is_admin() ) {
return;
}
@messica
messica / my_login_redirect.php
Created October 3, 2019 20:34
Respect redirect_to query parameter when logging in with Member Homepages
<?php
function my_login_redirect( $redirect, $request, $user ) {
if ( ! empty( $request ) ) {
remove_filter('login_redirect', 'pmpromh_login_redirect', 10, 3);
remove_filter('login_redirect','pmpro_login_redirect', 10, 3);
return $redirect;
}
}
add_action( 'login_redirect', 'my_login_redirect', 5, 3 );
<?php
// Copy from below here
/**
* Automatically applies discount code for users switching from a level in a set of given levels.
* Useful for giving discounts to members upgrading their memberships.
* To use, make sure to update the first 2 variables in each function.
*/
function my_pmpro_automatic_discount_application() {