Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / heartbeat-api-demo.php
Last active April 30, 2024 17:08
Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
<?php
/*
Plugin Name: Heartbeat API Demo
Plugin URI: http://www.strangerstudios.com/wp/heartbeat-api-demo
Description: Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
Version: .1
Author: strangerstudios
If logged in as a user and viewing the frontend of your website,
every 15 seconds you should see the following in your Javascript console:
@strangerstudios
strangerstudios / protect_specific_page.php
Last active April 23, 2024 12:52
Protect a specific page with PMPro
/*
Protect a specific page with PMPro
Edit the code below to check your specific page slug and membership level ID.
Add this code to your active theme's functions.php or a custom plugin.
*/
function protect_specific_page()
{
//make sure PMPro is active
@strangerstudios
strangerstudios / gist:3111478
Last active April 23, 2024 12:52
Lockdown BuddyPress with Paid Memberships Pro Example
<?php
/*
Plugin Name: PMPro BuddyPress Customizations
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-buddypress-customizations/
Description: Example code to lock down parts of BuddyPress with PMPro
Version: 0.2
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
/*
@strangerstudios
strangerstudios / pmpro_hide_urls.php
Created November 5, 2014 22:49
Redirect away from certain URLs with PMPro.
/*
Redirect away from certain URLs with PMPro.
Becareful, the code will redirect any URL *containing* the strings in the $urls array.
So e.g., if /not-locked/about/ is public and you have /about/ in the list, it will still be locked down to non-members.
*/
//hide some pages in buddypress
function pmpro_hide_urls()
{
//make sure PMPro is activated
if(!function_exists('pmpro_hasMembershipLevel'))
@strangerstudios
strangerstudios / pmpro-limit-members-per-level.php
Last active April 16, 2024 09:29 — forked from greathmaster/pmpro-limit-members-per-level.php
Limit the number of total sign ups for a given membership level
<?php
/*
Set a maximum number of members allowed to register for a membership level.
Add this code to a plugin for PMPro Customizations.
Set the "Maximum" for a level on the Memberships > Membership Levels > Edit Level admin page.
*/
function pmproml_pmpro_save_membership_level( $level_id) {
if( $level_id <= 0 ) {
@strangerstudios
strangerstudios / my_pmpro_category_filter.php
Last active April 14, 2024 16:20
Add specific members-only categories back to main loop when filtering searches and archives.
<?php
function my_pmpro_category_filter($query)
{
//get the members-only hidden categories
$hidden_cat_ids = $query->query_vars['category__not_in'];
//set the members-only category IDs NOT to filter
$not_hidden_cat_ids = array('1','10');
//add hidden category IDs back to the query
@strangerstudios
strangerstudios / pmpro_register_redirect.php
Created November 14, 2014 21:44
Disable the PMPro redirect from default WordPress register page to PMPro levels page.
//add this line to your active theme's functions.php or a custom plugin
add_filter('pmpro_register_redirect', '__return_false');
@strangerstudios
strangerstudios / pmpro_is_page.php
Last active January 22, 2024 17:08
Tests to check if you are on certain PMPro pages.
<?php
global $pmpro_pages, $pmpro_level;
if(is_page($pmpro_pages['levels'])) {
//on the pricing/levels page
}
if(is_page($pmpro_pages['checkout'])) {
//on the checkout page
}
@strangerstudios
strangerstudios / my_pmpro_not_logged_in_text_filter.php
Created November 16, 2015 14:56
Filter the teaser message text for a not logged in site visitor
function my_pmpro_not_logged_in_text_filter($text)
{
global $post;
$access = pmpro_has_membership_access($post->ID, NULL, true);
$level_ids = $access[1];
if(is_array($level_ids) && in_array(2, $level_ids))
{
$text = '<h4>This page requires a Bronze Account or higher.</h4><p>Already have an account? <a href="/login?redirect_to=' . urlencode($_SERVER['REQUEST_URI']) . '">Login Now »</a></p><p>New to this site? <a href="/membership-checkout/?level=2">Register Now »</a></p>';
@strangerstudios
strangerstudios / get_user_metadata_pmpro_prepop.php
Created October 29, 2015 16:10
Default some PMPro fields based on other user meta.
/*
Default some PMPro fields based on other user meta.
Add this code to your active theme's functions.php or a custom plugin.
*/
function get_user_metadata_pmpro_prepop($value, $user_id, $meta_key, $single)
{
//fields to sync, make sure there are no loops in this
$sync_fields = array(
"pmpro_bfirstname" => "first_name",