PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / build / block-library / blocks / post-author-avatar / index.php
kubio / build / block-library / blocks / post-author-avatar Last commit date
block.json 4 years ago index.php 1 year ago
index.php
78 lines
1 <?php
2
3 namespace Kubio\Blocks;
4
5 use Kubio\Core\Blocks\BlockBase;
6 use Kubio\Core\LodashBasic;
7 use Kubio\Core\Registry;
8 use Kubio\Core\Utils as GeneralUtils;
9
10 class PostAuthorAvatarBlock extends BlockBase {
11
12 const OUTER = 'outer';
13 const IMAGE = 'image';
14
15 public function computed() {
16 return array();
17 }
18
19 public function mapPropsToElements() {
20 if ( ! ( $postId = LodashBasic::get( $this->block_context, 'postId' ) ) ) {
21 return null;
22 }
23
24 $authorId = get_post_field( 'post_author', $postId );
25 if ( empty( $authorId ) ) {
26 return '';
27 }
28
29 $avatarSize = $this->getAttribute( 'avatarSize' );
30
31 $defaultImg = GeneralUtils::getDefaultAssetsURL( 'avatar-image-placeholder.png' );
32 $src = get_avatar_url( $authorId, array( 'size' => $avatarSize ) );
33 $src = $src ? $src : $defaultImg;
34 $src2x = get_avatar_url( $authorId, array( 'size' => $avatarSize * 2 ) );
35 $src2x = ( $src2x ? $src2x : $defaultImg ) . ' 2x';
36
37 if ( $avatarSize > 0 ) {
38 $map[ self::IMAGE ] = array(
39 'src' => esc_url( $src ),
40 'srcset' => esc_attr( $src2x ),
41 );
42 }
43
44 return $map;
45 }
46
47 public function getLinkAttribute() {
48 if ( ! ( $postId = LodashBasic::get( $this->block_context, 'postId' ) ) ) {
49 return null;
50 }
51
52 $authorId = get_post_field( 'post_author', $postId );
53 if ( empty( $authorId ) ) {
54 return '';
55 }
56
57 return $this->getLinkAttributes( $authorId );
58 }
59
60 public function getLinkAttributes( $aAuthorId ) {
61 if ( ! $this->getAttribute( 'addLink' ) ) {
62 return array();
63 }
64
65 $authorLink = get_author_posts_url( $aAuthorId );
66 $link = array(
67 'value' => $authorLink,
68 );
69
70 return $link;
71 }
72 }
73
74 Registry::registerBlock(
75 __DIR__,
76 PostAuthorAvatarBlock::class
77 );
78