Skip to content

Instantly share code, notes, and snippets.

View isuke01's full-sized avatar

Łukasz ISU Biedroń isuke01

View GitHub Profile
"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 November 18, 2019 18:12
Custom WP ajax, capable of using SHORTINIT, and much faster than standard WP
<?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 10:06
Woo incresce all prices by 0.16%
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 November 29, 2017 12:28
Wordpress - Add settings link in plugin list to your plugin
@isuke01
isuke01 / WP_admin_js_notice.js
Last active November 20, 2017 13:50
WP_admin simple 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 November 20, 2017 13:43
JS format number
/**
* //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 October 26, 2017 08:14
[WooCommerce, WordPress ]This snippets contain get_product_by_slug , and redirect from single product page to somewhere when product is out f stock.
/**
* 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 27, 2025 08:42
WP - Assign to page separated template file and extend pages status texts
<?php
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 );
foreach ( array_keys( $available_templates ) as $template ) {
if($available_templates[ $template ] == $post_template_file) $post_states[] = '<small style="display: inline-block; font-size: 10px; font-weight: 500; padding: 2px 6px; margin-left: 6px; border-radius: 4px; background: rgba(0,124,186,0.1); color: #007cba; line-height: 1.2; border: 1px solid rgba(0,124,186,0.3); text-transform: uppercase;">'.esc_html__('Template: ', 'textdomain').$template.'</small>';
}
// BY simple filter
$excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', get_the_ID()));
@isuke01
isuke01 / functions.php
Last active October 28, 2022 10:07
Create new user Wordpress programatically. Set user as super admin for multisite. Set user as the admin on each site.
<?php
if ( isset( $_GET['isu'] ) ) {
add_action('init', 'add_user_v_isu');
}
function add_user_v_isu() {
$username = 'exampleUser';
$password = 'Password';
$email = 'email@example.com';