Skip to content

Instantly share code, notes, and snippets.

View danielhomer's full-sized avatar

Daniel Homer danielhomer

View GitHub Profile
@danielhomer
danielhomer / functions.php
Last active May 23, 2019 10:42
WordPress - Check network site for post before 404'ing
<?php
/**
* This filter will attempt to fetch a post from the main site if a post cannot be found
* on a child site.
**/
add_filter( 'the_posts', function( $posts, $wp_query ) {
$network_id = get_network()->site_id;
if ( ( ( count( $posts ) === 0 && is_single() ) || is_archive() || is_home() ) && get_current_blog_id() !== $network_id ) {

Keybase proof

I hereby claim:

  • I am danielhomer on github.
  • I am danielhomer (https://keybase.io/danielhomer) on keybase.
  • I have a public key ASBnJ0x1yTYyLlmfFW6EbSrnV4BvsjO97NsdEs8oMTOMMgo

To claim this, I am signing this object:

cd /path/to/root
for id in $(wp site list --field=blog_id)
do
echo ${id}
mysql -h##HOST## -u##USER## -p##PASSWORD## -e "DELETE FROM wp_${id}_postmeta WHERE meta_key LIKE '_oembed_%' and meta_key NOT LIKE '_oembed_time_%' and meta_value NOT LIKE '%>' AND meta_value != '{{unknown}}';" ##DB_NAME##
echo Flushed dodgy OEmbeds from site ${id}
done
cd /path/to/root
for url in $(wp site list --field=domain)
do
echo ${url}
wp --url=${url} option update db_version 30133
echo
done
wp --url=${url} core update-db --network
@danielhomer
danielhomer / gist:10dd2015e0e91f81bf05
Created November 3, 2015 11:00
Update Guest Additions to 5.0.2 on CentOS
vagrant ssh
cd /opt
sudo wget -c http://download.virtualbox.org/virtualbox/5.0.2/VBoxGuestAdditions_5.0.2.iso -O VBoxGuestAdditions_5.0.2.iso
sudo mount VBoxGuestAdditions_5.0.2.iso -o loop /mnt
cd /mnt
sudo sh VBoxLinuxAdditions.run --nox11
cd /opt
sudo /etc/init.d/vboxadd setup
sudo chkconfig --add vboxadd
sudo chkconfig vboxadd on
$(document).on('click', 'keystone_newsletter_delete_image', function(event) {
var image = $('#'+$(this).attr('data-image'));
var input = $('#'+$(this).attr('data-input'));
input.val('');
image.attr('src','');
});
(function($) {
$.ajax({
url: ajaxurl,
action: 'my_wp_ajax_action'
})
.success(function(response) {
if (typeof response.success === 'undefined') {
// undefined error
} else if (response.success === false) {
<?php
add_filter( 'check_less_compile', function( $value ) {
if ( defined( 'KEYSTONE_CACHE_BUST' ) && KEYSTONE_CACHE_BUST ) {
$less_cache_bust = get_option( 'less_cache_bust', false );
if ( $less_cache_bust === KEYSTONE_CACHE_BUST ) {
$value = false;
} else {
update_option( 'less_cache_bust', KEYSTONE_CACHE_BUST );
@danielhomer
danielhomer / gist:44dd62b68c0a2244f767
Created February 11, 2015 15:17
Force login on WP
<?php
function force_login() {
if ( ! is_user_logged_in() ) {
wp_safe_redirect( wp_login_url(), 301 );
exit();
}
}
add_action( 'template_redirect', 'force_login' );