Skip to content

Instantly share code, notes, and snippets.

View dotancohen's full-sized avatar

Dotan Cohen dotancohen

View GitHub Profile
@dotancohen
dotancohen / use-remote-media.php
Created May 10, 2020 09:08 — forked from kingkool68/use-remote-media.php
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', array( $this, 'filter_wp_get_attachment_image_src' ) );
add_filter( 'wp_calculate_image_srcset', array( $this, 'filter_wp_calculate_image_srcset' ) );
add_filter( 'wp_get_attachment_url', array( $this, 'filter_wp_get_attachment_url' ) );
}
@dotancohen
dotancohen / Contract Killer 3.md
Created January 24, 2019 07:53 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@dotancohen
dotancohen / sshhosts
Created January 1, 2018 10:06 — forked from yaronuliel/sshhosts.sh
Connect to preconfigure ssh hosts (set in ~/.ssh/config) via simple list with numbers
#!/usr/bin/env bash
get_hosts="cat ~/.ssh/config | grep Host\\\\s | awk '{ print \$2 }' | sort -u"
if [[ $# -eq 0 ]] ; then
eval "$get_hosts | nl -ba"
exit;
fi
host_num=$1
@dotancohen
dotancohen / php-lint-git.sh
Last active July 3, 2018 12:04 — forked from tony4d/php-lint-git.sh
PHP lint all files added or modified locally
for i in $(git status -s | grep '^\s*A\|^\s*M' | sed -e 's/^.* //'); do php -l $i; done