| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
class Advanced_List { |
| 7 |
public function __construct() { |
| 8 |
add_action( 'init', array( $this, 'register' ) ); |
| 9 |
} |
| 10 |
|
| 11 |
public function register() { |
| 12 |
register_block_type( |
| 13 |
'ultimate-post/list', |
| 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 |
$dc_text_val = \ULTP\DCService::get_dc_content_for_rich_text( $attr ); |
| 25 |
$text = isset( $dc_text_val['0'] ) ? $dc_text_val['0'] : ''; |
| 26 |
$url = isset( $dc_text_val['1'] ) ? $dc_text_val['1'] : ''; |
| 27 |
// [ $text, $url ] = \ULTP\DCService::get_dc_content_for_rich_text( $attr ); array destructure is not support php 7 |
| 28 |
|
| 29 |
if ( ! empty( $url ) ) { |
| 30 |
$text = '<a href="' . esc_url( $url ) . '">' . wp_kses( $text, ultimate_post()->ultp_allowed_html_tags() ) . '</a>'; |
| 31 |
} |
| 32 |
|
| 33 |
$content = \ULTP\DCService::replace( $content, $text ); |
| 34 |
} |
| 35 |
|
| 36 |
return $content; |
| 37 |
} |
| 38 |
} |
| 39 |
|