# woo-mailerlite/3.1.17/includes/models/WooMailerLiteModel.php

MailerLite – WooCommerce integration, version 3.1.17. 160 lines.

- Page: https://pluginprobe.com/plugins/woo-mailerlite/3.1.17/code/includes/models/WooMailerLiteModel.php
- Raw: https://pluginprobe.com/plugins/woo-mailerlite/3.1.17/raw/includes/models/WooMailerLiteModel.php
- Modified: 2025-10-13T11:05:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woo-mailerlite/3.1.17/code/includes/models/WooMailerLiteModel.php#L10-L20`.

```php
<?php

class WooMailerLiteModel
{
	public array $meta = [
		'_woo_ml_product_tracked' => 'tracked',
		'_woo_ml_product_ignored' => 'ignored',
		'_woo_ml_category_tracked' => 'tracked'
	];
	public $attributes;

	protected $table;

	protected array $updateAttributes = [];

	protected $casts = [];

	protected $format;

	protected $removeEmpty = [];

	protected $isResource = false;

	public static $customTablesEnabled;

	public function __construct($attributes = [])
	{
		$this->attributes = $attributes;
	}

	public function __get($attribute)
	{
		if (in_array($attribute, $this->casts)) {

			if (!empty($this->format[$attribute])) {
				switch ($this->format[$attribute]) {
					case 'array':
						if (!is_array($this->attributes[$attribute])) {
							return json_decode($this->attributes[$attribute], true);
						}
						break;
					case 'object':
						return json_decode($this->attributes[$attribute]);
					case 'boolean':
						return (bool)$this->attributes[$attribute];
					case 'string':
						return (string)$this->attributes[$attribute];
					default:
						return $this->attributes[$attribute];
				}
			}
			return $this->attributes[$attribute];
		} elseif (isset($this->attributes[$attribute])) {
			return $this->attributes[$attribute];
		}
		return null;
	}

	public function __set($attribute, $value)
	{
		if (static::class === 'WooMailerLiteCategory') {
			unset($this->meta['_woo_ml_product_tracked']);
		}
		if (in_array($attribute, array_values($this->meta))) {
			$this->attributes[$attribute] = $value;
			$this->updateAttributes[] = $attribute;

		} else {
			$this->attributes[$attribute] = $value;
		}
	}

	public function __isset($attribute)
	{
		return isset($this->attributes[$attribute]);
	}

	public function __call($method, $parameters)
	{
		return $this->queryBuilder()->$method(...$parameters);
	}

	public static function __callStatic($name, $arguments)
	{
		return (new static([]))->$name(...$arguments);
	}

	public function save()
	{
		foreach ($this->updateAttributes as $updateAttribute) {
			if (static::class === 'WooMailerLiteCategory') {
				update_term_meta($this->resource_id, array_search($updateAttribute, $this->meta), $this->attributes[$updateAttribute]);
			} else {
				if ($updateAttribute === 'ignored') {
					$ignoredProducts = WooMailerLiteOptions::get('ignored_products', []);
					if (!$this->attributes[$updateAttribute]) {
						unset($ignoredProducts[$this->resource_id]);
					} else {
						$ignoredProducts[$this->resource_id] = $this->name;
					}
					WooMailerLiteOptions::update('ignored_products', $ignoredProducts);
				}
				update_post_meta($this->resource_id, array_search($updateAttribute, $this->meta), $this->attributes[$updateAttribute]);

			}
		}
	}

	public function exists()
	{
		return count($this->attributes) > 0;
	}

	public function setRelation($relation, $value)
	{
		$this->attributes[$relation] = $value;
		return $this;
	}

	public function queryBuilder()
	{
		return new WooMailerLiteQueryBuilder($this);
	}

	public function getTable()
	{
		return $this->table;
	}

	public function isResource()
	{
		return $this->isResource;
	}

	public function getCastsArray()
	{
		return $this->casts;
	}

	public function getFormatArray()
	{
		return $this->format;
	}

	public function getRemoveEmptyArray()
	{
		return $this->removeEmpty;
	}

	public function setResource()
	{
		$this->isResource = true;
	}

    public function setTable($table)
    {
        $this->table = $table;
    }
}

```
