Skip to content

Instantly share code, notes, and snippets.

@skydriver
skydriver / first-title-letter-query.php
Created April 18, 2014 12:13
WordPress List Posts by First Title Letter
<?php
global $wpdb;
$first_char = esc_attr($_GET[$search_key]);
$postids = $wpdb->get_col($wpdb->prepare("
SELECT ID
FROM $wpdb->posts
WHERE SUBSTR($wpdb->posts.post_title,1,1) = %s
AND $wpdb->posts.post_type = 'product'
@qutek
qutek / woocommerce-ajax.php
Last active November 23, 2025 20:16
[Wordpress] [Woocommerce] WooCommerce Ajax Handlers
<?php
/**
* WooCommerce Ajax Handlers
*
* Handles AJAX requests via wp_ajax hook (both admin and front-end events)
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/** Frontend AJAX events **************************************************/
@umidjons
umidjons / jquery-paste-drop-events.md
Created August 22, 2014 04:03
Handle paste and drop events on jQuery

Handle paste and drop events on jQuery

Imagine we have .myinput input field, that we should process its value after text pasted into it. We can't access value in paste directly, so we should wait some time. For that purpose one can use setTimeout function. Here is example how to correctly handle paste event.

jQuery(document).ready(function($){
@m1r0
m1r0 / wp_insert_attachment_from_url.php
Last active October 17, 2025 00:50
WP: Insert attachment from URL
<?php
/**
* Insert an attachment from a URL address.
*
* @param string $url The URL address.
* @param int|null $parent_post_id The parent post ID (Optional).
* @return int|false The attachment ID on success. False on failure.
*/
function wp_insert_attachment_from_url( $url, $parent_post_id = null ) {
@ccurtin
ccurtin / :WORDPRESS: using-PHP-variables-in-JS.md
Last active December 3, 2022 07:28
:WORDPRESS: using-PHP-variables-in-JS (wp localize script)
@taufik-nurrohman
taufik-nurrohman / php-html-css-js-minifier.php
Last active March 20, 2025 17:17
PHP Function to Minify HTML, CSS and JavaScript
<?php
// Based on <https://github.com/mecha-cms/x.minify>
namespace x\minify\_ { // start namespace
$n = __NAMESPACE__;
\define($n . "\\token_boolean", '\b(?:true|false)\b');
\define($n . "\\token_number", '-?(?:(?:\d+)?\.)?\d+');
@fdaciuk
fdaciuk / functions.php
Last active April 12, 2016 20:30
Adicionar mais campos no perfil de usuário do WordPress
<?php
add_filter( 'user_contactmethods', 'add_new_user_fields' );
function add_new_user_fields( $user_contact ) {
$user_contact[ 'billing_cel_phone' ] = 'Celular';
return $user_contact;
}
@DevinWalker
DevinWalker / cmb2-address.php
Created July 29, 2015 22:15
Plugin demonstrating CMB2 address field as repeatable
<?php
/*
* Plugin Name: CMB2 Custom Field Type - Address
* Description: Makes available an 'address' CMB2 Custom Field Type. Based on https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types#example-4-multiple-inputs-one-field-lets-create-an-address-field
* Author: jtsternberg
* Author URI: http://dsgnwrks.pro
* Version: 0.1.0
*/
/**
@ovizii
ovizii / functions.php
Last active July 13, 2020 18:17
Remote site snapshot using Wordpress API shortcode
function wpr_snap($atts, $content = null) {
extract(shortcode_atts(array(
"snap" => 'http://s.wordpress.com/mshots/v1/',
"url" => 'http://www.sagive.co.il',
"alt" => 'My image',
"w" => '400', // width
"h" => '300' // height
), $atts));
$img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>';
@neilgee
neilgee / less-fields-virtual.php
Last active March 10, 2022 00:36
WooCommerce Remove Address Fields from checkout based on presence of virtual products in cart
<?php
add_filter( 'woocommerce_checkout_fields' , 'virtual_products_less_fields' );
/**
* WooCommerce Remove Address Fields from checkout based on presence of virtual products in cart
* @link https://www.skyverge.com/blog/checking-woocommerce-cart-contains-product-category/
* @link https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
* @link https://businessbloomer.com/woocommerce-hide-checkout-billing-fields-if-virtual-product-cart/
*/