Why won’t this activate?
-
I’ve run into another anomaly with my Domain objects snippet (I finally had to give up on putting these in a namespace. They were constantly “not found.”)
I have this snippet:
/**
- SB Model API
*/
if (!defined(‘ABSPATH’)) exit;
/**
- ————————-
- Consultant Class
- */
class Consultant {
public string $id;
public string $name;
public string $email;
public string $calendly_link;
public string $tag;
public string $tagId;
public ?\DateTime $created_at;
public ?\DateTime $updated_at; protected static array $cache = []; public function __construct(
string $id,
string $name,
string $email,
string $calendly_link,
string $tag = ”,
string $tagId = ”,
?\DateTime $created_at = null,
?\DateTime $updated_at = null
) {
$this->id = $id;
$this->name = $name;
$this->email = $email;
$this->calendly_link = $calendly_link;
$this->tag = $tag;
$this->tagId = $tagId;
$this->created_at = $created_at;
$this->updated_at = $updated_at;
} public static function find(?string $id = null): ?self {
$id = $id ?: ‘sb’;
if (isset(self::$cache[$id])) return self::$cache[$id];global $wpdb; $table = $wpdb->prefix . 'sba_consultants'; $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$table} WHERE public_id = %s", $id), ARRAY_A); if (!$row) return null; $consultant = new self( $row['public_id'], $row['name'], $row['email'], $row['calendly_link'] ?? '', $row['tag'] ?? '', $row['tagId'] ?? '', new \DateTime($row['created_at']), new \DateTime($row['updated_at']) ); self::$cache[$id] = $consultant; return $consultant;} public static function find_all(): array {
global $wpdb;
$table = $wpdb->prefix . ‘sba_consultants’;
$rows = $wpdb->get_results(“SELECT * FROM {$table}”, ARRAY_A);$result = []; foreach ($rows as $row) { $consultant = new self( $row['public_id'], $row['name'], $row['email'], $row['calendly_link'] ?? '', $row['tag'] ?? '', $row['tagId'] ?? '', new \DateTime($row['created_at']), new \DateTime($row['updated_at']) ); self::$cache[$row['public_id']] = $consultant; $result[] = $consultant; } return $result;}
}
/**
- ————————-
- Client Class
- */
class Client {
public string $email;
public ?string $name;
public string $consultant_public_id;
public ?string $attribution_log; // <– JSON log for attribution events
public ?\DateTime $created_at;
public ?\DateTime $updated_at; protected static array $cache = []; public function __construct(
string $email,
?string $name,
string $consultant_public_id,
?string $attribution_log = null,
?\DateTime $created_at = null,
?\DateTime $updated_at = null
) {
$this->email = $email;
$this->name = $name;
$this->consultant_public_id = $consultant_public_id;
$this->attribution_log = $attribution_log;
$this->created_at = $created_at;
$this->updated_at = $updated_at;
} // ——————————-
// Find client by email
// ——————————-
public static function find_by_email(string $email): ?self {
if (isset(self::$cache[$email])) return self::$cache[$email];global $wpdb; $table = $wpdb->prefix . 'sba_clients'; $row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$table} WHERE email = %s", $email), ARRAY_A); if (!$row) return null; $client = new self( $row['email'], $row['name'] ?? null, $row['consultant_public_id'], $row['attribution_log'] ?? null, new \DateTime($row['created_at']), new \DateTime($row['updated_at']) ); self::$cache[$email] = $client; return $client;} // ——————————-
// Find all clients by consultant
// ——————————-
public static function find_all_by_consultant(string $consultant_public_id): array {
global $wpdb;
$table = $wpdb->prefix . ‘sba_clients’;
$rows = $wpdb->get_results($wpdb->prepare(“SELECT * FROM {$table} WHERE consultant_public_id = %s”, $consultant_public_id), ARRAY_A);$result = []; foreach ($rows as $row) { $client = new self( $row['email'], $row['name'] ?? null, $row['consultant_public_id'], $row['attribution_log'] ?? null, new \DateTime($row['created_at']), new \DateTime($row['updated_at']) ); self::$cache[$row['email']] = $client; $result[] = $client; } return $result;} // ——————————-
// Create a new client
// ——————————-
public static function create(array $data): self {
global $wpdb;
$table = $wpdb->prefix . ‘sba_clients’;$wpdb->insert($table, [ 'email' => $data['email'], 'name' => $data['name'] ?? null, 'consultant_public_id' => $data['consultant_public_id'], 'attribution_log' => $data['attribution_log'] ?? null, 'created_at' => current_time('mysql'), 'updated_at' => current_time('mysql') ]); return self::find_by_email($data['email']);} // ——————————-
// Save changes to an existing client
// ——————————-
public function save(): void {
global $wpdb;
$table = $wpdb->prefix . ‘sba_clients’;$wpdb->update( $table, [ 'name' => $this->name, 'consultant_public_id' => $this->consultant_public_id, 'attribution_log' => $this->attribution_log, 'updated_at' => current_time('mysql'), ], ['email' => $this->email] ); // Update cache self::$cache[$this->email] = $this;}
}
As long as they both have create and/or save functions, the snippet won’t activate. If I take those functions out of either class then it WILL activate.
Why won’t the snippet activate with both classes having the functions they obviously NEED?
- SB Model API
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.