elementor / lokl

Instant WordPress local development for Mac, Win & Linux
https://lokl.dev
70 stars 10 forks source link

Provisioning script's default homepage doesn't play nice with some WP-CLI commands #39

Open leonstafford opened 3 years ago

leonstafford commented 3 years ago

I use this to set the default homepage on a new Lokl site:

  wp post update 1 --post_title="Getting started with Lokl"                     
  wp post update 1 --post_content="Use this site as your starting point or import content from an existing site. <a href='/wp-admin'>View Dashboard</a>"
  wp option update page_on_front 1                                              
  wp option update show_on_front "page" 

This works as I intended, but doesn't look like a valid WP config, as post ID 1 is a Post, not a Page.

When going to Settings > Reading, we can see the radio for A static page vs Your latest posts, but neither of the dropdown options are selected.

When running wp profile stage, the following errors are seen:

Warning: Some code is trying to do a URL redirect. Backtrace:

0 WP_CLI\Utils\wp_redirect_handler(http://localhost:4967/hello-world/) called at [/usr/html/wp-includes/class-wp-hook.php:294]

1 WP_Hook->apply_filters(http://localhost:4967/hello-world/, Array ([0] => http://localhost:4967/hello-world/,[1] => 301)) called at [/usr/html/wp-includes/plugin.php:212]

2 apply_filters(wp_redirect, http://localhost:4967/hello-world/, 301) called at [/usr/html/wp-includes/pluggable.php:1290]

3 wp_redirect(http://localhost:4967/hello-world/, 301) called at [/usr/html/wp-includes/canonical.php:799]

4 redirect_canonical(http://localhost:4967/) called at [/usr/html/wp-includes/class-wp-hook.php:292]

5 WP_Hook->apply_filters(, Array ([0] => )) called at [/usr/html/wp-includes/class-wp-hook.php:316]

6 WP_Hook->do_action(Array ([0] => )) called at [/usr/html/wp-includes/plugin.php:484]

7 do_action(template_redirect) called at [/usr/html/wp-includes/template-loader.php:13]

8 require_once(/usr/html/wp-includes/template-loader.php) called at [/root/.wp-cli/packages/vendor/wp-cli/profile-command/src/Profiler.php:474]

9 WP_CLI\Profile\Profiler->load_wordpress_with_template() called at [/root/.wp-cli/packages/vendor/wp-cli/profile-command/src/Profiler.php:126]

10 WP_CLI\Profile\Profiler->run() called at [/root/.wp-cli/packages/vendor/wp-cli/profile-command/src/Command.php:110]

11 WP_CLI\Profile\Command->stage(Array (), Array ([format] => table,[order] => ASC))

12 call_user_func(Array ([0] => WP_CLI\Profile\Command Object (),[1] => stage), Array (), Array ([format] => table,[order] => ASC)) called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php:100]

13 WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher{closure}(Array (), Array ([format] => table,[order] => ASC))

14 call_user_func(Closure Object (), Array (), Array ([format] => table,[order] => ASC)) called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php:491]

15 WP_CLI\Dispatcher\Subcommand->invoke(Array (), Array ([format] => table,[order] => ASC), Array ()) called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:399]

16 WP_CLI\Runner->run_command(Array ([0] => profile,[1] => stage), Array ()) called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:422]

17 WP_CLI\Runner->run_command_and_exit() called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:107]

18 WP_CLI\Runner->do_early_invoke(before_wp_load) called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php:1136]

19 WP_CLI\Runner->start() called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php:23]

20 WP_CLI\Bootstrap\LaunchRunner->process(WP_CLI\Bootstrap\BootstrapState Object ([WP_CLI\Bootstrap\BootstrapStatestate] => Array ())) called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php:77]

21 WP_CLI\bootstrap() called at [phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php:27]

22 include(phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php) called at [phar:///usr/bin/wp/php/boot-phar.php:11]

23 include(phar:///usr/bin/wp/php/boot-phar.php) called at [/usr/bin/wp:4]

Common WP-CLI don't seem to be affected yet, but this is a bug in Lokl's default site example that should be fixed.

leonstafford commented 3 years ago

quick workaround is to set wp option update page_on_front 2, which sets it to a Page vs a Post

consider reporting issue to WP-CLI in that it should warn / error if setting homepage to invalid post ID