Skip to content

Instantly share code, notes, and snippets.

View tomaskavalek's full-sized avatar
:octocat:
Hardworking anytime 👍

Tomáš Kavalek tomaskavalek

:octocat:
Hardworking anytime 👍
View GitHub Profile
@tomaskavalek
tomaskavalek / wp-user-role-body-class.php
Created February 21, 2023 15:35
WordPress – Add user roles to body class
<?php
function tk_add_user_role_to_body_classes($classes)
{
global $current_user;
foreach ($current_user->roles as $user_role) {
if (is_admin()) {
$classes .= ' role-' . $user_role;
} else {
$classes[] = 'role-' . $user_role;
@tomaskavalek
tomaskavalek / SortableDirectoryIterator.php
Created February 17, 2023 11:40
Sortable solution for DirectoryIterator
<?php
class SortableDirectoryIterator implements IteratorAggregate
{
private $storage;
public function __construct($path)
{
$this->storage = new ArrayObject();
$files = new DirectoryIterator($path);
@tomaskavalek
tomaskavalek / wordpress-happyforms-recaptcha.php
Created September 13, 2022 12:29
WordPress HappyForms reCAPTCHA – solution for free version of HappyForms plugin
<?php
/**
* Google reCAPTCHA for WordPress HappyForms
*
* @author Tomas Kavalek <[email protected]>
* @version 1.0.0
*/
class HappyForms_Recaptcha
{
@tomaskavalek
tomaskavalek / plural.js
Created May 6, 2021 11:41
JavaScript Plurals
// 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 January 4, 2021 11:41
WordPress Contact Form 7 + Invisible reCAPTCHA – Removing duplicate ajax-loader
(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 November 16, 2020 17:57
Debug WordPress admin menu – on dashboard only
<?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 November 6, 2020 11:00
Bash – Get random number in interval
#!/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 July 7, 2020 08:41
Allow access WooCommerce orders old way, instead of opening dashboard
<?php
function tk_admin_menu_order()
{
global $submenu;
// WooCommerce
if ( ! isset($submenu['woocommerce'])) {
return false;
}
@tomaskavalek
tomaskavalek / Query
Created February 28, 2020 14:30 — forked from lukecav/Query
MySQL script to get all WooCommerce orders including metadata
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 January 27, 2020 08:55
Contributte DataGrid FilterDate localisation
<script src="{$basePath}/path/to/bootstrap-datepicker.cs.js"></script>