PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.34
Post Grid Gutenberg Blocks – PostX v5.0.34
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 / addons / builder / blocks / Post_Date_Meta.php

Post_Date_Meta.php in Post Grid Gutenberg Blocks – PostX 5.0.34, at addons/builder/blocks/Post_Date_Meta.php

110 lines 3.7 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 Post_Date_Meta {
7 public function __construct() {
8 add_action( 'init', array( $this, 'register' ) );
9 }
10 public function get_attributes() {
11
12 return array(
13 'blockId' => '',
14
15 /*
16 ============================
17 Post Date Meta Setting
18 ============================*/
19 'prefixEnable' => false,
20 'metaDateIconShow' => true,
21 'dateFormat' => 'updated',
22 'metaDateFormat' => 'M j, Y',
23
24 /*
25 ============================
26 Post Date Meta Label
27 ============================*/
28 'datePubLabel' => 'Publish Date',
29 'dateUpLabel' => 'Updated Date',
30
31 /*
32 ============================
33 Post Date Meta icon style
34 ============================*/
35 'metaDateIconStyle' => 'date1',
36
37 // --------------------------
38 // Advanced Settings
39 // --------------------------
40 'advanceId' => '',
41 'advanceZindex' => '',
42 'hideExtraLarge' => false,
43 'hideDesktop' => false,
44 'hideTablet' => false,
45 'hideMobile' => false,
46 'advanceCss' => '',
47 );
48 }
49
50 public function register() {
51 register_block_type(
52 'ultimate-post/post-date-meta',
53 array(
54 'editor_script' => 'ultp-blocks-editor-script',
55 'editor_style' => 'ultp-blocks-editor-css',
56 'render_callback' => array( $this, 'content' ),
57 )
58 );
59 }
60
61 public function content( $attr, $noAjax ) {
62 $attr = wp_parse_args( $attr, $this->get_attributes() );
63 $block_name = 'post-date-meta';
64
65 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
66 $attr['align'] = isset( $attr['align'] ) && $attr['align'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['align'] ) : '';
67 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
68 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
69 $allowed_html_tags = ultimate_post()->ultp_allowed_html_tags();
70 $attr['datePubLabel'] = wp_kses( $attr['datePubLabel'], $allowed_html_tags );
71 $attr['dateUpLabel'] = wp_kses( $attr['dateUpLabel'], $allowed_html_tags );
72
73 $wrapper_before = $wrapper_after = $content = '';
74
75 $wrapper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class=" wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . ( $attr['className'] ? ' ' . $attr['className'] : '' ) . '' . ( $attr['align'] ? ' align' . $attr['align'] : '' ) . '">';
76 $wrapper_before .= '<div class="ultp-block-wrapper">';
77 $content .= '<div class="ultp-date-meta">';
78 if ( $attr['prefixEnable'] ) {
79 $content .= '<span class="ultp-date-meta-prefix">';
80 if ( $attr['dateFormat'] == 'publish' ) {
81 $content .= $attr['datePubLabel'];
82 } else {
83 $content .= $attr['dateUpLabel'];
84 }
85
86 $content .= '</span>';
87 }
88 if ( $attr['metaDateIconShow'] && $attr['metaDateIconStyle'] ) {
89 $content .= '<span class="ultp-date-meta-icon">';
90 $content .= ultimate_post()->get_svg_icon( $attr['metaDateIconStyle'] );
91 $content .= '</span>';
92 }
93 if ( $attr['metaDateFormat'] ) {
94 $content .= '<span class="ultp-date-meta-format">';
95 if ( $attr['dateFormat'] == 'updated' ) {
96 $content .= get_the_modified_date( ultimate_post()->get_format( $attr['metaDateFormat'] ) );
97 } else {
98 $content .= get_the_date( ultimate_post()->get_format( $attr['metaDateFormat'] ) );
99 }
100
101 $content .= '</span>';
102 }
103 $content .= '</div>';
104 $wrapper_after .= '</div>';
105 $wrapper_after .= '</div>';
106
107 return $wrapper_before . $content . $wrapper_after;
108 }
109 }
110