Preserve custom output directory with CLI?
-
I’m hooking the WP
post_updatedaction to a custom function that callswp_schedule_single_event( time(), 'wp_static_html_output_server_side_export_hook' )to automate static exports after each new blog post update.I spent a lot of time trying to figure out why it wasn’t outputting the static files, when I realized it actually was, just to the standard uploads folder and not my custom directory in the plugin’s settings. Manually triggering the static export still uses the custom directory as expected.
I chased it down to \library\StaticHtmlOutput.php:127
get_write_directory()method which is called in_prepareInitialFileList(). It looks like that second method properly checks if the CLI (not GUI) is being used and then uses the custom base URL but not custom output directory as well (see lines 343-349). The custom output directory is only determined once from the HTTP POST ‘outputDirectory’ set to$outputDirvariable, and not saved database options. Of course with the CLI option, the HTTP POST value won’t be available, so it falls through towp_upload_dir()on line 136.Can this be refactored in the next update? I think a really simple
elsestatement within_prepareInitialFileList()would fix it:if ($viaCLI) { // read options from DB as array parse_str($this->_options->getOption('static-export-settings'), $pluginOptions); $newBaseURL = $pluginOptions['baseUrl']; $additionalUrls = $pluginOptions['additionalUrls']; $uploadDir = $pluginOptions['outputDirectory']; }else{ $uploadDir = $this->get_write_directory(); }…or you could deal with it directly in
get_write_directory()so that method still handles the logic it is named for, but the necessary $pluginOptions variable isn’t declared there.
The topic ‘Preserve custom output directory with CLI?’ is closed to new replies.