Skip to content

Instantly share code, notes, and snippets.

View pbrocks's full-sized avatar

Paul Barthmaier pbrocks

View GitHub Profile
@pbrocks
pbrocks / pmpro-defult-country-code.php
Created December 2, 2017 21:38
Code to add to pmpro-customizations.php to adjust default country for PMPro VAT
/**
* Default to country code for Spain if none is set.
* Add to PMPro Customizations plugin.
*/
function init_set_default_vat_country_code() {
//default to Spain
if(!isset($_SESSION['eucountry'])) {
$eucountry = 'ES';
}
}
@pbrocks
pbrocks / http2https.htaccess
Created December 6, 2017 07:17 — forked from strangerstudios/http2https.htaccess
Forward HTTP requests to HTTPS in Apache htaccess
# Forward HTTP requests to HTTPS
# (!) Make sure to place this under your RewriteEngine On and Rewrite Base lines.
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
@pbrocks
pbrocks / pmpro-redirect-away-from-subsite.php
Created December 21, 2017 07:31
Redirect away from PMPro subsite
<?php
/**
* Plugin Name: PMPro Customizations
*/
add_action( 'template_redirect', 'redirect_away_from_site_two' );
function redirect_away_from_site_two() {
global $current_user;
// Administrators are unaffected by the redirection.
if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
@pbrocks
pbrocks / accordion.css
Last active January 4, 2018 16:36
Checkout file with accordion to be added to child theme PMPro pages folder to override plugin checkout.php.
#tab-one #pmpro_checkout_box-checkout_boxes h3,
#pmpro_payment_information_fields > thead > tr > th > span.pmpro_thead-name {
display: none;
}
#tab-two thead tr th,
#pmpro_payment_information_fields > thead > tr > th > span.pmpro_thead-msg {
color: #2997c8;
}
/* Accordion styles */
.tab.accordion {
@pbrocks
pbrocks / bootstrap-config.json
Last active January 7, 2018 00:36 — forked from anonymous/config.json
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@pbrocks
pbrocks / pmpro-membership-user-information-dashboard-menu.php
Created January 8, 2018 22:07
Add to PMPro Customizations plugin to create a dashboard page showing current user membership information.
<?php
/**
* Add to PMPro Customizations plugin to create a dashboard page showing current user membership information.
*/
function membership_user_information_menu() {
add_dashboard_page( __( 'PMPro Dash Menu', 'pmpro-customizations' ), __( 'PMPro Dash Menu', 'pmpro-customizations' ), 'manage_options', 'membership-user-information.php', 'membership_user_information' );
}
add_action( 'admin_menu', 'membership_user_information_menu' );
function membership_user_information() {
global $current_user;
@pbrocks
pbrocks / neato-content-filter.php
Created January 11, 2018 05:10
neato-content-filter.php is a sample filter for the_content in WordPress
add_filter( 'the_content', 'neato_content_filter', 20 );
/**
* Add a spinning icon to the beginning of every post page.
*
* @uses is_single()
*/
function neato_content_filter( $content ) {
if ( is_page() ) {
// Add image to the beginning of each page
@pbrocks
pbrocks / plugin.php
Created January 12, 2018 21:36 — forked from mathetos/plugin.php
Dependent Plugin Activation/Deactivation and Alert
<?php
/*
* Dependent Plugin Activation/Deactivation
*
* Sources:
* 1. https://pippinsplugins.com/checking-dependent-plugin-active/
* 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*
*/
@pbrocks
pbrocks / pmpro_member_data_shortcode.php
Created January 19, 2018 16:35 — forked from andrewlimaza/pmpro_member_data_shortcode.php
Shortcode to get membership level data for a user
<?php
/**
* Shortcode to retrieve information about a user startdate/enddate
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
* www.paidmembershipspro.com - A membership plugin for WordPress.
*/
function pmpro_member_data_shortcode( $atts, $content=null, $code='' ) {
global $current_user;
@pbrocks
pbrocks / get-ip-address-optimized.php
Created February 2, 2018 22:54 — forked from cballou/get-ip-address-optimized.php
PHP - Advanced Method to Retrieve Client IP Address
<?php
function get_ip_address() {
$ip_keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
foreach ($ip_keys as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
// trim for safety measures
$ip = trim($ip);
// attempt to validate IP
if (validate_ip($ip)) {