Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
strangerstudios / my_pmpro_member_startdate.php
Created April 5, 2014 04:59
Use pmpro_member_startdate filter to set member start date to their user registered date instead of membership start date.
/*
Set member start date to their user registered date instead of membership start date.
*/
function my_pmpro_member_startdate($timestamp, $user_id)
{
$user = get_userdata($user_id);
return strtotime($user->user_registered);
}
add_filter('pmpro_member_startdate', 'my_pmpro_member_startdate', 10, 2);
@strangerstudios
strangerstudios / custom_pmpro_getMemberStartdate.php
Created April 16, 2014 15:55
Change pmpro_getMemberStartdate to have everyone starting at 6am.
function custom_pmpro_getMemberStartdate($timestamp, $user_id, $level_id)
{
global $wpdb;
//get timestamp
$sqlQuery = "SELECT UNIX_TIMESTAMP(startdate) FROM $wpdb->pmpro_memberships_users WHERE user_id = '" . esc_sql($user_id) . "' ORDER BY id LIMIT 1";
$timestamp = $wpdb->get_var($sqlQuery);
//convert to 6am
$datetime = date("Y-m-d", $timestamp) . " 06:00";
@strangerstudios
strangerstudios / mc_isMinecraftUsername.php
Last active August 29, 2015 14:00
Make sure people use their Mine Craft username when checking out with Paid Memberships Pro
/*
Make sure people use their Minecraft username when registering.
*/
//uses Minecraft website to test a username and returns true or false
function mc_isMinecraftUsername($username, $force = false)
{
global $premium_minecraft_usernames;
if(!is_array($premium_minecraft_usernames))
$premium_minecraft_usernames = array();
@strangerstudios
strangerstudios / xmlrpc_template.php
Created April 24, 2014 16:52
Use TwentyTen theme for XMLPRC Requests.
function xmlrpc_template($template)
{
if($_SERVER['SCRIPT_NAME'] == "/xmlrpc.php")
return "twentyten";
else
return $template;
}
add_filter('template', 'xmlrpc_template');
add_filter('option_template', 'xmlrpc_template');
add_filter('option_stylesheet', 'xmlrpc_template');
@strangerstudios
strangerstudios / gist:11312833
Created April 26, 2014 05:58
SQL to remove Paid Memberships Pro levels from users, delete orders, and delete discount code uses. This will NOT cancel subscriptions at the payment gateway.
#Back up first. USE AT YOUR OWN RISK
TRUNCATE TABLE `wp_pmpro_memberships_users`;
TRUNCATE TABLE `wp_pmpro_membership_orders`;
TRUNCATE TABLE `wp_pmpro_discount_codes_uses`;
@strangerstudios
strangerstudios / pmpro_xmlrpc_methods.php
Created May 7, 2014 21:21
Add our methods to the WordPress XMLRPC API. Each method points to a callback function to handle it.
<?php
/**
* Define the XMLRPC Methods We Add
* Since v2.0
*/
add_filter('xmlrpc_methods', 'pmpro_xmlrpc_methods');
function pmpro_xmlrpc_methods($methods)
{
$methods['pmpro.getMembershipLevelForUser'] = 'pmpro_xmlrpc_getMembershipLevelForUser';
$methods['pmpro.hasMembershipAccess'] = 'pmpro_xmlrpc_hasMembershipAccess';
@strangerstudios
strangerstudios / pmpro_xmlrpc_hasMembershipAccess.php
Created May 7, 2014 21:23
API method to check if a user has access to a certain post.
<?php
/**
* API method to check if a user has access to a certain post.
* Since v2.0
*/
function pmpro_xmlrpc_hasMembershipAccess($args)
{
// Parse the arguments, assuming they're in the correct order
$username = $args[0];
$password = $args[1];
@strangerstudios
strangerstudios / my_init_test.php
Created May 7, 2014 21:35
Use the WordPress IXR Client to query a remote XMLRPC method.
<?php
function my_init_test()
{
//check for ?test=1 or do nothing
if(empty($_REQUEST['test']))
return;
//user id to test
$remote_user_id = 1;
@strangerstudios
strangerstudios / gist:75899c6cf673cb1d1415
Created June 4, 2014 13:54
sample apache vhost.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin email@domain.com
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/vhosts/domain1.com/httpdocs/
ErrorLog /var/www/vhosts/domain1.com/logs/error.log
CustomLog /var/www/vhosts/domain1.com/logs/access.log combined
</VirtualHost>
@strangerstudios
strangerstudios / ninja_forms_change_from_address.php
Created June 27, 2014 23:59
Ninja Forms use email from form for email_from and email_from_name.
add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
function ninja_forms_change_from_address(){
global $ninja_forms_processing;
if( 1 == $ninja_forms_processing->get_form_ID() ) {
$user_email = $ninja_forms_processing->get_field_value( 2 );
$user_name = $ninja_forms_processing->get_field_value( 1 );
$ninja_forms_processing->update_form_setting( 'email_from', $user_email );
$ninja_forms_processing->update_form_setting( 'email_from_name', $user_name );
}
}