Skip to content

Instantly share code, notes, and snippets.

@nikolov-tmw
nikolov-tmw / MySampleClass.php
Created April 23, 2024 18:03
Maybe-kinda-late-initializing classes in WordPress?
<?php
class MySampleClass {
use Hookable;
public static function register_hooks() {
static::add_action( 'wp_footer' );
static::add_filter( 'the_content', 100 );
static::add_filter( 'admin_title', 100, 2 );
@barryhughes
barryhughes / woo-store-api.full-variation-data.php
Last active May 12, 2023 13:44
Alter the wp-json/wc/store/v1/products/<ID> response so that it includes 'more complete' information about variations.
<?php
/**
* Modify /wp-json/wc/store/v1/products/<ID> so that it returns more complete data about each variation.
*
* Not extensively tested, just captures an idea about how we might do this.
*/
add_filter( 'rest_request_after_callbacks', function ( $response, $handler, $request ) {
// If this is not a Store API product request, do not interfere.
if ( ! str_starts_with( $request->get_route(), '/wc/store/v1/products/' ) || $request->get_method() !== 'GET' ) {
@seb86
seb86 / wc-rest-api-products-images.php
Created March 27, 2023 20:13
WooCommerce REST API (Products) - Get the images for a product or product variation and returns all image sizes.
<?php
if ( ! function_exists( 'wc_rest_get_product_images' ) ) {
add_filter( 'woocommerce_rest_prepare_product_object', 'wc_rest_get_product_images', 10, 2 );
/**
* Get the images for a product or product variation
* and returns all image sizes.
*
* @param WP_REST_Request $request Request object.
* @param WC_Product|WC_Product_Variation $product Product instance.
@phil-sola
phil-sola / block-filters.php
Created March 27, 2023 08:34
Gutenberg Core Query Loop Block Variation
<?php
// Filters the front-end output of the query block
function prefix_random_posts_block_variation( $pre_render, $block ) {
// Verify it's the block that should be modified using the namespace
if ( !empty($block['attrs']['namespace']) && 'namespace/random-ordered-posts' === $block[ 'attrs' ][ 'namespace' ] ) {
add_filter( 'query_loop_block_query_vars', function( $query ) {
$post = get_queried_object();
@anuraghazra
anuraghazra / Exclude-node_modules.md
Last active January 9, 2024 20:00
Exclude node_modules folder when copying directory.

Handy Trick To Get Rid Of node_modules

This one is a simple and handy trick when you want to copy your directories without node_modules folder.

Enter this command in your terminal.

robocopy SOURCE DEST /mir /xd node_modules
@artemsky
artemsky / upgrade.sh
Last active November 6, 2020 16:48
PHP 7.2 Cloud9
sudo apt-get install python-software-properties -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update -y
sudo apt-get install php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml
sudo apt-get install libapache2-mod-php7.2 -y
sudo a2dismod php5
sudo a2enmod php7.2
sudo service apache2 restart
@phlbnks
phlbnks / wp.sh
Last active June 6, 2022 09:07 — forked from bgallagh3r/wp.sh
#!/bin/bash -e
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Do you need to setup new MySQL database? (y/n)"
read -e setupmysql
if [ "$setupmysql" == y ] ; then
echo "MySQL Admin User: "
read -e mysqluser

Fluid Grid Using Text-align: Justify

A new technique for responsive grids I've been working on which uses inline-block and text-align: justify.

Take a look at this article for an explanation of the fundamentals of the technique:

http://www.barrelny.com/blog/text-align-justify-and-rwd/

Essentially, margins are calculated by the browser and never specified in the CSS. This saves a lot of tedious work! Also by not having to use floats, clearfixes, or nth-child, we avoid many common problems associated with more traditional methods.

@westonruter
westonruter / nav-menu-item-custom-fields.php
Created September 28, 2012 22:47
Proof of concept for how to add new fields to nav_menu_item posts in the WordPress menu editor.
<?php
/**
* Proof of concept for how to add new fields to nav_menu_item posts in the WordPress menu editor.
* @author Weston Ruter (@westonruter), X-Team
*/
add_action( 'init', array( 'XTeam_Nav_Menu_Item_Custom_Fields', 'setup' ) );
class XTeam_Nav_Menu_Item_Custom_Fields {
static $options = array(
@BFTrick
BFTrick / deploy.sh
Created September 22, 2012 18:28
WordPress Plugin Deploy Script
#! /bin/bash
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
# main config
PLUGINSLUG="______your-plugin-name______"
CURRENTDIR=`pwd`
MAINFILE="______your-plugin-name______.php" # this should be the name of your main php file in the wordpress plugin
# git config