PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.41
Post Grid Gutenberg Blocks – PostX v5.0.41
5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 All 238 releases
ultimate-post / addons / builder / blocks / Post_Featured_Image.php

Post_Featured_Image.php in Post Grid Gutenberg Blocks – PostX 5.0.41, at addons/builder/blocks/Post_Featured_Image.php

104 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Post_Featured_Image {
7 public function __construct() {
8 add_action( 'init', array( $this, 'register' ) );
9 }
10 public function get_attributes() {
11
12 return array(
13 'blockId' => '',
14 /*
15 ============================
16 Post Featured Image Setting
17 ============================*/
18 'defImgShow' => false,
19 'altText' => 'Image',
20 'imgCrop' => 'full',
21 'imgSrcset' => false,
22
23 /*
24 ============================
25 Dynamic Caption
26 ============================*/
27 'enableCaption' => false,
28
29 /*
30 ============================
31 Video Settings
32 ============================*/
33 'enableVideoCaption' => false,
34 'videoWidth' => (object) array( 'lg' => '100' ),
35 'stickyEnable' => false,
36
37 /*
38 ============================
39 Advanced Settings
40 ============================*/
41 'advanceId' => '',
42 'advanceZindex' => '',
43 'hideExtraLarge' => false,
44 'hideDesktop' => false,
45 'hideTablet' => false,
46 'hideMobile' => false,
47 'advanceCss' => '',
48 );
49 }
50
51 public function register() {
52 register_block_type(
53 'ultimate-post/post-featured-image',
54 array(
55 'editor_script' => 'ultp-blocks-editor-script',
56 'editor_style' => 'ultp-blocks-editor-css',
57 'render_callback' => array( $this, 'content' ),
58 )
59 );
60 }
61
62 public function content( $attr, $noAjax ) {
63 $attr = wp_parse_args( $attr, $this->get_attributes() );
64 $block_name = 'post-image';
65 $wrapper_before = $wrapper_after = $content = '';
66
67 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
68 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
69 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
70 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
71 $attr['altText'] = wp_kses( $attr['altText'], ultimate_post()->ultp_allowed_html_tags() );
72
73 $post_video = get_post_meta( get_the_ID(), '__builder_feature_video', true );
74 $caption = get_post_meta( get_the_ID(), '__builder_feature_caption', true );
75
76 $embeded = $post_video ? ultimate_post()->get_embeded_video( $post_video, false, true, false, true, true, false, true, array( 'width' => array( 'width' => $attr['videoWidth'] ) ), 'from-block' ) : '';
77 $post_thumb_id = get_post_thumbnail_id( get_the_ID() );
78 $img_content = ultimate_post()->get_image( $post_thumb_id, $attr['imgCrop'], '', $attr['altText'], $attr['imgSrcset'] );
79 $img_caption = wp_get_attachment_caption( $post_thumb_id );
80
81 if ( $embeded || has_post_thumbnail() ) {
82 $isvideo = $embeded ? ( isset( $attr['defImgShow'] ) && $attr['defImgShow'] && $post_thumb_id ? false : true ) : false;
83 $wrapper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '">';
84 $wrapper_before .= '<div class="ultp-block-wrapper">';
85 $wrapper_before .= '<div class="ultp-image-wrapper">';
86 $wrapper_before .= '<div class="ultp-builder-' . ( $isvideo ? 'video' : 'image' ) . '">';
87 $content .= '<div class="ultp-' . ( $isvideo ? 'video' : 'image' ) . '-block' . ( $attr['stickyEnable'] ? ' ultp-sticky-video' : '' ) . '">';
88 $content .= $isvideo ? $embeded : $img_content;
89 $wrapper_after .= '<span class="ultp-sticky-close"></span></div>';
90 $wrapper_after .= '</div>';
91 $wrapper_after .= '</div>';
92
93 if ( $attr['enableCaption'] && $img_caption || $caption && $attr['enableVideoCaption'] ) {
94 $wrapper_after .= '<div class="ultp-featureImg-caption">';
95 $wrapper_after .= $isvideo ? $caption : $img_caption;
96 $wrapper_after .= '</div>';
97 }
98 $wrapper_after .= '</div>';
99 $wrapper_after .= '</div>';
100 }
101 return $wrapper_before . $content . $wrapper_after;
102 }
103 }
104