class GHMS_Install {
public static function install() {
self::create_tables();
self::seed_initial_data();
}
private static function create_tables() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$tables = [
"CREATE TABLE {$wpdb->prefix}ghms_agricultural_cycles (
id int(11) NOT NULL AUTO_INCREMENT,
sub_id int(11) DEFAULT NULL,
line_id int(11) DEFAULT NULL,
flower_type_id int(11) DEFAULT NULL,
start_date date DEFAULT NULL,
expected_date date DEFAULT NULL,
harvest_date date DEFAULT NULL,
status enum('planned','active','completed','aborted') DEFAULT 'planned',
PRIMARY KEY (id),
KEY sub_id (sub_id),
KEY line_id (line_id),
KEY flower_type_id (flower_type_id)
) $charset_collate;",
// Add all other tables from your SQL dump
];
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
foreach ($tables as $table) {
dbDelta($table);
}
}
}class GHMS_Tasks {
public function __construct() {
add_action('ghms_daily_maintenance', array($this, 'check_scheduled_tasks'));
add_action('init', array($this, 'schedule_events'));
}
public function schedule_events() {
if (!wp_next_scheduled('ghms_daily_maintenance')) {
wp_schedule_event(time(), 'daily', 'ghms_daily_maintenance');
}
}
public function check_scheduled_tasks() {
$today = current_time('Y-m-d');
$due_tasks = GHMS_Database::get_instance()->get_tasks_due_on($today);
foreach ($due_tasks as $task) {
$this->send_task_reminder($task);
}
}
private function send_task_reminder($task) {
$employee = GHMS_Database::get_instance()->get_employee($task->assigned_to);
$user = get_user_by('id', $employee->user_id);
if ($user) {
$subject = sprintf(__('Reminder: %s task due today', 'ghms'), $task->task_type);
$message = sprintf(
__('Hello %s, you have a %s task scheduled for today. Details: %s', 'ghms'),
$user->display_name,
$task->task_type,
$task->notes
);
wp_mail($user->user_email, $subject, $message);
}
}
}class GHMS_WooCommerce {
public function __construct() {
add_action('save_post_product', array($this, 'sync_product_with_ghms'), 10, 3);
add_action('woocommerce_order_status_changed', array($this, 'handle_order_status_change'), 10, 3);
}
public function sync_product_with_ghms($post_id, $post, $update) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if ($post->post_type != 'product') return;
$product = wc_get_product($post_id);
$flower_type_id = get_post_meta($post_id, '_ghms_flower_type_id', true);
if ($flower_type_id) {
// Update existing flower type
GHMS_Database::get_instance()->update_flower_type($flower_type_id, [
'name' => $product->get_name(),
'wc_product_id' => $post_id,
'wc_last_sync' => current_time('mysql')
]);
} else {
// Create new flower type
$flower_type_id = GHMS_Database::get_instance()->insert_flower_type([
'wc_product_id' => $post_id,
'name' => $product->get_name(),
'wc_last_sync' => current_time('mysql')
]);
update_post_meta($post_id, '_ghms_flower_type_id', $flower_type_id);
}
}
public function handle_order_status_change($order_id, $old_status, $new_status) {
if ($new_status == 'completed') {
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item) {
$product_id = $item->get_product_id();
$flower_type_id = get_post_meta($product_id, '_ghms_flower_type_id', true);
if ($flower_type_id) {
GHMS_Database::get_instance()->record_sale([
'flower_type_id' => $flower_type_id,
'wc_order_id' => $order_id,
'sold_quantity' => $item->get_quantity(),
'sale_date' => current_time('mysql')
]);
}
}
}
}
}
Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, class GHMS_Core does not have a method "init" in /home4/umifydmy/public_html/wp-includes/class-wp-hook.php:324
Stack trace:
#0 /home4/umifydmy/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#1 /home4/umifydmy/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#2 /home4/umifydmy/public_html/wp-settings.php(727): do_action('init')
#3 /home4/umifydmy/public_html/wp-config.php(121): require_once('/home4/umifydmy...')
#4 /home4/umifydmy/public_html/wp-load.php(50): require_once('/home4/umifydmy...')
#5 /home4/umifydmy/public_html/wp-blog-header.php(13): require_once('/home4/umifydmy...')
#6 /home4/umifydmy/public_html/index.php(17): require('/home4/umifydmy...')
#7 {main}
thrown in /home4/umifydmy/public_html/wp-includes/class-wp-hook.php on line 324