Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am yrosen on github.
  • I am yrosen (https://keybase.io/yrosen) on keybase.
  • I have a public key ASAlm2NJYbYOqK-kMuJ9BHUFhuk6eW8fQVQQVjHu0uz5AAo

To claim this, I am signing this object:

@yrosen
yrosen / wp-preview-changes-meta-fix.php
Last active December 21, 2015 01:59 — forked from roborourke/wp-preview-changes-meta-fix.php
Fix is_preview() to work properly when updating in admin AND when previewing in front end.
<?php
// post meta for previews
class wp_preview_meta {
private $doing_preview = false;
public function __construct() {
add_filter( 'add_post_metadata', array( $this, 'add' ), 10, 5 );
add_filter( 'update_post_metadata', array( $this, 'update' ), 10, 5 );
@yrosen
yrosen / functions.php
Created July 3, 2013 01:26
Make WordPress look at specific post meta fields when doing a search
<?php
add_action('posts_where_request', function($where) use($wpdb, $wp) {
if(is_search()) {
// Change this as needed
$keys = implode("','", array('url', 'author', 'source', 'subtitle'));
// Search in meta fields as well:
$where .= " OR ({$wpdb->postmeta}.meta_key IN('{$keys}') AND {$wpdb->postmeta}.meta_value LIKE '%{$wp->query_vars['s']}%')";
// Add in the postmeta table:
@yrosen
yrosen / gelfErrorHandler.php
Last active December 10, 2015 06:08
Replaces PHP's default error handler with one that sends everything to a GELF server (tested with Graylog2)
<?php
/**
* Replaces PHP's default error handler with one that
* sends everything to a GELF server (tested with Graylog2)
*
* From the PHP docs: The following error types cannot be handled with
* a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING,
* E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the
* file where set_error_handler() is called.
*
@yrosen
yrosen / firewall.sh
Created February 9, 2012 21:14
Basic iptables firewall
#!/bin/sh
# Drop ICMP echo-request messages sent to broadcast or multicast addresses
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Drop source routed packets
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
# Enable TCP SYN cookie protection from SYN floods
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
@yrosen
yrosen / ansicolors.sh
Created May 23, 2011 20:57
Shows forground & background ANSI color codes
#!/bin/sh
# I'm not really sure where this is originally from...
# It prints out a (colored!) list of background & foreground colors
for attr in 0 1 4 5 7 ; do
printf "ESC[%s;Foreground;Background - \n" $attr
for fore in 30 31 32 33 34 35 36 37; do
for back in 40 41 42 43 44 45 46 47; do
printf '\033[%s;%s;%sm %02s;%02s ' $attr $fore $back $fore $back