*/ class Comment extends Model { use Rememberable; public $timestamps = false; protected $table = DB_PREFIX . 'comments'; protected $primaryKey = 'comment_ID'; protected $dates = ['comment_date', 'comment_date_gmt']; /** * Length of time to cache this model for. * * @var int */ protected $rememberFor; /** * Create a new Eloquent model instance. * * @param array $attributes * * @return void */ public function __construct(array $attributes = []) { parent::__construct($attributes); // Set the current table to the site's own table if we're in a multisite if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) { $this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_comments'); } // enable caching if the user has opted for it in their configuration if (config('wordpress.caching')) { $this->rememberFor = config('wordpress.caching'); } else { unset($this->rememberFor); } } /** * Get all the comments that belong to this comment. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function children() { return $this->hasMany(self::class, 'comment_parent'); } /** * Get the post that this comment belongs to. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function post() { return $this->belongsTo(Post::class, 'comment_post_ID'); } /** * Comment filtered through the "comment_text" filters. * * @return string */ public function getContentAttribute() { return Action::filter('comment_text', $this->comment_content); } /** * Get the user that posted this comment. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function user() { return $this->belongsTo(User::class); } /** * Get an avatar for the comment. * * @param array $args args to pass to {@link get_avatar_url} * * @return false|string */ public function avatar($args = []) { return get_avatar_url($this->toWordpressComment(), $args); } /** * Get the {@link WP_Comment} instance for this Comment. * * @deprecated Use the methods already provided by this model. * * @return WP_Comment */ public function toWordpressComment() { return new WP_Comment((object) $this->toArray()); } /** * Get the comment this comment belongs to. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function parent() { return $this->belongsTo(self::class, 'comment_parent'); } }