WordPress: Allow Gantry theme upgrades from WordPress theme uploader (#1165)

This commit is contained in:
Matias Griese
2016-03-04 13:55:48 +02:00
parent 2d3cd1ecab
commit f98dbfe2ee
2 changed files with 27 additions and 0 deletions
+2
View File
@@ -7,6 +7,8 @@
3. [](#bugfix)
- Fixed error on saving system outline layouts (#1167)
3. [WordPress](#wordpress)
1. [](#new)
- Allow Gantry theme upgrades from WordPress theme uploader (#1165)
3. [](#bugfix)
- Fixed Hydrogen Child theme to reference properly `g5_hydrogen` parent directory
@@ -4,6 +4,8 @@ defined('ABSPATH') or die;
add_action( 'admin_init', 'gantry5_admin_start_buffer', -10000 );
add_action( 'admin_enqueue_scripts', 'gantry5_admin_scripts' );
add_action( 'wp_ajax_gantry5', 'gantry5_layout_manager' );
add_filter( 'upgrader_package_options', 'gantry5_upgrader_package_options', 10000 );
add_filter( 'upgrader_source_selection', 'gantry5_upgrader_source_selection', 0, 4 );
// Check if Timber is active before displaying sidebar button
if ( class_exists( 'Timber' ) ) {
@@ -78,3 +80,26 @@ function gantry5_layout_manager() {
// wp_die( $e->getMessage() );
}
}
// SimpleXmlElement is a weird class that acts like a boolean, we are going to take advantage from that.
class Gantry5Truthy extends SimpleXmlElement { }
function gantry5_upgrader_package_options($options) {
if ($options['abort_if_destination_exists'] && !$options['clear_destination']) {
$options['abort_if_destination_exists'] = new Gantry5Truthy('<bool><true></true></bool>');
$options['hook_extra']['gantry5_abort'] = $options['abort_if_destination_exists'];
}
return $options;
}
function gantry5_upgrader_source_selection($source, $remote_source, $this, $hook_extra) {
if (isset($hook_extra['gantry5_abort'])) {
// Allow upgrading Gantry themes from uploader.
if (file_exists($source . '/gantry/theme.yaml')) {
unset($hook_extra['gantry5_abort']->true);
}
}
return $source;
}