Skip to content

Instantly share code, notes, and snippets.

View ipokkel's full-sized avatar

Theuns Coetzee ipokkel

View GitHub Profile
@kimcoleman
kimcoleman / my_pmpro_remove_subscription_delay_for_renewals.php
Created July 11, 2022 14:07
Remove subscription delay for existing/past members. Charge them the full level price immediately at checkout. Update the level cost text.
<?php
/**
* Remove subscription delay for existing/past members.
*/
function my_pmpro_remove_subscription_delay_for_renewals() {
if ( is_admin() || ! is_user_logged_in() ) {
return;
}
$order = new MemberOrder();
<?php
/**
* Grant access to the back-end to certain user roles
*
* @param bool $prevent_admin_access
*
* @return bool
*/
function pmpro_grant_admin_access_to_dataanalyst( $prevent_admin_access ) {
if ( current_user_can( 'dataanalyst' ) ) {
<?php // do not copy this line.
/**
* Sponsored Members setup with child seat costs at checkout.
* SPONSOR SEAT + 4 seats 19.95 each
* + 5 to 19 @ 17.95
* + 20 to 39 @ $15.95
* + 40 to 79 @ 14.95
*
* 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.
@ipokkel
ipokkel / readonly-on-profile-page-registration-field.php
Last active March 24, 2022 06:56
Set a custom registration field for PMPro Register Helper as readonly on the profile edit page.
<?php
/**
* Readonly field on profile edit page.
*
* Add profile_readonly to field and set to true.
*
* Fields with this option will remain editable if the field is empty, or
* if the current user can manage options (administrators), or
* if the current user is a membership manager that have a
* membership manager role.
@ipokkel
ipokkel / wp-mail-log.php
Last active March 10, 2022 08:45
Debugging email for WordPress. Logs mail erorrs,
<?php
/**
* WordPress Mail Debugger
*
* Log mail error message to debug-mail.log in wp-contents folder.
* Log mail error to debug.log in wp-contents folder.
*/
function wp_mail_error_log( $wp_error ) {
// Log mail error message to debug-mail.log file in wp-contents folder
@ipokkel
ipokkel / add-required-html-attribute.php
Last active May 9, 2022 16:21
Add required HTML attribute to required fields on PMPro Checkout Page.
<?php
/**
* Add HTML5 attribute required to all required PMPro 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/
*/
@dparker1005
dparker1005 / load-pmpro-stripe-library.php
Last active February 24, 2022 16:49
Make sure that PMPro loads the Stripe library first if other plugins are loading outdated versions on every page load.
<?php
/**
* Make sure that PMPro loads the Stripe library first if other plugins are loading outdated
* versions on every page load. This is a blunt way to address the conflict and should be used
* with caution.
*
* To use, add as a new file in your site's `wp-content/mu-plugins/` folder.
*/
if ( file_exists( dirname( __FILE__ ) . "/../plugins/paid-memberships-pro/includes/lib/Stripe/init.php" ) && ! class_exists( "Stripe\Stripe" ) ) {
@andrewlimaza
andrewlimaza / clear-stripe-level-meta.php
Created February 16, 2022 15:17
Clear Stripe level meta data [Script]
<?php
/**
* Clear any unnecessary Stripe data from level meta table that may be causing checkout issues.
*
* To run this code add it to your WordPress website by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* Once installed, add ?clean_stripe=1 to any URL while logged-in as an admin.
*
* After running this script, please delete it from your site.
*
* @return void
@kimwhite
kimwhite / my-pmpro-addon-package-access.php
Last active January 25, 2022 14:25
Give access to specific Addon Packages by Level
<?php // do not copy this line.
/**
* Give user's with a certain level ID 4 free access to all some Addon Packages content.
*
* 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/
*/
@andrewlimaza
andrewlimaza / pmpro-addon-packages-woocommerce.php
Last active January 25, 2022 14:17
Add or Remove Addon Package access based on WooCommerce purchased products.
<?php
/**
* Integrate Addon Packages with WooCommerce product purchased (based on the order status).
* Recommended to be used with PMPro WooCommerce to apply a default level for all products that give access to posts (Addon Packages).
*
* To get started, please adjust the $product_ids_to_posts global array which uses a product_id => post_id key/value pair.
* Extend this array for all products that will give access to posts.
*
* Adds access to the post once the order is completed.
* Removes access from the post if the order is set to cancelled, failed or refunded.