Skip to content

Instantly share code, notes, and snippets.

@glueckpress
glueckpress / wp_rocket__wp_get_attachment_image__lazyload.php
Last active January 6, 2020 08:18
[WordPress][WP Rocket] [deprecated] Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
<?php
/**
* Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
*
* @link https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
* @link https://github.com/wp-media/wp-rocket/blob/v2.10.9/inc/front/lazyload.php#L24-L47
*
* @param int $attachment_id (Required) Image attachment ID.
* @param string|array $size (Optional) Image size. Accepts any
* valid image size, or an array of width
@peterdemartini
peterdemartini / command.sh
Last active March 6, 2025 07:29
Exclude node_modules in timemachine
find `pwd` -type d -maxdepth 3 -name 'node_modules' | xargs -n 1 tmutil addexclusion
@RadGH
RadGH / woocommerce-add-to-cart-url-with-redirect.php
Last active September 27, 2017 12:38
WooCommerce URL to add to cart and redirect to cart or checkout with quantity, limit, and option to remove other products.
<?php
/*
* Returns a URL that upon visiting, will add the product to the cart and do some other things as described below.
* $qty = How many items to add to the cart
* $limit = If true, it will prevent you from having more than $qty in your cart.
* $remove_others = If true, any other products will be removed from the cart.
* $redirect_to = If set to "cart" or "checkout", will redirect after adding the item. Does not work with a URL (to avoid XSS).
*
* @param $product_id
* @param int $qty
@itzikbenh
itzikbenh / home.php
Last active April 5, 2020 09:30
Very simple infinite scroll in WordPress.
//Just a random file for loading your posts to see that the infinite scroll works.
<?php get_header(); ?>
<div class="col-md-6 col-md-offset-3">
<div class="post-container">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="page-header post">
<h1><?php the_title(); ?></h1>
<p><?php the_excerpt(); ?></p>
</div>
@gschoppe
gschoppe / cat-like-custom-taxonomy.php
Created February 28, 2016 01:07
Use category (checkbox-based) interface with non-hierarchical custom taxonomies
<?php
// Event taxonomies
add_action( 'init', function() {
$labels = array(
'name' => _x( 'Terms', 'taxonomy general name' ),
'singular_name' => _x( 'Term', 'taxonomy singular name' ),
);
register_taxonomy( 'taxonomy_name', array( 'post' ), array(
'hierarchical' => false,
@alexdumont
alexdumont / gist:1df846047cfdead33b2b
Created October 16, 2015 08:14
URL and Javascript
window.location.host //www.test.com:8082
window.location.hostname // www.test.com
window.location.port // 8082
window.location.protocol // http
window.location.pathname // index.php
window.location.href // http://www.test.com:8082/index.php#tab2
window.location.hash // #tab2
window.location.search // ?foo=123
$(location).attr('host'); // www.test.com:8082
@vladimirlukyanov
vladimirlukyanov / dont_group_products_at_cart_woocommerce.php
Created September 16, 2015 20:25
Don't group products at cart – Woocommerce
<?php
add_filter('woocommerce_add_cart_item_data', 'namespace_force_individual_cart_items', 10, 2);
function namespace_force_individual_cart_items($cart_item_data, $product_id) {
$unique_cart_item_key = md5(microtime() . rand());
$cart_item_data['unique_key'] = $unique_cart_item_key;
return $cart_item_data;
}
@mikejolley
mikejolley / ipn-test.php
Last active September 5, 2024 01:54
Quick snippet/plugin/dropin to test IPN support
<?php
/**
* Plugin Name: PayPal Sandbox IPN Tester
* Description: Pings the IPN endpoint to see if your server can connect. Just head to <a href="/?ipn-test=1">yoursite.com/?ipn-test=1</a> whilst logged in as admin.
* Version: 1.0.0
* Author: WooThemes
* Requires at least: 4.1
* Tested up to: 4.3
*/
if ( ! defined( 'ABSPATH' ) ) {
@manospsyx
manospsyx / woocommerce-composites-hide-cart-order-components.php
Last active November 22, 2021 04:45
Use this snippet to hide Components in the cart, checkout, order and e-mail templates
<?php
/**
* Plugin Name: WooCommerce Composite Products - Hide Components in all Templates
* Plugin URI: https://woocommerce.com/products/composite-products/
* Description: Use this snippet to hide Components in the cart, checkout, order and e-mail templates.
* Version: 1.0
* Author: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
@chriscct7
chriscct7 / gist:d7d077afb01011b1839d
Last active January 24, 2024 04:20
Plugins that need to be updated to be ready for the move to PHP 5 constructors

Important Notice for WordPress Plugins Using PHP 4 Style Constructors

The ability to use PHP 4 style constructors is getting removed from PHP. Without an update, many plugins will eventually no longer work (this is PHP breaking this backwards compatibility, not WordPress)

One of the more common uses of the PHP 4 style constructor (as opposed to PHP 5 style __construct() ) are plugins with widgets calling WP_Widget::WP_Widget() and/or parent::WP_Widget() and/or {object}->WP_Widget()

Note: Starting in WordPress 4.3, regardless of the PHP version in use on a server, WordPress will throw a deprecated notice when one of the PHP 4 style constructors is called specifically for widgets.

Basically instead of doing these: