Last active
November 15, 2015 19:17
-
-
Save cdillon/88f919e1269f3a01370b to your computer and use it in GitHub Desktop.
A minimalist WordPress plugin to allow child themes to inherit their parent's screenshot.
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 | |
/** | |
* Plugin Name: Theme Screenshot Inheritance | |
* Description: Child themes without screenshots inherit their parent theme's screenshot. | |
* | |
* Drop this in the /plugins or /mu-plugins directory. | |
*/ | |
/** | |
* Add parent screenshot to child theme. | |
* | |
* @param $prepared_themes | |
* @return mixed | |
*/ | |
function theme_screenshot_inheritance( $prepared_themes ) { | |
// build list of names and id's | |
$list = array(); | |
foreach ( $prepared_themes as $key => $theme ) { | |
$list[$key] = $theme['name']; | |
} | |
$list = array_flip( $list ); | |
// child theme inherits parent screenshot | |
foreach ( $prepared_themes as $key => $theme ) { | |
if ( $theme['parent'] && !$theme['screenshot'][0] ) { | |
// find theme in our list | |
$parent_theme_id = $list[$theme['parent']]; | |
// get screenshot | |
$parent_screenshot = $prepared_themes[$parent_theme_id]['screenshot']; | |
// replace child theme screenshot | |
$prepared_themes[$key]['screenshot'] = $parent_screenshot; | |
} | |
} | |
return $prepared_themes; | |
} | |
add_filter( 'wp_prepare_themes_for_js', 'theme_screenshot_inheritance' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment