Skip to content

Instantly share code, notes, and snippets.

View mcgregormedia's full-sized avatar

Andy McGregor mcgregormedia

View GitHub Profile
111.119.236.122 - - [06/Oct/2015:12:06:54 +0100] "POST /xmlrpc.php HTTP/1.1" 200 899 "-" "-"
@mcgregormedia
mcgregormedia / gist:d2f9f3a5305061e83162
Last active October 9, 2015 10:50
Disable WordPress XML-RPC methods
add_filter( 'xmlrpc_methods', 'remove_xmlrpc_methods');
function remove_xmlrpc_methods( $methods ) {
unset( $methods['system.multicall'] );
unset( $methods['system.listMethods'] );
unset( $methods['system.getCapabilities'] );
return $methods;
}
@mcgregormedia
mcgregormedia / gist:7a0f2df66505a7776625
Created October 9, 2015 10:22
Disable WordPress XML-RPC
add_filter('xmlrpc_enabled','__return_false');
@mcgregormedia
mcgregormedia / gist:a2db146114b04f4bec3b
Created October 9, 2015 10:22
Block XML-PC in htaccess
<files xmlrpc*="">
order deny,allow
deny from all
</files>
function mmuk_scripts() {
wp_enqueue_script( 'retina-js', get_template_directory_uri() . '/js/retina.js', '', '', true );
}
add_action( 'wp_enqueue_scripts', 'mmuk_scripts' );
add_filter( 'delete_attachment', 'delete_retina_support_images' );
function delete_retina_support_images( $attachment_id ) {
$meta = wp_get_attachment_metadata( $attachment_id );
$upload_dir = wp_upload_dir();
$path = pathinfo( $meta['file'] );
foreach ( $meta as $key => $value ) {
if ( 'sizes' === $key ) {
foreach ( $value as $sizes => $size ) {
$original_filename = $upload_dir['basedir'] . '/' . $path['dirname'] . '/' . $size['file'];
$retina_filename = substr_replace( $original_filename, '@2x.', strrpos( $original_filename, '.' ), strlen( '.' ) );
function retina_support_create_images( $file, $width, $height, $crop = false ) {
if ( $width || $height ) {
$resized_file = wp_get_image_editor( $file );
if ( ! is_wp_error( $resized_file ) ) {
$filename = $resized_file->generate_filename( $width . 'x' . $height . '@2x' );
$resized_file->resize( $width * 2, $height * 2, $crop );
$resized_file->save( $filename );
$info = $resized_file->get_size();
add_filter( 'wp_generate_attachment_metadata', 'retina_support_attachment_meta', 10, 2 );
function retina_support_attachment_meta( $metadata, $attachment_id ) {
foreach ( $metadata as $key => $value ) {
if ( is_array( $value ) ) {
foreach ( $value as $image => $attr ) {
if ( is_array( $attr ) )
retina_support_create_images( get_attached_file( $attachment_id ), $attr['width'], $attr['height'], true );
}
}
}
function new_mail_from( $old ) {
return '[email protected]';
}
function new_mail_from_name( $old ) {
return 'Your Name';
}
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');