Improve handling of extension_loaded()

Now the extension is only considered to be loaded in the
body of the conditional guarded by
 if ( extension_loaded( 'foo' ) ) { ... }
or in the rest of the function, if it's of the format
 if ( !extension_loaded( 'foo' ) ) { ... }

Change-Id: I79c1a368849c739db28b2c0ac37d371ac32951c3