Skip to content

Instantly share code, notes, and snippets.

@simongcc
simongcc / add_custom_column_to_edit_tag.php
Last active Mar 30, 2021
Adding custom column displaying in Wordpress Manage Category/Custom Taxonomy editing page
View add_custom_column_to_edit_tag.php
/*
Purpose: add custom column header and custom column content to respective custom header in Manage Category Editing Page
Version Tested: 3.8
Story:
Because I found no explanation nor documents in Wordpress.org, I tried to trace the code in wp-admin folder
after understanding the operation of apply_filter(), add_action() and add_filter()
Logic:
The table list in edit_tag.php is based on
@simongcc
simongcc / date-validation.js
Created Dec 19, 2020
regular expression to test date format 'dd-mm-yyyy'
View date-validation.js
Examples
let date = '31-12-2004'
date_regex = /^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{4}$/;
date_regex.test( date )
let date = 31
let date_regex = /^(0[1-9]|[1-2][0-9]|3[0-1])$/;
date_regex.test( date )
let date = 12
@simongcc
simongcc / read-csv.sh
Created Dec 16, 2020
Bash Reading CSV
View read-csv.sh
#!/bin/bash
# Purpose: Read Comma Separated CSV File
# Author: Vivek Gite under GPL v2.0+
# Site: https://www.cyberciti.biz/faq/unix-linux-bash-read-comma-separated-cvsfile/
# ------------------------------------------
INPUT=bridge-category.csv
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read cat_en cat_zht
@simongcc
simongcc / css-table.scss
Created Sep 19, 2020
CSS Table example
View css-table.scss
.table {
// display: table;
width: 100%;
background: red;
.tbl-col-group {
display: table-column-group;
.tbl-col {
display: table-column;
@simongcc
simongcc / delete-all-woocommerce-products.php
Last active Sep 7, 2020 — forked from mikaelz/delete-all-woocommerce-products.php
Remove all WooCommerce products from database via SQL
View delete-all-woocommerce-products.php
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");
@simongcc
simongcc / batch.sh
Last active Aug 18, 2020
Bash batch file notes
View batch.sh
for file in *.po; do
po-to-xls ${file%.*}.po -o ${file%.*}.xlsx
done
# https://stackoverflow.com/questions/2664740/extract-file-basename-without-path-and-extension-in-bash
# $file is the file original name
# no extension: ${file%.*}.po
# s=/the/path/foo.txt
# echo "${s##*/}"
# foo.txt
View functions.md

=INDEX('[Healh-Factor-product list_Health-lookup.xlsx]Sheet1'!$A:$A,MATCH(""&TRIM(E313)&"",'[Healh-Factor-product list_Health-lookup.xlsx]Sheet1'!$D:$D,),0)

@simongcc
simongcc / ExportAllCSVinOneSpreadsheet.gs
Created Apr 16, 2017
Google script to export all csv in one spreadsheet
View ExportAllCSVinOneSpreadsheet.gs
/*
* script to export data in all sheets in the current spreadsheet as individual csv files
* files will be named according to the name of the sheet
* Note: This script uses the DocsList.createFile() method, which is only available for Google Apps accounts.
* author: Michael Derazon
*/
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var csvMenuEntries = [{name: "export as csv files", functionName: "saveAsCSV"}];
View mysql-notes.md
View WP-Trace-Intercept-codes.php
<?php
var_dump($this->request);
if( strpos( $this->request, 'SQL_CALC_FOUND_ROWS' ) > 0 ) {
file_put_contents('/volumes/ram/test_'. time() .'.txt', $this->request);
}