Skip to content

Instantly share code, notes, and snippets.

@kingkool68
kingkool68 / use-remote-media.php
Last active March 24, 2024 11:37
Check if a local file exists in the WordPress media library and if it doesn't exist, replace the URL with a different URL. Helpful when working with a local site that doesn't have all of the media downloaded as the production site. See https://localwp.com/community/t/proxying-requests-to-wp-content-uploads-to-a-production-site/15701
<?php
// Put this in wp-config.php and replace https://example.com/ with the URL of the production site.
define( 'RH_USE_REMOTE_MEDIA_URL', 'https://example.com/' );
// Put the rest of this in functions.php or a custom plugin or somewhere else.
if ( defined( 'RH_USE_REMOTE_MEDIA_URL' ) && ! empty( RH_USE_REMOTE_MEDIA_URL ) ) {
add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src' );
add_filter( 'wp_calculate_image_srcset', 'filter_wp_calculate_image_srcset' );
add_filter( 'wp_get_attachment_url', 'filter_wp_get_attachment_url' );
}
@adactio
adactio / minimal-serviceworker.js
Last active August 18, 2023 09:15
An attempt at a minimal viable service worker.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
// HTML files: try the network first, then the cache.
// Other files: try the cache first, then the network.
// Both: cache a fresh version if possible.
// (beware: the cache will grow and grow; there's no cleanup)
const cacheName = 'files';
@murtaugh
murtaugh / eems-droplet-for-EE2.md
Last active October 27, 2021 03:33
Set up a DigitalOcean droplet for ExpressionEngine

(This is an updated version of Clearfire's tutorial, which is excellent, but has become slightly outdated as Digital Ocean updates their applications.)

  1. Create your droplet. Name it, select your size and location, then hit the Applications tab and select (as of this writing) "LAMP on 14.04". Add your SSH key if you want, and submit.
  2. SSH into your new droplet, and maybe check to make sure the following PHP modules have been installed: (In my recent experience, these have all been installed automatically, but that could change, and it takes 10 seconds to check.)

    apt-get install php5-gd

    apt-get install php5-mysql

    apt-get install php5-curl

  3. Make sure mod_rewrite is enabled, with a2enmod rewrite.
  4. If you like, increase PHP's upload_max_filesize and post_max_filesize values by editing the php.ini file, with this: nano /etc/php5/apache2/php.ini
  5. Give Apach