| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPGraphQL\Model; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Avatar - Models data for avatars |
| 7 |
* |
| 8 |
* @property ?string $default |
| 9 |
* @property ?string $extraAttr |
| 10 |
* @property bool $forceDefault |
| 11 |
* @property bool $foundAvatar |
| 12 |
* @property ?int $height |
| 13 |
* @property ?string $rating |
| 14 |
* @property ?string $scheme |
| 15 |
* @property ?int $size |
| 16 |
* @property ?string $url |
| 17 |
* @property ?int $width |
| 18 |
* |
| 19 |
* @package WPGraphQL\Model |
| 20 |
* |
| 21 |
* @extends \WPGraphQL\Model\Model<array<string,mixed>> |
| 22 |
*/ |
| 23 |
class Avatar extends Model { |
| 24 |
/** |
| 25 |
* Avatar constructor. |
| 26 |
* |
| 27 |
* @param array<string,mixed> $avatar The incoming avatar to be modeled. |
| 28 |
*/ |
| 29 |
public function __construct( array $avatar ) { |
| 30 |
$this->data = $avatar; |
| 31 |
parent::__construct(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @return bool |
| 36 |
*/ |
| 37 |
protected function is_private() { |
| 38 |
$show_avatars = get_option( 'show_avatars' ); |
| 39 |
return ! (bool) $show_avatars; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* {@inheritDoc} |
| 44 |
*/ |
| 45 |
protected function init() { |
| 46 |
if ( empty( $this->fields ) ) { |
| 47 |
$this->fields = [ |
| 48 |
'default' => function () { |
| 49 |
return ! empty( $this->data['default'] ) ? $this->data['default'] : null; |
| 50 |
}, |
| 51 |
'extraAttr' => function () { |
| 52 |
return ! empty( $this->data['extra_attr'] ) ? $this->data['extra_attr'] : null; |
| 53 |
}, |
| 54 |
'forceDefault' => function () { |
| 55 |
return ! empty( $this->data['force_default'] ); |
| 56 |
}, |
| 57 |
'foundAvatar' => function () { |
| 58 |
return ! empty( $this->data['found_avatar'] ); |
| 59 |
}, |
| 60 |
'height' => function () { |
| 61 |
return ! empty( $this->data['height'] ) ? absint( $this->data['height'] ) : null; |
| 62 |
}, |
| 63 |
'rating' => function () { |
| 64 |
return ! empty( $this->data['rating'] ) ? $this->data['rating'] : null; |
| 65 |
}, |
| 66 |
'scheme' => function () { |
| 67 |
return ! empty( $this->data['scheme'] ) ? $this->data['scheme'] : null; |
| 68 |
}, |
| 69 |
'size' => function () { |
| 70 |
return ! empty( $this->data['size'] ) ? absint( $this->data['size'] ) : null; |
| 71 |
}, |
| 72 |
'url' => function () { |
| 73 |
return ! empty( $this->data['url'] ) ? $this->data['url'] : null; |
| 74 |
}, |
| 75 |
'width' => function () { |
| 76 |
return ! empty( $this->data['width'] ) ? absint( $this->data['width'] ) : null; |
| 77 |
}, |
| 78 |
]; |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|