Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Standiford alexstandiford

View GitHub Profile
View Hash_Generator.php
<?php
class Hash_Generator {
/**
* The generated hash.
*
* @var string
*/
private $hash = false;
@alexstandiford
alexstandiford / add-sales-revenue-to-affiliate-area.php
Last active Jun 3, 2020
Adds sales revenue to affiliate area.
View add-sales-revenue-to-affiliate-area.php
<?php
/**
* Adds a section showing the total sales earned by the affiliate to the AffiliateWP affiliate area's statistics tab.
*/
add_action( 'affwp_affiliate_dashboard_after_earnings', function( $affiliate_id ) {
// You can add or remove statuses here. Any status shown in this array will be included in the calculation.
// Supported statuses are paid, unpaid, pending, and rejected.
$statuses = [ 'paid', 'unpaid', 'pending', ];
@alexstandiford
alexstandiford / wp-darkmode.css
Last active May 7, 2020
WordPress Dark Mode CSS. Grabbed from the Dark Mode plugin in the WordPress repository.
View wp-darkmode.css
body:not(.gutenberg-editor-page) {
background-color: #111111;
color: #bbc8d4
}
body:not(.gutenberg-editor-page) #wpbody,
body:not(.gutenberg-editor-page) #wpfooter {
background-color: #111111;
color: #bbc8d4
}
View gist:fcf262fd35ab2361a145a7e17e5d5313
javascript:(function(){ const outline = document.querySelector('.outline-everything-with-red'); if(!outline){ style = document.createElement('style'); style.classList.add('outline-everything-with-red'); style.appendChild(document.createTextNode('* {outline: 1px solid red;}')); document.head.appendChild(style); console.log('The following elements appear to be wider than the document.'); [].forEach.call( document.querySelectorAll('*'), function(el) { if (el.offsetWidth > docWidth) { console.log(el); } } ); } else{ outline.remove(); } var docWidth = document.documentElement.offsetWidth; })()
View manipulate-referral.php
<?php
// Manipulate referral that was just created for the specified order ID
// This example is WooCommerce-specific. The action used is based on whatever action is used to run 'get_pending_referral' in your integration class.
// Integration class is located in includes/integrations/
add_action( 'woocommerce_checkout_update_order_meta',function( $order_id ){
$referral = affilite_wp()->referrals->get_by('reference',$order_id);
if( $referral ){
// Change referral based on params here.
}
@alexstandiford
alexstandiford / custom-type.php
Created Apr 2, 2020
Create a custom Referral Type in AffiliateWP
View custom-type.php
<?php
add_action('affwp_referral_type_init',function( $registry ){
$registry->register_type( 'custom_type', array(
'label' => __( 'Custom Type', 'text-domain' ),
) );
}
@alexstandiford
alexstandiford / Custom_Integration.php
Last active Jul 2, 2020
Set up an Custom AffiliateWP Integration
View Custom_Integration.php
<?php
/**
* Custom Integration Class
*
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
View webpack.config.js
/**
* Webpack Config.
*
* This configuration is a fork of the config that comes with the block editor scripts.
*/
/**
* External dependencies
*/
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
@alexstandiford
alexstandiford / inactive-affiliate-404-redirect.php
Created Jan 3, 2020
Redirects any URL that refers an inactive affiliate to the 404 page.
View inactive-affiliate-404-redirect.php
<?php
/*
* Any URL that refers an inactive affiliate will be redirected to the 404 page.
*
* @since 1.0.0
*/
add_action( 'template_redirect', function() {
global $wp_query;
// Return early if not using AffiliateWP.
@alexstandiford
alexstandiford / install-wp-tests.sh
Created Aug 2, 2019
Script to set up a WordPress test environment for add-ons that requires other plugins as dependencies.
View install-wp-tests.sh
#!/usr/bin/env bash
# ===================================================================================================
# Script to set up a WordPress test environment for add-ons that requires other plugins as dependencies.
# Note that this uses Composer to install the dependencies, so each dependent plugin must have Composer
# Configured properly in-order for this tool to install the dependencies properly.
#
# Ultimately, this is a modified version of the default shell script that is obtained with wp-cli's
# wp scaffold plugin-tests command. It has been updated to include steps that will install composer
# dependencies inside of the test environment's plugin directory.
You can’t perform that action at this time.