PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.6
Post Grid Gutenberg Blocks – PostX v5.0.6
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 2.1.2 All 237 releases
ultimate-post / blocks / Button.php

Button.php in Post Grid Gutenberg Blocks – PostX 5.0.6, at blocks/Button.php

42 lines 1.1 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 Button {
7 public function __construct() {
8 add_action( 'init', array( $this, 'register' ) );
9 }
10
11 public function register() {
12 register_block_type(
13 'ultimate-post/button',
14 array(
15 'render_callback' => array( $this, 'render' ),
16 )
17 );
18 }
19
20 public function render( $attr, $content ) {
21
22 if ( ultimate_post()->is_dc_active( $attr ) && isset( $attr['dc'] ) ) {
23
24 // [ $text, $url ] = \ULTP\DCService::get_dc_content_for_rich_text( $attr );
25 $dc_text_val = \ULTP\DCService::get_dc_content_for_rich_text( $attr );
26 $text = isset( $dc_text_val['0'] ) ? $dc_text_val['0'] : '';
27 $url = isset( $dc_text_val['1'] ) ? $dc_text_val['1'] : '';
28
29 // Replacing URL with dynamic content
30 if ( ! empty( $url ) ) {
31 $pattern = '/href="([^"]*)"/';
32 $replacement = 'href="' . esc_url( $url ) . '"';
33 $content = preg_replace( $pattern, $replacement, $content );
34 }
35
36 $content = \ULTP\DCService::replace( $content, wp_kses( $text, ultimate_post()->ultp_allowed_html_tags() ) );
37 }
38
39 return $content;
40 }
41 }
42