Skip to content

Instantly share code, notes, and snippets.

View khromov's full-sized avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / gist:6398615
Created August 31, 2013 14:36
Shairport startup script for Raspberry Pi. See full tutorial: http://snippets.khromov.se/raspberry-pi-shairport-build-instructions/
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $networking
# Required-Stop: $remote_fs $networking
# Should-Start: pulseaudio alsa-utils hostname
# Should-Stop: pulseaudio alsa-utils hostname
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
<?php
/*
Plugin Name: Test plugin
Plugin URI: http://snippets.khromov.se/useful-wordpress-filters-drew-jaynes-wordpress-talk
Description: Test plugin
Version: 1.0
Author: khromov
Author URI: http://snippets.khromov.se
License: GPL2
*/
@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 / gist:10502980
Created April 11, 2014 21:27
Adding custom shortcodes to Contact Form 7
<?php
/*
Plugin Name: Contact Form 7 Post Title shortcode
Plugin URI:
Description: Use in form: [post_title thetitle] - use in email (to get value): [thetitle]
Version: 2014.04.07
Author: khromov
Author URI: http://profiles.wordpress.org/khromov/
License: GPL2
*/
@khromov
khromov / wp-users-media.php
Created May 16, 2014 09:44
wp-users-media.php Plugin
<?php
/**
* Plugin Name: WP Users Media
* Plugin URI: http://www.wknet.com/wp-users-media/
* Description: WP Users Media is a WordPress plugin that displays only the current users media files and attachments in WP Admin.
* Version: 1.0.3
* Author: Damir Calusic
* Author URI: http://www.damircalusic.com/
* License: GPLv2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
@khromov
khromov / limit-author-view-scope.php
Created May 28, 2014 15:22
Limit author view scope WordPress
<?php
/*
Plugin Name: Limit Author View scope
Plugin URI:
Description: Limits non-admins to only see their own media and comments.
Version: 2014.05.28
Author: khromov
Author URI: https://profiles.wordpress.org/khromov
License: GPL2
*/
@khromov
khromov / bootstrap-3-grid.css
Last active June 12, 2017 16:05
Bootstrap 3 Grid (Without the rest of the framework).
/*!
* Grid portion of Bootstrap under sc- namespace.
* Classes:
* sc-container-fluid, sc-row, sc-col-X-Y (like regular B3)
*
* For more info, see:
* http://snippets.khromov.se/decoupled-bootstrap-3-grid/
*
* Bootstrap v3.2.0 (http://getbootstrap.com)
* Copyright 2011-2014 Twitter, Inc.
@khromov
khromov / file.php
Last active January 29, 2019 21:24
Advanced Custom Fields get_field() sanitization
<?php
/**
* Helper function to get sanitized field
* and also normalize values.
*
* @param $field_key
* @param bool $post_id
* @param bool $format_value
* @param string $sanitization_method esc_html / esc_attr or NULL for none
* @return array|bool|string
@khromov
khromov / xss.js
Created September 16, 2014 12:59
XSS example
lol</span><script>alert(1);</script>
@khromov
khromov / isMobile.js
Created October 2, 2014 13:23
Mobile detection
/*
* Tiny mobile detection script, courtesy of
* https://github.com/markdalgleish/stellar.js/issues/37
*/
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);