Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Hardworking anytime 👍

Tomáš Kavalek tomaskavalek

:octocat:
Hardworking anytime 👍
View GitHub Profile
@tomaskavalek
tomaskavalek / plural.js
Created May 6, 2021
JavaScript Plurals
View plural.js
// CZ
function plural(n)
{
return arguments[(n === 1) ? 1 : ((n >= 2 && n <= 4) ? 2 : 3)];
}
// Examples
plural(1, 'uživatel', 'uživatelé', 'uživatelů')
"uživatel"
@tomaskavalek
tomaskavalek / cf7-recaptcha.js
Created Jan 4, 2021
WordPress Contact Form 7 + Invisible reCAPTCHA – Removing duplicate ajax-loader
View cf7-recaptcha.js
(function ($) {
'use strict';
// CF7 + reCAPTCHA
if($('.ajax-loader').length > 1) {
if($('input[type=submit].wpcf7-form-control.wpcf7-submit').is(":hidden")) {
if ($('input[type=submit].wpcf7-form-control.wpcf7-submit + span.ajax-loader').length) {
$('input[type=submit].wpcf7-form-control.wpcf7-submit + span.ajax-loader').remove();
}
}
@tomaskavalek
tomaskavalek / wp-admin-menu-debug.php
Created Nov 16, 2020
Debug WordPress admin menu – on dashboard only
View wp-admin-menu-debug.php
<?php
if ( ! function_exists('debug_admin_menus')) {
function debug_admin_menus()
{
global $submenu, $menu, $pagenow;
if (current_user_can('manage_options')) {
if ($pagenow === 'index.php') {
echo '<pre>';
print_r($menu);
echo '</pre>';
@tomaskavalek
tomaskavalek / get-random-number-sh
Created Nov 6, 2020
Bash – Get random number in interval
View get-random-number-sh
#!/bin/bash
# Get random number 0–5
local RANDOM_NUMBER=$(grep -m1 -ao '[0-5]' /dev/urandom | head -n1)
@tomaskavalek
tomaskavalek / woocommerce_admin_move_dashboard_menu_item.php
Last active Jul 7, 2020
Allow access WooCommerce orders old way, instead of opening dashboard
View woocommerce_admin_move_dashboard_menu_item.php
<?php
function tk_admin_menu_order()
{
global $submenu;
// WooCommerce
if ( ! isset($submenu['woocommerce'])) {
return false;
}
@tomaskavalek
tomaskavalek / Query
Created Feb 28, 2020 — forked from lukecav/Query
MySQL script to get all WooCommerce orders including metadata
View Query
select
p.ID as order_id,
p.post_date,
max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value END ) as billing_email,
max( CASE WHEN pm.meta_key = '_billing_first_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_first_name,
max( CASE WHEN pm.meta_key = '_billing_last_name' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_last_name,
max( CASE WHEN pm.meta_key = '_billing_address_1' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_1,
max( CASE WHEN pm.meta_key = '_billing_address_2' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_address_2,
max( CASE WHEN pm.meta_key = '_billing_city' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_city,
max( CASE WHEN pm.meta_key = '_billing_state' and p.ID = pm.post_id THEN pm.meta_value END ) as _billing_state,
@tomaskavalek
tomaskavalek / @layout.latte
Created Jan 27, 2020
Contributte DataGrid FilterDate localisation
View @layout.latte
<script src="{$basePath}/path/to/bootstrap-datepicker.cs.js"></script>
@tomaskavalek
tomaskavalek / woocommerce-products-filter.php
Created Feb 23, 2019
WooCommerce Admin Custom Products Filtering
View woocommerce-products-filter.php
<?php
/**
* Return (render :-D) HTML Select > Option for filtering
*
* @param string $post_type
* @return void
*/
function webona_custom_product_filters(string $post_type): void
{
if ($post_type !== 'product') {
@tomaskavalek
tomaskavalek / howto.txt
Created Feb 12, 2019
PHP 7.x + Microsoft SQL Driver & Debian (stretch)
View howto.txt
Firstly install https://warlord0blog.wordpress.com/2017/12/12/php7-0-microsoft-sql-driver-debian-stretch/
Then https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017
@tomaskavalek
tomaskavalek / gulpfile.js
Created Jan 25, 2019
Gulp 4 + Vagrant gulp.watch() fix
View gulpfile.js
// Don't forget to use {usePolling: true}
// Without this options gulp under vagrant ignore file change in synced directory from your machine :-)
gulp.watch(path, {usePolling: true}, ['css']);