| 1 |
<?php |
| 2 |
namespace ABlocks\Frontend\DynamicContent\Interpreters; |
| 3 |
|
| 4 |
use ABlocks\Helper; |
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
class Image extends Abstracts\Interpreter { |
| 9 |
protected string $field; |
| 10 |
|
| 11 |
public function __construct( string $name, array $setting, bool $is_richtext = false ) { |
| 12 |
parent::__construct( $name, $setting, $is_richtext ); |
| 13 |
$this->field = strval( $this->setting[0] ?? '' ); |
| 14 |
} |
| 15 |
public function content() : string { |
| 16 |
|
| 17 |
switch ( $this->field ) { |
| 18 |
case 'featured-image': |
| 19 |
$this->content = get_the_post_thumbnail_url( get_the_ID(), 'full' ); |
| 20 |
break; |
| 21 |
|
| 22 |
case 'site-logo': |
| 23 |
$this->content = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ), 'full' )[0] ?? ''; |
| 24 |
break; |
| 25 |
|
| 26 |
case 'author-profile-picture': |
| 27 |
$author_id = get_post_field( 'post_author', get_the_ID() ); |
| 28 |
$this->content = get_avatar_url( $author_id ); |
| 29 |
break; |
| 30 |
|
| 31 |
case 'user-profile-picture': |
| 32 |
$this->content = is_user_logged_in() ? get_avatar_url( get_current_user_id() ) : ''; |
| 33 |
break; |
| 34 |
} |
| 35 |
return $this->content; |
| 36 |
} |
| 37 |
} |
| 38 |
|