Skip to content

Instantly share code, notes, and snippets.

View mcgregormedia's full-sized avatar

Andy McGregor mcgregormedia

View GitHub Profile
@mcgregormedia
mcgregormedia / mmwd_update_frontend_woocommerce_fields
Last active August 29, 2015 14:16
Add WooCommerce _visibility and _regular_price metakeys in WPUF form
// Update price and visibility
function mmwd_update_frontend_woocommerce_fields( $post_id, $form_id, $form_settings, $form_vars ){
// update _price depending on _sale_price or _regular_price
$_price = ( $_POST['_sale_price'] ) ? esc_html( $_POST['_sale_price'] ) : esc_html( $_POST['_regular_price'] );
update_post_meta( $post_id, '_price', $_price );
// update _visibility
update_post_meta( $post_id, '_visibility', 'visible' );
function title_format( $content ) {
return '%s';
}
add_filter( 'private_title_format', 'title_format' );
add_filter( 'protected_title_format', 'title_format' );
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 'your.name@your-domain.co.uk';
}
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');
From: "Example User" <email@example.com>
function mmuk_replace_howdy_message( $wp_admin_bar ) {
$my_account = $wp_admin_bar -> get_node( 'my-account' );
$newtitle = str_replace( 'Howdy,', 'Logged in as', $my_account->title );
$wp_admin_bar -> add_node( array(
'id' => 'my-account',
'title' => $newtitle,
) );
}
add_filter( 'admin_bar_menu', 'mmuk_replace_howdy_message',25 );