Skip to content

Instantly share code, notes, and snippets.

Avatar

Stanislav Khromov khromov

View GitHub Profile
@khromov
khromov / gist:6398615
Created Aug 31, 2013
Shairport startup script for Raspberry Pi. See full tutorial: http://snippets.khromov.se/raspberry-pi-shairport-build-instructions/
View gist:6398615
#! /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
View wordpress-test-plugin.php
<?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 Aug 14, 2022
Fixing Cart Widget showing the incorrect item when using WPML with WooCommerce, by forcing cart widget to refresh on every page load.
View cart-cache-breaker.php
/** 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 Apr 11, 2014
Adding custom shortcodes to Contact Form 7
View gist:10502980
<?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
wp-users-media.php Plugin
View wp-users-media.php
<?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
Limit author view scope WordPress
View limit-author-view-scope.php
<?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 Jun 12, 2017
Bootstrap 3 Grid (Without the rest of the framework).
View bootstrap-3-grid.css
/*!
* 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 Jan 29, 2019
Advanced Custom Fields get_field() sanitization
View file.php
<?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 Sep 16, 2014
XSS example
View xss.js
lol</span><script>alert(1);</script>
@khromov
khromov / isMobile.js
Created Oct 2, 2014
Mobile detection
View isMobile.js
/*
* 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);