WordPress MP6 registers Google fonts apart from my theme

My theme (customized theme Esplanade on www.maartenvandekamp.nl) uses Google fonts. These fonts are registered and enqueued the right way in functions.php.

The new (secret!) plugin MP6 also uses Google fonts, but does not check if a user is logged in, so these fonts are always enqueued when a post of page is viewed, even when I’m logged out. In my case, a visitor downloads the same font twice, taking extra bandwidth and loading time.

You can recognize the MP6 stylesheet by the next line:

<link rel='stylesheet' id='open-sans-css' href='//fonts.googleapis.com/css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&#038;subset=latin-ext%2Clatin&#038;ver=0.1' type='text/css' media='all' />

This bug (for me) is easy to fix.

Fix

Open WordPress Admin and navigate to the plugin editor ( Plugins > Editor ), select the MP6 plugin (mp6/mp6.php) and scroll down until you reach the following function:

function mp6_load_open_sans()

Add the following line – if ( is_user_logged_in() ) - above the line:

wp_register_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=latin-ext,latin', false, 0.1 );

The new code will be:


// load Open Sans
add_action( 'init', 'mp6_load_open_sans' );
function mp6_load_open_sans() {
if ( is_user_logged_in() ) 
    wp_register_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=latin-ext,latin', false, 0.1 );
    wp_enqueue_style( 'open-sans' );
}

The MP6 plugin will work as expected when a user / admin is logged in and when this is not the case, the Google fonts won’t be enqueued and no extra bandwidth will be wasted