I am very new to WordPress development. I hit this error when i developering my very own class and namespace to do the life simpler to reuse my code on cross of platforms/frameworks.
I’ve added my CLI command like this
wp product:sync
And when i run my CLI command whitout my class its run because it shut, I can get entry to the internel WordPress capabilities didn’t working.
CLI_Controller.php
<?php
namespace WMSControllers;
use WMSControllersCLICLI_Products;
class CLI
{
perform init()
{
add_action('cli_init', perform () {
$product_cli = new CLI_Products();
WP_CLI::add_command('product:sync', $product_cli->execute());
WP_CLI::add_command('inventory:sync', $product_cli->hello_world());
WP_CLI::add_command('order:sync', $product_cli->hello_world());
});
}
}
Product_Controller.php
<?php
namespace WMSControllersCLI;
use WMSControllersWMSApiAPIServiceItems;
class CLI_Products
{
public perform hello_world()
{
WP_CLI::line('Howdy World!');
}
perform execute()
{
$api_items = new Gadgets();
$args = array(
'post_type' => 'product',
'posts_per_page' => 10
);
$loop = new WP_Query($args);
whereas ($loop->have_posts()) {
$loop->the_post();
international $product;
if ($product->get_sku()) {
$merchandise = [
'sku' => $product->get_sku(),
'description' => get_the_title()
];
print_r($merchandise);
} else {
echo 'Product lacking SKU quantity';
}
}
$items->import($merchandise);
wp_reset_query();
}
}
So once I run this command its giving this error
PHP Deadly error: Uncaught Error: Class
‘WMSControllersWMSApiAPIServiceItems’ not present in
/var/www/frontend/wp-content/plugins/wordpress-woocommerce-plugin/src/Controllers/CLI/Product_Controller.php:16
Stack hint:
#0 /var/www/frontend/wp-content/plugins/wordpress-woocommerce-plugin/src/Controllers/CLI_Controller.php(14):
WMSControllersCLICLI_Products->execute()
So its appear to be the principle file didn’t load success, is there a method or work a spherical to load customized class/namespaces inside my CLI instructions?