themosis / framework

The Themosis framework core.

Home Page:https://framework.themosis.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access wordpress on Console

ancient-spirit opened this issue · comments

Hi @jlambe ,

I think we can make a console that load wordpress if we explicit inherit the class.
The example below is perfect combined with the console stub generator by @tipytechnique on the PR with small adjustment

The parent class that load wordpress:

<?php

namespace Themosis\Core\Console;

use Illuminate\Console\Command;

class WordPress extends Command
{
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        require_once web_path('cms/wp-load.php');
    }
}

And our custom command:

<?php

namespace App\Console\Commands\WordPress;

use Themosis\Core\Console\WordPress;

class PullProduct extends WordPress
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $signature = 'wordpress:pull-product';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'pull published product from erp';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        dd(get_users());
        return 0;
    }
}

Originally posted by @oxyrealm-dev in #706 (comment)