Created
January 16, 2021 16:57
-
-
Save baizmandesign/8d56f459f02ed4842402142449db13ae to your computer and use it in GitHub Desktop.
layouts / inc / theme / wpddl.theme-support.class.php patch for WP CLI layouts import command
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
Index: wpddl.theme-support.class.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/wpddl.theme-support.class.php b/wpddl.theme-support.class.php | |
--- a/wpddl.theme-support.class.php (date 1610816073426) | |
+++ b/wpddl.theme-support.class.php (date 1610816073426) | |
@@ -39,7 +39,7 @@ | |
$this->file_manager_export = new WPDD_FileManager('/theme-dd-layouts', 'wp_nonce_export_layouts_to_theme'); | |
- if (is_admin()) { | |
+ if (is_admin() || defined ('WP_CLI') ) { | |
if (isset($_GET['page']) && $_GET['page'] == 'toolset-export-import') { | |
add_action('wp_loaded', array($this, 'export_and_download_layouts')); | |
add_action('wp_loaded', array($this, 'import_layouts')); | |
@@ -70,7 +70,9 @@ | |
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){ | |
die(''); | |
} else { | |
- printf('<div class="alert-no-post-content toolset-alert toolset-alert-error">%s</div>', $text); | |
+ if ( ! defined ('WP_CLI') ) { | |
+ printf('<div class="alert-no-post-content toolset-alert toolset-alert-error">%s</div>', $text); | |
+ } | |
} | |
} | |
@@ -342,7 +344,7 @@ | |
die(wp_json_encode($out)); | |
} | |
- function import_layouts() | |
+ function import_layouts( $files = null, $args = array() ) | |
{ | |
if ($_POST) { | |
if (isset($_POST['ddl-import']) && $_POST['ddl-import'] == __('Import', 'ddl-layouts') && isset($_POST['layouts-import-nonce']) && wp_verify_nonce($_POST['layouts-import-nonce'], 'layouts-import-nonce')) { | |
@@ -358,6 +360,17 @@ | |
add_action('admin_notices', array(&$this, 'nonce_control_failed')); | |
} | |
} | |
+ | |
+ if ( defined ( 'WP_CLI' ) ) { | |
+ $overwrite = isset($args['layouts-overwrite']) ? true : false; | |
+ $delete = isset($args['layouts-delete']) ? true : false; | |
+ $overwrite_assignment = isset($args['overwrite-layouts-assignment']) ? true : false; | |
+ | |
+ $import = $this->manage_manual_import($files, $overwrite, $delete, $overwrite_assignment); | |
+ | |
+ return $import ; // Return result to WP CLI interface. | |
+ | |
+ } | |
} | |
function nonce_control_failed() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment