• Resolved shareasale-wp

    (@shareasale-wp)


    I’m hooking the WP post_updated action to a custom function that calls wp_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 $outputDir variable, and not saved database options. Of course with the CLI option, the HTTP POST value won’t be available, so it falls through to wp_upload_dir() on line 136.

    Can this be refactored in the next update? I think a really simple else statement 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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Leon Stafford

    (@leonstafford)

    Hi Shareasale,

    Thanks for using the plugin and for going to length to describe the issue that’s occurring.

    I’ve marked this in for the V2.6 release, together with some more checking of the CLI export and custom output dir settings:

    https://github.com/leonstafford/wordpress-static-html-plugin/projects/2

    My testing plan for the last few releases has been a bit too ad-hoc, so some bugs like this are creeping in. I have a more comprehensive test plan for V2.6 to ensure more stable functionality.

    Cheers,

    Leon

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Awesome, and thanks for the super fast reply!

    Plugin Author Leon Stafford

    (@leonstafford)

    Hi Shareasale,

    I was able to put it into the get_write_directory() as you suggested.

    Please have a try of this version of the plugin, including the fix:

    https://github.com/leonstafford/wordpress-static-html-plugin/raw/master/shareasale.zip

    This will include some other changes scheduled for V2.6 release. If you notice any other issues with this development version, please let me know.

    Cheers,

    Leon

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Thanks, Leon! I really appreciate it. So far it works great, but I’ll let you know if I discover anything else with 2.6. 🙂

    Plugin Author Leon Stafford

    (@leonstafford)

    Awesome, glad that it worked out!

    If you’re happy with the plugin, please consider leaving a review here:

    https://ww.wp.xz.cn/support/plugin/static-html-output-plugin/reviews/

    Cheers,

    Leon

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Done, and one better — I also donated to the plugin’s development. Thanks again. 🙂

    Plugin Author Leon Stafford

    (@leonstafford)

    Many thanks! Glad I could be of help. Let me know if there are any features you’d like to see added and stay tuned for some nice stuff coming in V2.6 soon. Cheers, Leon

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Unfortunately 2.6 seems to have broken the CLI exports for us. At first I thought it just wasn’t retaining the files and zip archive for CLI exports, since all I got back was an empty directory when it was triggered. However, checking the WP-STATIC-EXPORT-LOG file shows it has only a couple of line entries compared to the manual export, which works fine. Maybe something to look into?

    Reverting to the 2.5 version you linked above on Github fixed it for us.

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Additionally, I noticed in 2.6 the settings page URL/slug must have changed so immediately after updating, you get an access denied instead. I solved this same situation in another plugin of mine by using WordPress’ “admin_page_access_denied” hook with this function:

    
    /* for backwards compatibility with v1.0's old settings slug... */
    	public function admin_page_access_denied() {
    		if ( isset( $_GET['page'] ) && 'old_plugin_name' === $_GET['page'] ) {
    			$new_settings_url = menu_page_url( 'new_plugin_name', false );
    			wp_redirect( $new_settings_url );
    			exit;
    		}
    	}

    Hope it helps!

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Digging into the logs, it looks like it’s due to a fatal error:

    PHP Fatal error:  Uncaught Error: Call to undefined function get_home_path() in /var/www/html/wp-content/plugins/static-html-output-plugin/library/StaticHtmlOutput/UrlRequest.php:1148
    Stack trace:
    #0 /var/www/html/wp-content/plugins/static-html-output-plugin/library/StaticHtmlOutput.php(457): StaticHtmlOutput_UrlRequest->cleanup()
    #1 /var/www/html/wp-content/plugins/static-html-output-plugin/library/StaticHtmlOutput.php(508): StaticHtmlOutput->crawlABitMore(true)
    #2 /var/www/html/wp-content/plugins/static-html-output-plugin/library/StaticHtmlOutput.php(1058): StaticHtmlOutput->crawl_site(true)
    #3 /var/www/html/wp-content/plugins/static-html-output-plugin/wp-static-html-output.php(53): StaticHtmlOutput->doExportWithoutGUI()
    #4 /var/www/html/wp-includes/class-wp-hook.php(284): wp_static_html_output_server_side_export()
    #5 /var/www/html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
    #6 /var/www/html/wp-includes/plugin.php(515): WP_Hook->do_action(Array)
    #7 /var/www/html/wp-cron.php(126): do_action_ref_array in /var/www/html/wp-content/plugins/static-html-output-plugin/library/StaticHtmlOutput/UrlRequest.php on line 1148

    Just switching get_home_path() with ABSPATH fixes the issue, as far as I can tell.

    Plugin Author Leon Stafford

    (@leonstafford)

    Hi Shareasale,

    Thanks again for reporting your issue with lots of information, it really helps.

    I’ll look into these 2 issues now.

    Could you please tell me a bit more about your environment, as I need to start testing better in a combination of potential user environments:

    ie,

    – is your source WP site in a domain.com/subdir/ or just a top level domain?
    – anything else unique about your development environment that may be pertinent information?

    I do remember checking this when I added that function call last week, it seems I should have read it harder: https://wordpress.stackexchange.com/questions/188448/whats-the-difference-between-get-home-path-and-abspath

    I have 2 other bug fixes from this release ready to go out tonight, so will look to include fixes for these scenarios also.

    Cheers,

    Leon

    Thread Starter shareasale-wp

    (@shareasale-wp)

    Hi Leon,

    No worries!

    My WP site is installed in a root directory, so it’s accessible from the TLD. The main testing environment is a virtual machine (WordPress docker container), but I’ve also tested it on my regular webserver with the same results so I don’t think the environment had an effect.

    Plugin Author Leon Stafford

    (@leonstafford)

    Hi there,

    Thanks for the info!

    I added the change to ABSPATH to V2.6.1 and am just publishing another small patch with V2.6.2 which reduces the filesize of the plugin (bloated with a full AWS SDK).

    Cheers,

    Leon

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Preserve custom output directory with CLI?’ is closed to new replies.