PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
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 / acf / background-image.php

background-image.php in Getwid – Gutenberg Blocks 3.0.2, at includes/blocks/template-parts/acf/background-image.php

113 lines 3.4 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\TemplateParts\Acf;
4
5 class AcfBackgroundImage extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $assets_handle = 'getwid/template-parts/acf';
8
9 public function __construct() {
10
11 parent::__construct( 'getwid/template-acf-background-image' );
12
13 register_block_type(
14 getwid_get_plugin_path( 'assets/blocks/template-parts/acf/background-image' ),
15 array(
16 'render_callback' => array( $this, 'render_callback' ),
17 )
18 );
19 }
20
21 public function get_label() {
22 return __( 'ACF Background Image', 'getwid' );
23 }
24
25 public function can_be_disabled() {
26 return false;
27 }
28
29 public function render_callback( $attributes, $content ) {
30
31 if ( ( get_post_type() === getwid()->postTemplatePart()->postType ) || ( get_post_type() === 'revision' ) ) {
32 return $content;
33 }
34
35 $block_name = 'wp-block-getwid-template-acf-background-image';
36 $wrapper_class = $block_name;
37 $wrapper_style = '';
38
39 if ( isset( $attributes['className'] ) ) {
40 $wrapper_class .= ' ' . esc_attr( $attributes['className'] );
41 }
42
43 if ( isset( $attributes['customField'] ) ) {
44 $wrapper_class .= ' custom-field-' . esc_attr( $attributes['customField'] );
45 }
46
47 if ( isset( $attributes['minHeight'] ) ) {
48 $wrapper_style .= 'min-height: ' . esc_attr( $attributes['minHeight'] ) . ';';
49 }
50
51 $image_size = ( isset( $attributes['imageSize'] ) && $attributes['imageSize'] ) ? $attributes['imageSize'] : 'post-thumbnail';
52 $current_post = get_post( get_the_ID() );
53
54 $content_container_style = '';
55
56 if ( isset( $attributes['contentMaxWidth'] ) ) {
57 $content_container_style .= 'max-width: ' . esc_attr( $attributes['contentMaxWidth'] ) . 'px;';
58 }
59
60 $content_container_class = $block_name . '__content';
61
62 getwid_custom_paddings_style_and_class( $wrapper_style, $wrapper_class, $attributes );
63 getwid_custom_alignment_classes( $wrapper_class, $attributes );
64
65 $foreground_style = '';
66 $foreground_class = $block_name . '__foreground';
67
68 if ( isset( $attributes['foregroundGradientType'] ) ) {
69 getwid_custom_gradient_styles( 'foreground', $foreground_style, $attributes );
70 }
71
72 if ( isset( $attributes['foregroundOpacity'] ) && 35 !== $attributes['foregroundOpacity'] ) {
73 $foreground_class .= ' getwid-opacity-' . esc_attr( $attributes['foregroundOpacity'] );
74 }
75
76 if ( isset( $attributes['foregroundColor'] ) ) {
77 $foreground_style .= 'background-color: ' . esc_attr( $attributes['foregroundColor'] ) . ';';
78 }
79
80 if ( isset( $attributes['foregroundFilter'] ) ) {
81 $foreground_style .= 'mix-blend-mode: ' . esc_attr( $attributes['foregroundFilter'] ) . ';';
82 }
83
84 $result = '';
85 $extra_attr = array(
86 'block_name' => $block_name,
87 'wrapper_class' => $wrapper_class,
88 'wrapper_style' => $wrapper_style,
89 'current_post' => $current_post,
90 'imageSize' => $image_size,
91 'content_container_style' => $content_container_style,
92 'content_container_class' => $content_container_class,
93 'foreground_style' => $foreground_style,
94 'foreground_class' => $foreground_class,
95 'content' => $content,
96 );
97
98 if ( ( getwid_acf_is_active() && isset( $attributes['customField'] ) && has_post_thumbnail() ) || strlen( $content ) ) {
99 ob_start();
100
101 getwid_get_template_part( 'template-parts/acf/background-image', $attributes, false, $extra_attr );
102
103 $result = ob_get_clean();
104 }
105
106 return $result;
107 }
108 }
109
110 getwid()->blocksManager()->addBlock(
111 new AcfBackgroundImage()
112 );
113