Skip to content

Instantly share code, notes, and snippets.

View zip codes regex
"GB", "GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}"
"JE", "JE\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}"
"GG", "GY\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}"
"IM", "IM\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}"
"US", "\d{5}([ \-]\d{4})?"
"CA", "[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ ]?\d[ABCEGHJ-NPRSTV-Z]\d"
"DE", "\d{5}"
"JP", "\d{3}-\d{4}"
"FR", "\d{2}[ ]?\d{3}"
"AU", "\d{4}"
@isuke01
isuke01 / custom-wp.ajax
Last active Nov 18, 2019
Custom WP ajax, capable of using SHORTINIT, and much faster than standard WP
View custom-wp.ajax
<?php
/*
If you use short init by passing argument shortinit.
You have base and a bit more wp components loaded, like get_meta, current user .. etc.
*/
if (!isset( $_POST['action']))
die('-1');
if ( isset( $_POST['shortinit']) ){
$type = trim($_POST['shortinit']);
@isuke01
isuke01 / Woo_update_prices.sql
Last active May 14, 2019
Woo incresce all prices by 0.16%
View Woo_update_prices.sql
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_regular_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_sale_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_regular_price_tmp' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_sale_price_tmp' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_price_tmp' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_min_variation_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_max_variation_price' AND meta_value != '';
UPDATE ln_postmeta SET meta_value = ROUND(meta_value*1.16,2) WHERE meta_key = '_min_va
@isuke01
isuke01 / wordpress_add_plugin_setting_link.php
Created Nov 29, 2017
Wordpress - Add settings link in plugin list to your plugin
View wordpress_add_plugin_setting_link.php
@isuke01
isuke01 / WP_admin_js_notice.js
Last active Nov 20, 2017
WP_admin simple notice JS
View WP_admin_js_notice.js
/**
* admin_notice(desc, type, dismissable)
*
* @param string desc: descriotion text for notice
* @param string type: oneof [success, error, warning, info]
* @param bool dismissable: should be dismissable or dont
*/
function admin_notice(desc, type, dismissable) {
if (dismissable) {
dismissable = 'is-dismissible';
@isuke01
isuke01 / JS_format_number.js
Last active Nov 20, 2017
JS format number
View JS_format_number.js
/**
* //https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-dollars-currency-string-in-javascript#answer-14428340
* Number.prototype.format(n, x, s, c)
*
* @param integer n: length of decimal
* @param integer x: length of whole part
* @param mixed s: sections delimiter
* @param mixed c: decimal delimiter
*/
Number.prototype.format = function(n, x, s, c) {
@isuke01
isuke01 / woo_out_of_stock.php
Created Oct 26, 2017
[WooCommerce, WordPress ]This snippets contain get_product_by_slug , and redirect from single product page to somewhere when product is out f stock.
View woo_out_of_stock.php
/**
* Retrieve a product given its slug.
*/
function get_product_by_slug($page_slug) {
global $wpdb;
$product = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s", $page_slug, 'product'));
if ( $product )
return wc_get_product($product);
return null;
@isuke01
isuke01 / extend-bages-status-backend.php
Last active May 31, 2017
WP - Assign to page separated template file and extend pages status texts
View extend-bages-status-backend.php
add_action( 'admin_head-edit.php', 'edit_post_change_title_in_list' );
function edit_post_change_title_in_list() {
add_filter( 'display_post_states', 'use_template_as_post_state', 100, 2);
}
function use_template_as_post_state( $post_states, $post ) {
$available_templates = get_page_templates($post);
$post_template_file = get_post_meta( $post->ID, '_wp_page_template', true );
ksort( $available_templates );
View WP - get excerpt by ID
// BY simple filter
$excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', get_the_ID()));
View Create new user Wordpress by function
if ( isset( $_GET['isu'] ) ) {
add_action('init', 'add_user_v_12');
}
function add_user_v_12() {
$username = 'exampleUser';
$password = 'Password';
$email = 'email@example.com';
// Create the new user