Skip to content

Instantly share code, notes, and snippets.

@foliovision
Last active October 24, 2016 11:40
Show Gist options
  • Save foliovision/86835e70c0062481d708 to your computer and use it in GitHub Desktop.
Save foliovision/86835e70c0062481d708 to your computer and use it in GitHub Desktop.
Profile Builder - make the custom avatars global for WP Multisite
<?php
if( is_multisite() && function_exists('switch_to_blog') ) {
add_filter( 'get_avatar', 'fv_pb_global_avatar_start', 20, 5 );
add_filter( 'get_avatar', 'fv_pb_global_avatar_end', 22, 5 );
function fv_pb_global_avatar_start( $avatar ) {
switch_to_blog(1);
return $avatar;
}
function fv_pb_global_avatar_end($avatar) {
restore_current_blog();
$avatar = preg_replace( "~src='.*?/wp-content~", "src='/wp-content", $avatar );
return $avatar;
}
}
add_action( 'current_screen', 'fv_wppb_upload_to_master_blog', 0 );
function fv_wppb_upload_to_master_blog() {
if ( isset($_REQUEST['action']) && 'upload-attachment' == $_REQUEST['action'] && isset($_REQUEST['wppb_upload']) && 'true' == $_REQUEST['wppb_upload'] ) {
switch_to_blog(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment