# Acorn scheduler is not loading wordpress correctly

**URL:** <https://discourse.roots.io/t/acorn-scheduler-is-not-loading-wordpress-correctly/28969>\
**Category:** acorn\
**Created:** [December 3, 2024, 3:27pm UTC](https://discourse.roots.io/t/acorn-scheduler-is-not-loading-wordpress-correctly/28969 "2024-12-03T15:27:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfr148](https://discourse.roots.io/user_avatar/discourse.roots.io/mfr148/32/5849_2.png) [@mfr148](https://discourse.roots.io/u/mfr148)\
**Post date:** [December 3, 2024, 3:27pm UTC](https://discourse.roots.io/t/acorn-scheduler-is-not-loading-wordpress-correctly/28969/1 "2024-12-03T15:27:14Z")

</div>

Hello We are stuck on this one and we need help.

> <https://github.com/roots/acorn/issues/383>
>
> \### Version
> 
> v4.2.2
> 
> \### What did you expect to happen?
> 
> I'm using Acorn in comb…inaison with Radicle.
> 
> I did register a Kernel instance : 
> 
> \`\`\`php
> \\Roots\\bootloader()-\>boot(function ($app) {
> $app-\>singleton(
> \\Illuminate\\Contracts\\Console\\Kernel::class,
> \\App\\Console\\Kernel::class
> );
> });
> \`\`\`
> 
> Which provides schedules : 
> 
> \`\`\`php
> namespace App\\Console;
> 
> use Illuminate\\Contracts\\Events\\Dispatcher;
> use Illuminate\\Contracts\\Foundation\\Application;
> use Roots\\Acorn\\Console\\Kernel as RootsKernel;
> use Illuminate\\Console\\Scheduling\\Schedule;
> 
> class Kernel extends RootsKernel
> {
> protected function schedule(Schedule $schedule)
> {
> $schedule-\>command('debug:dump')-\>everySecond();
> }
> 
> public function \_\_construct(Application $app, Dispatcher $events)
> {
> if (! defined('ARTISAN\_BINARY')) {
> define('ARTISAN\_BINARY', dirname(\_\_DIR\_\_, 2) . '/vendor/roots/acorn/bin/acorn');
> }
> 
> $this-\>app = $app;
> $this-\>events = $events;
> 
> // Make sure our schedules are getting registered
> $this-\>app-\>extend(Schedule::class, function ($app) {
> return tap(new Schedule($this-\>scheduleTimezone()), function ($schedule) {
> $this-\>schedule($schedule-\>useCache($this-\>scheduleCache()));
> });
> });
> 
> $this-\>app-\>booted(function () {
> $this-\>defineConsoleSchedule();
> });
> }
> }
> \`\`\`
> 
> 
> Schedules are working nicely, but the load of Wordpress is not complete.  
> For example, If I would want to get the permalink of a page inside my command : 
> 
> 
> \`\`\`php
> // App\\Console\\Commands\\DebugDump
> 
> public function handle()
> {
> ray(get\_permalink(2));
> }
> \`\`\`
> 
> When using WP-CLI, this works perfectly : 
> 
> \`\`\`bash
> wp acorn debug:dump 
> 
> // http://site.test/my-page-name
> \`\`\`
> 
> But in the scheduler context, I get :  
> 
> \`\`\`bash
> wp acorn schedule:test
> 
> Running \['vendor/roots/acorn/bin/acorn' debug:dump\] ................................................................................... 344ms DONE
> ⇂ '/opt/homebrew/Cellar/php@8.2/8.2.18/bin/php' 'vendor/roots/acorn/bin/acorn' debug:dump \> '/dev/null' 2\>&1
>   
> // http://site.test/?page\_id=2
> \`\`\`
> 
> \### What actually happens?
> 
> When running the scheduler with acorn, the \[acorn binary\](https://github.com/roots/acorn/blob/4.x/bin/acorn) is called. 
> 
> This binary loads wordpress and then expect acorn to boot on top : 
> 
> \`\`\`php
> require\_once "{$rootPath}/{$composer\['extra'\]\['wordpress-install-dir'\]}/wp-blog-header.php";
> 
> Roots\\Acorn\\Bootloader::getInstance()-\>boot();
> \`\`\`
> 
> The seconds line nevers gets called.  
> 
> What actually happens is that the \`wp-settings.php\` file is going to load the mu-plugins, which loads Acorn (\`00-acorn-boot.php\`), and the load of Acorn "captures" the "request", and so any code that should have run after the load of mu-plugins (inside \`wp-settings.php\`) won't run, including settings up default post\_types and so on :  
> 
> \`\`\`php
> // file: wp-settings.php
> 
> // Load must-use plugins.
> foreach ( wp\_get\_mu\_plugins() as $mu\_plugin ) {
> $\_wp\_plugin\_file = $mu\_plugin;
> include\_once $mu\_plugin; // \<-- loading acorn will stop here.
> $mu\_plugin = $\_wp\_plugin\_file;
> do\_action( 'mu\_plugin\_loaded', $mu\_plugin );
> }
> 
> /\*\* Never reach this part \*/
> 
> /\*\* ... \*/
> 
> create\_initial\_taxonomies();
> create\_initial\_post\_types();
> 
> /\*\* ... \*/
> \`\`\`
> 
> This means that if I run a command with the scheduler : 
> 
> \`\`\`bash
> wp acorn schedule:test
> Running \['vendor/roots/acorn/bin/acorn' debug:dump\] ................................................................................... 344ms DONE
> ⇂ '/opt/homebrew/Cellar/php@8.2/8.2.18/bin/php' 'vendor/roots/acorn/bin/acorn' debug:dump \> '/dev/null' 2\>&1
> \`\`\`
>   
> The \`debug:dump\` command \*\*won't be able to get a permalink\*\* (eg: \`get\_permalink(1)\`) as the internal \`get\_post\_status\_object()\` function could not return values because the core is not fully loaded.
> 
> \### Steps to reproduce
> 
> Create a Kernel class :  
> 
> \`\`\`php
> namespace App\\Console;
> 
> use Illuminate\\Contracts\\Events\\Dispatcher;
> use Illuminate\\Contracts\\Foundation\\Application;
> use Roots\\Acorn\\Console\\Kernel as RootsKernel;
> use Illuminate\\Console\\Scheduling\\Schedule;
> 
> class Kernel extends RootsKernel
> {
> protected function schedule(Schedule $schedule)
> {
> $schedule-\>command('debug:dump')-\>everySecond();
> }
> 
> public function \_\_construct(Application $app, Dispatcher $events)
> {
> if (! defined('ARTISAN\_BINARY')) {
> define('ARTISAN\_BINARY', dirname(\_\_DIR\_\_, 2) . '/vendor/roots/acorn/bin/acorn');
> }
> 
> $this-\>app = $app;
> $this-\>events = $events;
> 
> // Make sure our schedules are getting registered
> $this-\>app-\>extend(Schedule::class, function ($app) {
> return tap(new Schedule($this-\>scheduleTimezone()), function ($schedule) {
> $this-\>schedule($schedule-\>useCache($this-\>scheduleCache()));
> });
> });
> 
> $this-\>app-\>booted(function () {
> $this-\>defineConsoleSchedule();
> });
> }
> }
> \`\`\`
> 
> Make sure to register the kernel class when booting acorn : 
> 
> \`\`\`php
> \\Roots\\bootloader()-\>boot(function ($app) {
> $app-\>singleton(
> \\Illuminate\\Contracts\\Console\\Kernel::class,
> \\App\\Console\\Kernel::class
> );
> });
> \`\`\`
> 
> Then, after creating a command which tries to display a permalink, test it thru the scheduler using \`wp acorn schedule:test\`.
> 
> 
> \### System info
> 
> MacBook Air M1
> MacOS Sonoma 14.5
> PHP 8.2.18
> 
> 
> \### Log output
> 
> \_No response\_
> 
> \### Please confirm this isn't a support request.
> 
> Yes

Can anyone has the solution? We can hire someone for that ? thanks a lot
