Skip to content

Instantly share code, notes, and snippets.

View alexstandiford's full-sized avatar

Alex Standiford alexstandiford

View GitHub Profile
<?php
/*
Plugin Name: Quick Post Widget
Description: Adds a Quick Post widget that creates and publishes posts with hashtags converted to tags.
*/
// Add the Quick Post widget to the dashboard
function qpw_add_dashboard_widgets() {
wp_add_dashboard_widget('qpw_widget', 'Quick Post', 'qpw_widget_display');
}
<?php
add_action('after_switch_theme', function(){
// Set a flag indicating a new installation
set_theme_mod('theme_version', '1.2.3');
});
// Upgrade routine for backwards compatibility with pre-existing home screen setup.
add_action('init', function() {
// Check if the update logic has already been executed
@alexstandiford
alexstandiford / tailwind.config.js
Created August 27, 2021 17:54
WordPress theme.json that extends Tailwind CSS configs
const fs = require( 'fs' )
const themeJson = fs.readFileSync( './theme.json' )
const theme = JSON.parse( themeJson )
const colors = theme.settings.color.palette.reduce( ( acc, item ) => {
const [color, number] = item.slug.split( '-' )
// If there is a number identifier, make this an object
if(undefined !== number) {
@alexstandiford
alexstandiford / affwp-order-detail-notes.php
Last active February 26, 2021 18:35
Example Plugin Affiliate Dashboard
<?php
/**
* Plugin Name: Affiliate Order Detail Notes
* Text Domain: affwp_od
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@alexstandiford
alexstandiford / Hash_Generator.php
Last active September 12, 2020 01:19
hash-generator
<?php
class Hash_Generator {
/**
* The generated hash.
*
* @var string
*/
private $hash = false;
@alexstandiford
alexstandiford / add-sales-revenue-to-affiliate-area.php
Last active March 9, 2024 05:36
Adds sales revenue to affiliate area.
<?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 10:21
WordPress Dark Mode CSS. Grabbed from the Dark Mode plugin in the WordPress repository.
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
}
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; })()
<?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 April 2, 2020 14:40
Create a custom Referral Type in AffiliateWP
<?php
add_action('affwp_referral_type_init',function( $registry ){
$registry->register_type( 'custom_type', array(
'label' => __( 'Custom Type', 'text-domain' ),
) );
}