| 1 |
<?php |
| 2 |
|
| 3 |
namespace Getwid\Blocks\TemplateParts; |
| 4 |
|
| 5 |
class PostDate 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-date' ); |
| 12 |
|
| 13 |
register_block_type( |
| 14 |
getwid_get_plugin_path( 'assets/blocks/template-parts/post-date' ), |
| 15 |
array( |
| 16 |
'render_callback' => array( $this, 'render_callback' ), |
| 17 |
) |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
public function get_label() { |
| 22 |
return __( 'Date', '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-date'; |
| 36 |
$wrapper_class = $block_name; |
| 37 |
$wrapper_style = ''; |
| 38 |
|
| 39 |
if ( isset( $attributes['className'] ) ) { |
| 40 |
$wrapper_class .= ' ' . esc_attr( $attributes['className'] ); |
| 41 |
} |
| 42 |
|
| 43 |
if ( isset( $attributes['textAlignment'] ) ) { |
| 44 |
$wrapper_style .= 'text-align: ' . esc_attr( $attributes['textAlignment'] ) . ';'; |
| 45 |
} |
| 46 |
|
| 47 |
if ( isset( $attributes['bold'] ) && $attributes['bold'] ) { |
| 48 |
$wrapper_style .= 'font-weight: bold;'; |
| 49 |
} |
| 50 |
|
| 51 |
if ( isset( $attributes['italic'] ) && $attributes['italic'] ) { |
| 52 |
$wrapper_style .= 'font-style: italic;'; |
| 53 |
} |
| 54 |
|
| 55 |
if ( isset( $attributes['customFontSize'] ) ) { |
| 56 |
$font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize']; |
| 57 |
$wrapper_style .= 'font-size: ' . esc_attr( $font_size ) . ';'; |
| 58 |
} |
| 59 |
|
| 60 |
if ( isset( $attributes['fontSize'] ) ) { |
| 61 |
$wrapper_class .= ' has-' . esc_attr( $attributes['fontSize'] ) . '-font-size'; |
| 62 |
} |
| 63 |
|
| 64 |
$archive_year = get_the_time( 'Y' ); |
| 65 |
$archive_month = get_the_time( 'm' ); |
| 66 |
$archive_day = get_the_time( 'd' ); |
| 67 |
$is_back_end = getwid_is_block_editor(); |
| 68 |
|
| 69 |
getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end ); |
| 70 |
|
| 71 |
$icon_class = ''; |
| 72 |
$icon_style = ''; |
| 73 |
|
| 74 |
getwid_custom_color_style_and_class( |
| 75 |
$icon_style, |
| 76 |
$icon_class, |
| 77 |
$attributes, |
| 78 |
'color', |
| 79 |
$is_back_end, |
| 80 |
array( |
| 81 |
'color' => 'iconColor', |
| 82 |
'custom' => 'customIconColor', |
| 83 |
) |
| 84 |
); |
| 85 |
|
| 86 |
$result = ''; |
| 87 |
$extra_attr = array( |
| 88 |
'wrapper_class' => $wrapper_class, |
| 89 |
'wrapper_style' => $wrapper_style, |
| 90 |
'archive_year' => $archive_year, |
| 91 |
'archive_month' => $archive_month, |
| 92 |
'archive_day' => $archive_day, |
| 93 |
'icon_class' => $icon_class, |
| 94 |
'icon_style' => $icon_style, |
| 95 |
); |
| 96 |
|
| 97 |
if ( get_the_date() ) { |
| 98 |
ob_start(); |
| 99 |
|
| 100 |
getwid_get_template_part( 'template-parts/post-date', $attributes, false, $extra_attr ); |
| 101 |
|
| 102 |
$result = ob_get_clean(); |
| 103 |
} |
| 104 |
|
| 105 |
return $result; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
getwid()->blocksManager()->addBlock( |
| 110 |
new PostDate() |
| 111 |
); |
| 112 |
|