true, 'data' => $data]); if ($status) { http_response_code($status); } exit; } } if (!function_exists('wp_send_json_error')) { function wp_send_json_error($data = null, $status = null) { echo json_encode(['success' => false, 'data' => $data]); if ($status) { http_response_code($status); } exit; } } if (!function_exists('current_time')) { function current_time($type) { return time(); } } if (!function_exists('wp_cache_get')) { function wp_cache_get($key, $group = '') { static $cache = []; return $cache[$group][$key] ?? false; } } if (!function_exists('wp_cache_set')) { function wp_cache_set($key, $data, $group = '', $expire = 0) { static $cache = []; $cache[$group][$key] = $data; return true; } } if (!function_exists('wp_cache_delete')) { function wp_cache_delete($key, $group = '') { static $cache = []; unset($cache[$group][$key]); return true; } } if (!function_exists('did_action')) { function did_action($hook) { return 0; } } if (!function_exists('add_action')) { function add_action($hook, $callback, $priority = 10, $accepted_args = 1) { return true; } } if (!function_exists('add_filter')) { function add_filter($hook, $callback, $priority = 10, $accepted_args = 1) { return true; } } if (!function_exists('apply_filters')) { function apply_filters($tag, $value) { return $value; } } if (!function_exists('doing_action')) { function doing_action($hook) { return false; } } if (!function_exists('wp_die')) { function wp_die($message = '', $title = '', $args = []) { echo $message; exit(1); } } if (!function_exists('error_log')) { function error_log($message) { fwrite(STDERR, $message . PHP_EOL); } } if (!function_exists('wpautop')) { function wpautop($text) { return $text; } } if (!function_exists('get_user_by')) { function get_user_by($field, $value) { return null; } } if (!function_exists('get_current_user_id')) { function get_current_user_id() { return 1; } } if (!function_exists('current_user_can')) { function current_user_can($capability, ...$args) { return true; } } if (!function_exists('is_user_logged_in')) { function is_user_logged_in() { return true; } } if (!function_exists('get_post')) { function get_post($post) { return null; } } if (!function_exists('get_post_type')) { function get_post_type($post = null) { return 'post'; } } if (!function_exists('get_the_title')) { function get_the_title($post = 0) { return 'Test Post'; } } if (!function_exists('get_post_status')) { function get_post_status($post = null) { return 'publish'; } } if (!function_exists('wp_kses_post')) { function wp_kses_post($string) { return $string; } } if (!function_exists('mb_substr')) { function mb_substr($str, $start, $length = null) { if ($length === null) { return substr($str, $start); } return substr($str, $start, $length); } } // WP_Error stub class. class WP_Error { public $errors = []; public $error_data = []; public function __construct($code = '', $message = '', $data = '') { if (!empty($code)) { $this->errors[$code] = [$message]; $this->error_data[$code] = $data; } } public function get_error_code() { $codes = $this->get_error_codes(); return $codes[0] ?? ''; } public function get_error_message($code = '') { if (empty($code)) { $code = $this->get_error_code(); } return $this->errors[$code][0] ?? ''; } public function get_error_codes() { return array_keys($this->errors); } public function get_error_data($code = '') { if (empty($code)) { $code = $this->get_error_code(); } return $this->error_data[$code] ?? ''; } public function add($code, $message, $data = '') { $this->errors[$code][] = $message; if (!empty($data)) { $this->error_data[$code] = $data; } } } // WP_Post stub class. class WP_Post { public $ID = 0; public $post_author = 1; public $post_title = ''; public $post_content = ''; public $post_status = 'publish'; public $post_type = 'post'; } // Load the plugin files we want to test. require_once WPAW_PLUGIN_DIR . 'includes/class-model-registry.php';