Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / pmpro_hide_account_page_until_validated.php
Last active July 21, 2023 15:56
Hide the PMPro Account page until a user confirms their email address via the PMPro Email Confirmation addon.
/*
Add this function to a custom plugin.
Update your membership confirmation text then to include a reminder about confirming your email.
*/
function pmpro_hide_account_page_until_validated() {
//bail if pmpro or the email confirmation addon is not loaded
if(!function_exists('pmpro_getMembershipLevelForUser') || !function_exists('pmproec_isEmailConfirmationLevel'))
return;
@strangerstudios
strangerstudios / pmproet_templates.php
Created June 17, 2017 15:07
Example of using the pmproet_templates filter in the PMPro Email Templates addon to add your own email templates.
/*
If you add this code into a plugin, then the PMPro Email Templates addon
will allow you to set/change the body of the email through its UI.
You can then send an email using this template using code like:
$email = new PMProEmail();
$email->template = 'my_email_template_name';
$email->email = 'email@youaresendingto.com';
$email->send();
@strangerstudios
strangerstudios / debug_param_for_wp_config.php
Created June 15, 2017 14:43
Enable/disable WP_DEBUG by adding a debug=1 param to any URL
//add this to your wp-config.php file
session_start();
if(!empty($_REQUEST['debug']) || !empty($_SESSION['WP_DEBUG'])) {
define('WP_DEBUG', true);
//define('WP_DEBUG_LOG', true);
$_SESSION['WP_DEBUG'] = true;
} elseif(isset($_REQUEST['debug'])) {
define('WP_DEBUG', false);
unset($_SESSION['WP_DEBUG']);
} else {
@strangerstudios
strangerstudios / init_test_stripe.php
Last active February 21, 2020 08:22
Test a Stripe Webhook Event with WordPress and Paid Memberships Pro
/*
Test Stripe webhook events
Add to a custom plugin, then visit /?teststripe=1
*/
function init_test_stripe() {
if(!empty($_REQUEST['teststripe'])) {
$_REQUEST['event_id'] = 'evt_9ktqwT5xFlKNOp'; //EDIT THIS to be the ID of an actual recurring payment event in your account
require_once(PMPRO_DIR . "/services/stripe-webhook.php");
@strangerstudios
strangerstudios / my_pmproal_extra_cols.php
Last active April 12, 2021 22:30
Show the Member Badge for each level on the table layout Membership Levels page
<?php
/*
Sample method to show a level's Member Badge on the table layout of the
Membership Levels page when using the Advanced Levels Page Shortcode Add On.
*/
function my_pmproal_extra_cols_before_header( ) {
echo '<th>Badge</th>';
}
add_action( 'pmproal_extra_cols_before_header', 'my_pmproal_extra_cols_before_header');
@strangerstudios
strangerstudios / my_pmproal_before_level_member_badge.php
Last active April 12, 2021 22:30
Show the Member Badge for each level on the 3 column layout Membership Levels page
<?php
/*
Sample method to show a level's Member Badge on the three column layout of the
Membership Levels page when using the Advanced Levels Page Shortcode Add On.
*/
function my_pmproal_before_level_member_badge( $level_id, $layout ) {
if( function_exists( 'pmpromb_getBadgeForLevel' ) ) {
$image = pmpromb_getBadgeForLevel($level_id);
if( ! empty( $image ) && $layout == '3col' ) {
echo '<img class="pmpro_member_badge" src="' . esc_url($image) . '" border="0" />';
@strangerstudios
strangerstudios / pmpro_after_change_author_level_update_posts.php
Last active September 27, 2021 17:41
Unpublish an author's posts when their membership is cancelled.
<?php function pmpro_after_change_author_level_update_posts( $level_id, $user_id ) {
//get the user roles
$usermeta = get_userdata($user_id);
$user_roles = $usermeta->roles;
//check if the user is an author and is cancelling
if ( in_array( 'author', $user_roles ) && $level_id == 0 ) {
//get the user's posts
$args = array(
'author' => $user_id,
@strangerstudios
strangerstudios / my_pmprocpt_redirect_to.php
Created May 15, 2017 21:04
Change PMPro CPT to redirect to the login page instead of the chosen "Redirect To" page if the user is logged out.
/*
Change PMPro CPT to redirect to the login page instead of the chosen "Redirect To" page
if the user is logged out.
*/
function my_pmprocpt_redirect_to($redirect_to) {
if(!is_user_logged_in()) {
$redirect_to = wp_login_url($_SERVER['REQUEST_URI']);
}
return $redirect_to;
@strangerstudios
strangerstudios / stillfat.php
Created May 11, 2017 15:39
Sends a text reminder via PHP/PEAR Mail/PEAR Net_SMTP
<?php
/*
1. Make sure PEAR Mail and PEAR Net_SMTP are installed.
2. Add this php script somewhere on your server. (Edit the appropriate lines.)
3. The script assumes a Gmail email and emailing a Verizon VText email address to send via text message.
4. Then add a crontab line like this somewhere send you a message every 2 hours.
55 */2 * * * php /var/scriptfolder/stillfat.php > /dev/null 2>&1
*/
require_once('Mail.php');
@strangerstudios
strangerstudios / pmpro_has_membership_access_filter_for_authors.php
Created April 15, 2017 21:32
Make sure authors can always see their own posts with PMPro
/*
Make sure authors can always see their own posts.
Add this code to a custom plugin.
*/
function pmpro_has_membership_access_filter_for_authors($hasaccess, $mypost, $myuser, $post_membership_levels) {
if($mypost->post_author == $myuser->ID)
$hasaccess = true;
return $hasaccess;