PluginProbe
Getwid – Gutenberg Blocks / 2.0.7
Getwid – Gutenberg Blocks v2.0.7
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
getwid / includes / blocks / template-parts / post-featured-image.php

post-featured-image.php in Getwid – Gutenberg Blocks 2.0.7, at includes/blocks/template-parts/post-featured-image.php

112 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 class PostFeaturedImage extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-featured-image';
8 protected static $assetsHandle = 'getwid/template-parts';
9
10 public function __construct() {
11
12 parent::__construct( self::$blockName );
13
14 register_block_type(
15 self::$blockName,
16 array(
17 'attributes' => array(
18 'linkTo' => array(
19 'type' => 'string',
20 'default' => 'none'
21 ),
22 'align' => array(
23 'type' => 'string'
24 ),
25 'imageSize' => array(
26 'type' => 'string',
27 'default' => 'large'
28 ),
29
30 'className' => array(
31 'type' => 'string'
32 ),
33 ),
34 'render_callback' => [ $this, 'render_callback' ]
35 )
36 );
37 }
38
39 public function block_frontend_assets() {
40
41 if ( is_admin() ) {
42 return;
43 }
44
45 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
46 return;
47 }
48
49 add_filter( 'getwid/optimize/assets',
50 function ( $assets ) {
51 $assets[] = self::$assetsHandle;
52
53 return $assets;
54 }
55 );
56
57 $rtl = is_rtl() ? '.rtl' : '';
58
59 wp_enqueue_style(
60 self::$assetsHandle,
61 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
62 [],
63 getwid()->settings()->getVersion()
64 );
65 }
66
67 public function render_callback( $attributes, $content ) {
68
69 //Not BackEnd render if we view from template page
70 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
71 return $content;
72 }
73
74 $block_name = 'wp-block-getwid-template-post-featured-image';
75 $wrapper_class = $block_name;
76
77 if ( isset( $attributes[ 'className' ] ) ) {
78 $wrapper_class .= ' ' . esc_attr( $attributes[ 'className' ] );
79 }
80
81 $wrapper_style = '';
82 //Classes
83 if ( isset( $attributes[ 'align' ] ) ) {
84 $wrapper_class .= ' align' . esc_attr( $attributes[ 'align' ] );
85 }
86
87 $imageSize = ( ( isset( $attributes[ 'imageSize' ] ) && $attributes[ 'imageSize' ] ) ? $attributes[ 'imageSize' ] : 'post-thumbnail' );
88
89 $result = '';
90
91 $extra_attr = array(
92 'wrapper_class' => $wrapper_class,
93 'wrapper_style' => $wrapper_style,
94 'imageSize' => $imageSize
95 );
96
97 if ( has_post_thumbnail() ) {
98 ob_start();
99
100 getwid_get_template_part( 'template-parts/post-featured-image', $attributes, false, $extra_attr );
101
102 $result = ob_get_clean();
103 }
104
105 $this->block_frontend_assets();
106
107 return $result;
108 }
109 }
110
111 new \Getwid\Blocks\PostFeaturedImage();
112