Skip to content

Instantly share code, notes, and snippets.

View Tusko's full-sized avatar

Tusko Trush Tusko

View GitHub Profile
@Tusko
Tusko / backdrop.css
Created June 13, 2022 07:50
blue background
.element {
backdrop-filter: saturate(50%) blur(8px);
-webkit-backdrop-filter: saturate(50%) blur(8px);
}
@Tusko
Tusko / functions.php
Last active February 27, 2022 13:46
WP Ajax search (ACF included)
<?php
/* Wordpress Custom Search by title, ACF, post_meta */
// Wordpress ?s= redirect to /search/
function wpa_search_redirect() {
global $wp_rewrite;
if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) { return; }
$search_base = $wp_rewrite->search_base;
if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {
wp_redirect(home_url("/{$search_base}/" . urlencode(get_query_var('s'))));
@Tusko
Tusko / jquery.ajax.js
Last active November 12, 2021 02:54
$.ajax Promise
/*
* ajax Defaults (optional):
$.ajaxSetup({
type : 'POST',
dataType : 'json',
cache : true,
global : true,
data : {},
contentType : 'application/json',
beforeSend : function (xhr) {
@Tusko
Tusko / functions.php
Created June 4, 2021 11:04
Get access by product SKU for Woocommerce
<?php
//place code in the end of functions.php in theme
add_action('template_redirect', 'wc_sku_redirect');
function wc_sku_redirect() {
$parseUrl = explode('/', $wp->request);
if(isset($parseUrl[0]) && $parseUrl[0] === 'product') {
$pid = wc_get_product_id_by_sku($parseUrl[1]);
if($pid) {
wp_safe_redirect(get_permalink($pid));
exit;
@Tusko
Tusko / example.json
Created March 18, 2021 10:28
Woocommerce import from json
[
{
"id": "new24",
"category_id": "new-category",
"category_name": "Моя нова категорія",
"category_published": true,
"name": "Новий товар lab24",
"private": false,
"price": 199,
"pricelist": [
@Tusko
Tusko / deferimg.js
Last active September 27, 2020 09:51
deferimg.js
function load_defer_img(source) {
'use strict';
return $.Deferred(function(task) {
var image = new Image();
image.onload = function() {
task.resolve(image);
};
image.onerror = function() {
task.reject();
};
@Tusko
Tusko / LICENSE
Created September 2, 2020 11:15 — forked from engelfrost/LICENSE
Fake localStorage. Useful for Safari Private Browsing and browsers that don't implement localStorage.
The MIT License (MIT)
Copyright (c) 2015 Textalk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@Tusko
Tusko / functions.php
Last active April 18, 2020 16:59
Get archives of Custom Post Type
function get_cpt_archives( $cpt, $echo = false ) {
global $wpdb;
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s AND post_status = 'publish' GROUP BY YEAR({$wpdb->prefix}posts.post_date), MONTH({$wpdb->prefix}posts.post_date) ORDER BY {$wpdb->prefix}posts.post_date DESC", $cpt );
$results = $wpdb->get_results( $sql );
if ( $results ) {
$archive = array();
foreach ( $results as $r ) {
$year = date( 'Y', strtotime( $r->post_date ) );
$month = date( 'F', strtotime( $r->post_date ) );
@Tusko
Tusko / header.php
Last active March 21, 2020 11:40
ACF tel button output
<?php
$tel = get_field( 'tel', 'options' );
echo $tel ? '<a class="header-tel" href="tel:' . preg_replace( "/[^0-9+]/", "", $tel ) . '">' . $tel . '</a>' : '';
@Tusko
Tusko / bower.json
Created March 17, 2020 12:18 — forked from marchrius/bower.json
Load Google Maps API using jQuery Deferred.
{
"name": "load-google-maps",
"version": "1.0.0",
"authors": ["Glenn Baker", "Gavin Foley", "Matteo Gaggiano"],
"description": "Load Google Maps API using jQuery Deferred.",
"main": "load-google-maps.js",
"keywords": ["Google Maps", "Async"],
"license": ["MIT", "GPL"],
"dependencies": {
"jquery": ">=1.5"