Skip to content

Instantly share code, notes, and snippets.

View geoffguillain's full-sized avatar

Geoff geoffguillain

  • Automattic
  • French Polynesia
View GitHub Profile
@geoffguillain
geoffguillain / seinsei_redirect_first_course.php
Created May 17, 2022 04:50
Add redirect to course after woo checkout
/*
* Team 51 - Add redirect to course after checkout
**/
add_action('woocommerce_thankyou', 'ona_add_redirect_after_checkout');
function ona_add_redirect_after_checkout( $order_id ) {
$order = new WC_Order( $order_id );
// exit early if not wc-completed or wc-processing
if( 'wc-completed' != $order->post_status

The inefficient theme

get-last-image.php

get_children() is not cached on the VIP GO Platform but also performs a no-LIMIT query by default. Any no-LIMIT query will have scaling issue as the database increase.

How to solve this issue:

Setting posts_per_page to 1 is already a good start as it will take care of the no-LIMIT issue Going further using a WP_Query like the one below to fetch the last image attached could be more optimised.

@geoffguillain
geoffguillain / class-remove-empty-level-wpcli.php
Last active May 7, 2019 21:35
Remove empty wp_user_level entries in the wp_usermeta table
if ( defined( 'WP_CLI' ) && WP_CLI ) {
/**
* Remove empty wp_user_level entries in the wp_usermeta table
*/
class RemoveEmptyLevelWPCLI {
public function __invoke( $args, $assoc_args ) {
// If --dry-run is not set, then it will default to true.
// Must set --dry-run explicitly to false to run this command.
@geoffguillain
geoffguillain / managecapbyrole.php
Created March 11, 2019 19:05
WP CLI script managecapbyrole - Add or remove a capacity to all users with a specific role
<?php
if ( defined( 'WP_CLI' ) && WP_CLI ) {
/**
* Add or remove a capacity to all users with a specific role
*/
class ManageCapByRoleWPCLI {
/**