Skip to content

Instantly share code, notes, and snippets.

@Robdel12
Robdel12 / how-to-run.md
Last active April 5, 2019 17:08
A small example of Percy & puppeteer

The quickest test suite to setup

Once you fill in the URLs you want to snapshot, you can run the visual tests by:

  • Setting your PERCY_TOKEN to a project in https://percy.io
  • Running npm run percy (or yarn percy)
  • ??
  • Get other work done (profit)!

That's about it :p

@FellowshipAgency
FellowshipAgency / disable-css-grid.scss
Created September 6, 2018 11:21
Easily disable CSS Grid
// To easily view how a site looks when CSS Grid is not available, use this in the SASS file.
// First you need this variable:
$cssgrid: "(grid-template-rows:initial)";
// Then you can uncomment the below to re-declare the variable and so disable the @supports for every browser:
// $cssgrid: "(display:no-css-grid-support)";
// Wrap every usage of CSS Grid in this:
@supports(#{$cssgrid}) {
@pento
pento / php-block.js
Last active February 29, 2024 01:31
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@cmunns
cmunns / woo_bronto_json.php
Created January 26, 2018 17:31
WooCommerce Bronto Script
add_action('wp_footer', 'add_bronto_json');
function add_bronto_json() {
$brontoItems = [];
if( is_wc_endpoint_url( 'order-received' ) ):
if(isset($_GET['view-order'])) {
$order_id = $_GET['view-order'];
@bjornjohansen
bjornjohansen / maintenance.php
Created August 31, 2017 11:57
Custom WordPress maintenance mode page
<?php
wp_load_translations_early();
$protocol = wp_get_server_protocol();
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 30' );
?>
<!DOCTYPE html>
<html>
@ollietreend
ollietreend / acf-php-to-json.php
Last active April 22, 2024 11:12
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@bjornjohansen
bjornjohansen / test-password-permutations.php
Last active February 2, 2017 11:09
Test a bunch of permutations of the password when logging into WordPress.
<?php
/**
* Test a bunch of permutations of the password when logging into WordPress.
*
* Drop this file in your mu-plugins directory.
* Inspired by Facebook: https://twitter.com/gcpascutto/status/821755332984717314/photo/1
* Works with any properly coded hashing pluggables, like Roots’ WP Password bcrypt.
*
* @author bjornjohansen
* @version 0.1.4
@richardW8k
richardW8k / rw-gf-total-field-logic.php
Last active November 10, 2017 03:18
Enables use of the total field with conditional logic. [hide] this field if [total][less than][0.1] or [show] this field if [total][greater than][0]. Because the total field is always the last field to be saved you can't use it when configuring conditional logic on other fields. Displaying other fields based on the total would prevent those fiel…
<?php
class RW_GF_Total_Field_Logic {
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
function init() {
if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) {
return;
@DanBeckett
DanBeckett / gforms_address_uk_postcode_validation
Last active March 29, 2018 13:15
Validate Gravity Forms standard multi-part Address field to check for a UK Valid Postcode
add_filter("gform_field_validation_[FORM_ID]_[FIELD_ID]", "uk_postcode_validation", 10, 4);
function uk_postcode_validation($result, $value, $form, $field){
//address field will pass $value as an array with each of the elements as an item within the array, the key is the field id
$postcode = $value["[FIELD_ID].5"];
//the default regex is valid both with and without the space in the middle.
//to force the space, replace with the following:
//'#^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) [0-9][ABD-HJLNP-UW-Z]{2})$#'
@corsonr
corsonr / gist:9152652
Last active January 19, 2023 22:41
WooCommerce : add custom fields to product variations
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_process_product_meta_variable', 'save_variable_fields', 10, 1 );
/**