Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View barryhughes's full-sized avatar
🇨🇦

Barry Hughes barryhughes

🇨🇦
  • Automattic
  • Vancouver Island, Canada
View GitHub Profile
<?php
/**
* Facilitates dictating a separate (IP-address protected) Google Maps
* API key for server-side geocoding requests.
*/
class Server_Side_Google_Maps_Key {
/**
* @var string
*/
private $key = '';
@barryhughes
barryhughes / fetch-csv-file.php
Created January 12, 2020 22:04
Load a CSV file and transform to an array. Simple helper for quick and dirty scripting.
<?
/**
* Given a path to a valid CSV file, returns an array containing the data
* (an array of arrays, with outer arrays representing the rows and inner
* arrays representing the columns).
*
* @param string $path_to_csv
*
* @return array
*/
<?php
namespace WooCommerce_Helpers {
/**
* Looks for an existing WooCommerce attribute with the same label, or else
* creates a new attribute using the provided information.
*
* If a new attribute is successfully created, or an existing attribute is
* matched, the attribute object will be returned. Otherwise, bool false is
* returned.
*
@barryhughes
barryhughes / php-streams.http-basic-auth.php
Last active December 31, 2019 15:25
HTTP authentication with file_get_contents() | PHP
<?php
/**
* Make an HTTP request with basic authentication, using 'pure PHP'.
*
* @see https://www.php.net/manual/en/wrappers.http.php
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
*/
$username = 'http_username';
$password = 'http_password';
@barryhughes
barryhughes / password-reset-link-generator.wp-cli.php
Last active December 20, 2019 16:30
Handy dandy WordPress password reset link generator (command line). Useful when we want to create a URL to share with a customer because they are for whatever reason having difficulties using the regular password reset facilities.
@barryhughes
barryhughes / custom-event-category-templates.php
Created October 25, 2018 19:58
An example of using a different theme template for different event categories.
<?php
/**
* Use custom templates for event views when specific categories
* have been requested.
*/
class Event_Category_Templates {
/**
* This will be true if an event view has been requested.
*
* @var bool
@barryhughes
barryhughes / bbpress-topic-ordering.php
Last active November 23, 2019 10:58
bbPress 2.6.x: don't allow "bumped" topics to surface to the top.
<?php
/**
* Order bbPress topic archives by post date (date created), not by last activity.
*
* This can be added either within a standalone plugin or to a theme's functions.php
* file.
*
* @param array $args
*
* @return array
location / {
- rewrite ^ /index.php$request_uri;
+ rewrite ^ /index.php;
}
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
+ try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPTFILENAME $document_root$fastcgi_script_name;
@barryhughes
barryhughes / users-by-total-subscriptions.sql
Created September 18, 2019 01:01
Build a list of user IDs, ordered by the number of known (WooCommerce) subscriptions each user is associated with.
SELECT meta_value AS user_id,
COUNT(*) AS subscription_count
FROM wp_posts
JOIN wp_postmeta ON ID = post_id
WHERE post_type = 'shop_subscription'
AND meta_key = '_customer_user'
GROUP BY meta_value
ORDER BY subscription_count DESC
<?php
/**
* Hide 'expired' events from the /all/ recurring events view.
*
* This snippet is best added to a custom (mu-)plugin, for instance:
*
* wp-content/mu-plugins/ecp-customizations.php
*
* It is only intended as a temporary shim until a future version
* of The Events Calendar or Events Calendar PRO resolves things;