Skip to content

Instantly share code, notes, and snippets.

View khromov's full-sized avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / cart-cache-breaker.php
Last active August 14, 2022 01:39
Fixing Cart Widget showing the incorrect item when using WPML with WooCommerce, by forcing cart widget to refresh on every page load.
/** Break html5 cart caching */
add_action('wp_enqueue_scripts', 'cartcache_enqueue_scripts', 100);
function cartcache_enqueue_scripts()
{
wp_deregister_script('wc-cart-fragments');
wp_enqueue_script( 'wc-cart-fragments', get_template_directory_uri() . '/cart-fragments.js', array( 'jquery', 'jquery-cookie' ), '1.0', true );
}
@khromov
khromov / tampermonkey-script.js
Last active August 12, 2022 12:48
Tampermonkey: Find driving slot Trafikverket
// ==UserScript==
// @name Find slot
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Book a Förarprov with the place and type (manual/auto) that you want, then go to Boka Prov > Personbil B > Bokade Prov > Press the edit icon for the existing test. Enable the script and reload the page. The script will look for a better time in the same configuration of auto/manual and location.
// @author You
// @match https://fp.trafikverket.se/boka/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=trafikverket.se
// @require https://cdnjs.cloudflare.com/ajax/libs/ion-sound/3.0.7/js/ion.sound.min.js
// @grant none
@khromov
khromov / gutenberg-locked-template.php
Created June 9, 2022 23:41
WordPress Gutenberg - Add a locked template to a post type
<?php
add_action('init', function() {
// For which posts type
$post_type_object = get_post_type_object( 'post' );
// Which allowed blocks
$post_type_object->template = [
['core/heading', ['level' => '5', 'content' => 'Default value']],
['core/paragraph'],
['core/image'],
@khromov
khromov / control-blocks-by-post-type.php
Created June 9, 2022 23:32
WordPress Gutenberg - Control allowed blocks by post type
<?php
add_filter( 'allowed_block_types_all', function($allowed_block_types, $block_editor_context) {
if ( $block_editor_context->post->post_type === 'post' ) {
return [
'acf/my-cool-block',
'core/paragraph'
];
}
return $allowed_block_types;
}, 10, 2 );
@khromov
khromov / docker-compose.yml
Created August 24, 2021 13:55
docker-compose file for Redis with persistence
version: "3"
services:
redis:
image: "redis:6.2-alpine"
command: sh -c "redis-server --appendonly yes"
ports:
- "6379:6379"
volumes:
- ./redis-data:/data
@khromov
khromov / sync-parent-categories-acf.php
Last active August 14, 2021 23:40
Sync taxonomy categories with ACF taxonomy field in WordPress
<?php
add_action('save_post', array($this, 'mark_parent_categories'), 11);
/**
* Marks parent categories automatically. Works with the ACF taxonomy selector as well.
*
* @return mixed
*/
function mark_parent_categories($post_id) {
global $post;
@khromov
khromov / README.md
Last active September 20, 2020 22:04
docker-compose file for phpMyAdmin and MySQL
@khromov
khromov / PWAOfflineStatus.js
Last active July 26, 2020 04:57
React Progressive Web App Online / Offline warning message hook
import React, { useState, useEffect } from 'react';
function PWAOfflineStatus(props) {
const [isOnline, setOnlineStatus] = useState(true);
// https://stackoverflow.com/questions/44756154/progressive-web-app-how-to-detect-and-handle-when-connection-is-up-again
useEffect(() => {
const setFromEvent = function(event) {
if(event.type === 'online') {
setOnlineStatus(true);
@khromov
khromov / README.md
Created July 12, 2019 08:38
Amazing Marvin webhook

Webhook for Amazing Marvin

In order for this to work you need to fetch your Zapier token from Marvin Settings > Strategies > Zapier integration > Settings.

However, you don't actually need a Zapier for this to work, just send the request from your favourite framework.

@khromov
khromov / README.md
Last active May 16, 2020 07:38
Migrate an Amazing Marvin list to Wallabag

Migrate an Amazing Marvin reading list to Wallabag

Example: You've been using the Amazing Marvin Bookmarklet and now the tasks have piled up and Marvin is acting sluggish. Wallabag is a prefect place to migrate these bookmarks.

Prerequisites

  • PHP 7
  • Python 3

Process

  • Export one or more of your reading lists containings URLs from Amazing Marvin by going to Account > Backups > Backup.