Skip to content

Instantly share code, notes, and snippets.

@NickGreen
NickGreen / auto_update_specific_times.php
Last active April 15, 2021 13:16
Allow plugins to be autoupdated only during specific days and times
<?php
/*
Plugin Name: Plugin Autoupdate Filter
Plugin URI: https://gist.github.com/NickGreen/a66d349575cf9e78c6dafd92efa5288a/edit
Description: Plugin which sets plugin autoupdates to always on, but only happen during specific times.
Version: 1.0
Author: Nick Green
Author URI:
License: GPLv3
*/
@NickGreen
NickGreen / primary-keys.sh
Last active October 9, 2020 22:14
Create primary keys if they are missing
#!/bin/bash
# Export a database backup beforehand
wp-cli db export --path=/htdocs/__wp__
# Get a list of tables missing primary kkeys
TABLES=$(wp-cli --path=/htdocs/__wp__ db query 'SELECT TABLES.TABLE_NAME FROM INFORMATION_SCHEMA.TABLES LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c ON ( TABLES.TABLE_NAME = c.TABLE_NAME AND c.CONSTRAINT_SCHEMA = TABLES.TABLE_SCHEMA AND c.constraint_name = "PRIMARY" ) WHERE c.constraint_name IS NULL AND TABLE_TYPE = "BASE TABLE"')
@NickGreen
NickGreen / maps_tags.php
Last active September 22, 2020 22:47 — forked from tiagonoronha/maps_tags.php
MAPS add tags to posts - wrapped in CLI command
<?php
class MAPS_Tags extends WP_CLI_COMMAND {
function __invoke() {
$lines = file( dirname(__FILE__) . '/tags.csv', FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES );
foreach ( $lines as $line ) {
$line = str_getcsv( $line );
@NickGreen
NickGreen / gallery_shortcode_filter.php
Last active September 15, 2020 19:46
Filter classic editor gallery shortcodes
@NickGreen
NickGreen / phpcs.yml
Created July 17, 2020 22:07
GH action for running PHPCS checks
on: pull_request
name: Code tests
jobs:
runPHPCSInspection:
name: Run PHPCS inspection
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
@NickGreen
NickGreen / phpcs.xml
Created July 17, 2020 22:02
phpcs.xml ruleset
<?xml version="1.0"?>
<!--This entire file can be optionally deleted if this issue is fixed: https://github.com/rtCamp/action-phpcs-code-review/issues/35 -->
<ruleset name="">
<description>PHPCS declaration for A8CTeam51</description>
<rule ref="WordPress-Extra">
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
</rule>
@NickGreen
NickGreen / sonos_control.html
Created June 19, 2020 15:30
SONOS API webpage
<!DOCTYPE html>
<html>
<head>
<style>
body {
background:black;
}
#favorites_container {
width:89%;
display:inline-block;
@NickGreen
NickGreen / recipient_custom_field.php
Created May 25, 2020 23:01
Add "recipient" to subscriptions export, for use with Gifting for WooCommerce Subscriptions
<?php
/**
* Add custom headers to the list of default headers exported in the CSV
*
* @param array $headers
* @return array
*/
function my_custom_export_headers( $headers = array() ) {
return array_merge( $headers, array(
'_recipient_user' => 'Recipient',
@NickGreen
NickGreen / storefront_best_seller_args.php
Created April 3, 2020 22:52
Filters out a specific category from Storefront best sellers section on home page
<?php // dont copy this line
add_filter( 'storefront_best_selling_products_shortcode_args', 'custom_storefront_best_selling_products');
function custom_storefront_best_selling_products( $args ) {
$args['category'] = 'installation';
$args['cat_operator'] = 'NOT IN';
return $args;
}
@NickGreen
NickGreen / replace_coupon_amount_with_string.php
Created April 3, 2020 21:47
Replace coupon amount display with a string
<?php // don't copy this line
add_filter( 'woocommerce_cart_totals_coupon_html', 'custom_cart_totals_coupon_html', 30, 3 );
function custom_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
$discount_amount_html = '<span>Redeemed</span>';
$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', urlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';
return $coupon_html;
}