| 1 |
<?php |
| 2 |
|
| 3 |
namespace Getwid\Blocks\TemplateParts; |
| 4 |
|
| 5 |
class PostButton extends \Getwid\Blocks\AbstractBlock { |
| 6 |
|
| 7 |
protected static $assets_handle = 'getwid/template-parts'; |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
|
| 11 |
parent::__construct( 'getwid/template-post-button' ); |
| 12 |
|
| 13 |
register_block_type( |
| 14 |
getwid_get_plugin_path( 'assets/blocks/template-parts/post-button' ), |
| 15 |
array( |
| 16 |
'render_callback' => array( $this, 'render_callback' ), |
| 17 |
) |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
public function get_label() { |
| 22 |
return __( 'Button', '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-post-button'; |
| 36 |
$wrapper_class = $block_name; |
| 37 |
$wrapper_class .= ' wp-block-button'; |
| 38 |
$wrapper_style = ''; |
| 39 |
|
| 40 |
if ( isset( $attributes['className'] ) ) { |
| 41 |
$wrapper_class .= ' ' . esc_attr( $attributes['className'] ); |
| 42 |
} |
| 43 |
|
| 44 |
if ( isset( $attributes['textAlignment'] ) ) { |
| 45 |
$wrapper_style .= 'text-align: ' . esc_attr( $attributes['textAlignment'] ) . ';'; |
| 46 |
} |
| 47 |
|
| 48 |
$is_back_end = getwid_is_block_editor(); |
| 49 |
$link_style = ''; |
| 50 |
$link_class = 'wp-block-button__link'; |
| 51 |
|
| 52 |
getwid_custom_color_style_and_class( $link_style, $link_class, $attributes, 'background', $is_back_end ); |
| 53 |
getwid_custom_color_style_and_class( $link_style, $link_class, $attributes, 'color', $is_back_end ); |
| 54 |
|
| 55 |
$extra_attr = array( |
| 56 |
'wrapper_class' => $wrapper_class, |
| 57 |
'wrapper_style' => $wrapper_style, |
| 58 |
'link_class' => $link_class, |
| 59 |
'link_style' => $link_style, |
| 60 |
); |
| 61 |
|
| 62 |
ob_start(); |
| 63 |
|
| 64 |
getwid_get_template_part( 'template-parts/post-button', $attributes, false, $extra_attr ); |
| 65 |
|
| 66 |
$result = ob_get_clean(); |
| 67 |
|
| 68 |
return $result; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
getwid()->blocksManager()->addBlock( |
| 73 |
new PostButton() |
| 74 |
); |
| 75 |
|