Forked from devinsays/custom-logo-update-script.php
Last active
April 14, 2016 01:06
-
-
Save ericnicolaas/fa64a99ef02f9efbcdf89345c74d6aff to your computer and use it in GitHub Desktop.
Code snippet for update script to use new theme logo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Theme Update Script | |
* | |
* Runs if the logo has not been set yet. | |
*/ | |
function prefix_update_check() { | |
// Return if update has already been run | |
if ( -1 == get_theme_mod( 'custom_logo', -1 ) ) { | |
return; | |
} | |
// If we're not on 3.5 yet, exit now | |
if ( ! function_exists( 'the_custom_logo' ) ) { | |
return; | |
} | |
// Set a default value of false for the custom logo | |
$custom_logo = false; | |
// If a logo has been set previously, update to use logo feature introduced in WordPress 4.5 | |
if ( get_theme_mod( 'logo', false ) ) { | |
// Since previous logo was stored a URL, convert it to an attachment ID | |
$logo = attachment_url_to_postid( get_theme_mod( 'logo' ) ); | |
if ( is_int( $logo ) ) { | |
$custom_logo = $logo; | |
} | |
remove_theme_mod( 'logo' ); | |
} | |
set_theme_mod( 'custom_logo', $custom_logo ); | |
} | |
add_action( 'after_setup_theme', 'prefix_update_check' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment