Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
wp_get_theme() - false positives...
<?php
/*
Installed themes:
Parent theme = Genesis version 1.9.1
Child theme = Child version 1.0
*/
// EXAMPLE 1:
$theme = wp_get_theme( get_template_directory() );
// var_dump $theme->get( 'Template') returns 'genesis'
// var_dump $theme->get( 'Version' ) returns bool(false)
// Using this example...
$minimum = '2.0';
$out = version_compare( $theme->get( 'Version' ), $minimum, '<' ) );
// var_dump $out returns bool(true), therefore we think installed version is good to go
// but in fact installed version is only 1.9.1 and we need 2.0
// This is because bool(false) is evaluated as "less than" $minimum, so we get a false result
// EXAMPLE 2:
$theme = wp_get_theme();
// var_dump $theme->get( 'Template') returns 'genesis'
// var_dump $theme->get( 'Version' ) returns '1.0', which is child theme version!
// Using this example...
$minimum = '1.8';
$out = version_compare( $theme->get( 'Version' ), $minimum, '<' ) );
// var_dump $out returns bool(false) but our installed G version is 1.9.1!
// This is because the compare is between child theme and genesis versions
// and returns a false result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.