| 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 |
|