Skip to content

Instantly share code, notes, and snippets.

View rmorse's full-sized avatar

Ross Morsali rmorse

View GitHub Profile
INITIALISATION
==============
load wp-config.php
set up default constants
load wp-content/advanced-cache.php if it exists
load wp-content/db.php if it exists
connect to mysql, select db
load object cache (object-cache.php if it exists, or wp-include/cache.php if not)
load wp-content/sunrise.php if it exists (multisite only)
@caseywatts
caseywatts / bookmarkleting.md
Last active May 2, 2024 03:04
Making Bookmarklets

This is one chapter of my "Chrome Extension Workshops" tutorial, see the rest here: https://gist.github.com/caseywatts/8eec8ff974dee9f3b247

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

Making Bookmarklets

I'm feeling very clever. I've got this sweet line of javascript that replaces "cloud" with "butt". My mom would LOVE this, but she doesn't computer very well. I'm afraid to show her the Developer Console and have her type/paste this in. But she IS pretty good at bookmarks, she knows just how to click those!

A bookmark normally takes you to a new web page. A bookmarklet is a bookmark that runs javascript on the current page instead of taking you to a new page. To declare that it is a bookmarklet, the "location" it points to starts with javascript:.

@youknowriad
youknowriad / log.js
Created April 24, 2024 22:47
Gutenberg Log Deprecations
const { createElement: el, useState, useEffect } = React;
const PanelBody = wp.components.PanelBody;
const PluginSidebar = wp.editor.PluginSidebar;
const addAction = wp.hooks.addAction;
const registerPlugin = wp.plugins.registerPlugin;
function MyPluginSidebar() {
const [ deprecations, setDeprecations ] = useState( [] );
useEffect( () => {
addAction(
@britweb-tim
britweb-tim / wp-cli-wc-import-csv.php
Last active April 4, 2024 16:58
Add a WP CLI Command for importing woocommerce products from csv
<?php
// Add a WP CLI Command which allows import of CSV files from the command line.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once WP_PLUGIN_DIR . '/woocommerce/includes/import/class-wc-product-csv-importer.php';
// Maybe require and invoke any other filters you need here as theme/plugins may not be loaded at this point.
class WP_CLI_WC_Import_CSV {
@Restuta
Restuta / framework-sizes.md
Last active March 7, 2024 00:01
Sizes of JS frameworks, just minified + minified and gzipped, (React, Angular 2, Vue, Ember)

Below is the list of modern JS frameworks and almost frameworks – React, Vue, Angular, Ember and others.

All files were downloaded from https://cdnjs.com and named accordingly. Output from ls command is stripped out (irrelevant stuff)

As-is (minified)

$ ls -lhS
566K Jan 4 22:03 angular2.min.js
@aurooba
aurooba / wp_inline_svg.php
Last active February 17, 2024 23:33
Helper function to inline your SVG files in a WordPress theme or plugin and optionally also update the attributes. Only works with WordPress 6.2 and onwards. Blog post with explanation and usage instructions: https://aurooba.com/inline-svgs-in-your-wordpress-code-with-this-helper-function/
<?php
/**
* Get an SVG file from the imgs/ folder in the theme, update its attributes if necessary and return it as a string.
*
* @author Aurooba Ahmed
* @see https://aurooba.com/inline-svgs-in-your-wordpress-code-with-this-helper-function/
*
* @param string $filename The name of the SVG file to get.
* @param array $attributes (optional) An array of attributes to add/modify to the SVG file.
@wesbos
wesbos / is_blog.php
Created September 2, 2011 19:32
WordPress is_blog()
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
public function is_cache_plugin_installed() {
return
function_exists( 'w3tc_flush_post' ) ||
function_exists( 'wp_cache_post_change' ) ||
function_exists( 'rocket_clean_post' ) ||
has_action( 'cachify_remove_post_cache' ) ||
has_action( 'litespeed_purge_post' ) ||
function_exists( 'wpfc_clear_post_cache_by_id' ) ||
class_exists( 'WPO_Page_Cache' ) ||
has_action( 'cache_enabler_clear_page_cache_by_post' ) ||
@mikejolley
mikejolley / functions.php
Last active June 19, 2023 03:10
WooCommerce - Show quantity inputs for simple products within loops.
<?php
/**
* Code should be placed in your theme functions.php file.
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
@kasparsd
kasparsd / custom-post-taxonomy-permalinks.php
Created June 13, 2012 15:47
Create permalink structure URLs for custom post types that include all parent terms from a custom taxonomy
<?php
/*
Term Archive Pages:
- http://example.com/recipes/dinner/
- http://example.com/recipes/breakfast,brunch/
Single Recipe Pages:
- http://example.com/recipes/dinner/soup-title/