Skip to content

Instantly share code, notes, and snippets.

View ipokkel's full-sized avatar

Theuns Coetzee ipokkel

View GitHub Profile
@tsi
tsi / newsite
Last active May 27, 2018 09:39
Bash script to create virtual hosts and prepare your drupal directory.
#!/bin/bash
# This script creates virtual hosts and prepares your mysql DB and drupal directory.
# you should put it under /usr/local/bin/
# and run it with sudo newsite
# Set the path to your localhost
www=/var/www
echo "Enter directory name under $www"
read sn
@jonathantneal
jonathantneal / README.md
Last active June 28, 2018 04:17
Importing CSS from within CSS using PostCSS

[PostCSS] is a powerful tool for transforming stylesheets. If it’s unfamiliar to you, PostCSS turns stylesheets into readable objects in JavaScript called ASTs (Abstract Syntax Trees) and then turns those ASTs back into stylesheets, completing the circle.

Nothing changes. What’s the fun in that? The greatness of PostCSS is found in PostCSS plugins.

PostCSS plugins read and modify the AST before it’s turned back into a stylesheet. There are plugins to automatically add [vendor prefixes] to properties and selectors, or interpret Sass-like [variables], [mixins], and [loops], or down-mix [future] and [experimental] features to CSS. PostCSS plugins can even generate entirely new documents based on the CSS, like [styleguides].


Writing a PostCSS plugin is remarkably simple, thanks to its solid API. Still, one of the first challenges aspiring plugin authors face is importing other files. In other words, replacing links in a stylesheet with the contents of those links. This is where something like `@import

@andrewlimaza
andrewlimaza / rh_example_location.php
Last active March 26, 2019 20:46
Change location where Register Helpers are shown depending if user is logged in or not for Paid Memberships Pro.
<?php
// Show the custom Register Helper Fields in a different location if the user is logged in.
function my_pmprorh_init()
{
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
@messica
messica / my_profile_redirect.php
Created December 21, 2018 00:20
Redirect wp-admin profile to BuddyPress Profile
<?php
/**
* Redirect wp-admin profile to BuddyPress Profile
*/
function my_profile_redirect() {
global $current_user;
if(defined('IS_PROFILE_PAGE') && !current_user_can('manage_options')) {
wp_redirect("/members/$current_user->user_login/profile");
exit;
@kimcoleman
kimcoleman / redirect_profile_page_to_bbpress_user_profile.php
Last active March 27, 2019 17:19
Redirect the Member's Profile page to the bbPress User Profile when using the Member Directory and Profile Pages Add On for Paid Memberships Pro
<?php
/**
* Use this recipe to redirect the Profile page as defined under Memberships > Page Settings to the member's
* bbPress User Profile when using the Member Directory and Profile Pages Add On in conjunction with bbPress.
*
* You must set a placeholder page under Memberships > Page Settings > Profile in order for this redirect to work.
*/
function redirect_profile_page_to_bbpress_user_profile() {
global $pmpro_pages;
if ( ! empty( $pmpro_pages ) && ! empty( $pmpro_pages['profile'] ) && is_page( $pmpro_pages['profile'] ) ) {
@ideadude
ideadude / init_create_my_administrator_user.php
Created February 13, 2018 17:23
Create a WordPress administrator user account via PHP/FTP.
<?php
/*
Sometimes you have FTP access to a site, but don't have a WP administrator account.
You can use this code to create one.
1. Add this code into any plugin or theme file that you know will be run.
2. Visit /?createmyadministratoruser=1.
3. Delete the code you added.
*/
function init_create_my_administrator_user() {
@pbrocks
pbrocks / redirect-to-login-if-not-logged-in.php
Created December 24, 2018 02:19
Redirect to login if not logged in or if not PMPro membership page.
<?php
/**
* Redirect to login or homepage if user is logged out or not a member
* Add this code to your active theme's functions.php file.
*/
function my_template_redirect() {
global $current_user;
$okay_pages = array(
pmpro_getOption( 'billing_page_id' ),
@andrewlimaza
andrewlimaza / hide-approval-members-directory.php
Created April 4, 2019 09:27
Hide Members from Member Directory Page when not approved [Paid Memberships Pro]
<?php
/**
* PLEASE NOTE: This will affect only new signups that have happened after this code has been added to your site
* (this won't run through existing pending/denied members and update their directory status).
* This will run on checkout and every time a member is approved, denied or reset in the Approvals Add On.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
// Hide users from Directory when level requires Approval + show them once they are approved.
function hide_user_from_directory_if_level_requires_approval( $level_id, $user_id ) {
@andrewlimaza
andrewlimaza / rh-payment-type-pay-by-check.php
Last active April 5, 2019 09:42
Pay By Check select a payment type from Register Helper Add On.
<?php
/**
* Creates a custom field for checkout called "Payment Type" which will allow you to specify which payment type was selected for an order.
* Saves the selection inside the Order > Payment Type.
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmprorh_init() {
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
@greathmaster
greathmaster / pmpro-subscription-delays-with-prorated-initial-payment.php
Created February 2, 2018 21:40
Custom subscription delay with prorating. Read comments and description for details.
/*
Uses PMPro Subscription Delays Add On to set date of first paymen to the first of next month. So if current date is: 2018-03-21, date
of first subscription payment is 2018-04-01. Initial payment is prorated based on signup date uses total number of weekdays as the base.
For example if the date is 2018-02-02 (February 2nd, 2018). They will be charged (19/20)*$initial_payment.
*/
function my_pmprosd_modify_start_date($start_date, $order, $subscription_delay)
{
$day_number = date('j');
$month_number = date('m') ;