__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
namespace EssentialBlocks\Blocks;
use EssentialBlocks\Utils\Helper;
use EssentialBlocks\Core\Block;
class PostMeta extends Block
{
protected $frontend_styles = [ 'essential-blocks-fontawesome' ];
/**
* Default attributes
*
* @var array
*/
protected $default_attributes;
public function __construct()
{
$this->default_attributes = [
'metaDisplay' => 'inline',
'showAuthor' => true,
'authorLabel' => __( 'Author: ', 'essential-blocks' ),
'showDate' => true,
'dateLabel' => __( "Published Date: ", 'essential-blocks' ),
'showProductSku' => true,
'productSkuLabel' => __( "SKU: ", 'essential-blocks' ),
'type' => 'post',
'enableContents' => [ "author", "date", "product_sku" ],
'showMetaIcon' => true,
'authorIcon' => 'far fa-circle-user',
'dateIcon' => 'far fa-calendar-days',
'skuIcon' => 'fas fa-barcode',
'showAuthorPicture' => false,
'authorPictureLink' => true,
'authorPictureBorderRadius' => 50
];
}
/**
* Unique name of the block.
* @return string
*/
public function get_name()
{
return 'post-meta';
}
/**
* Check if we're in a Loop Builder context
*
* @param array $context
* @return bool
*/
private function is_in_loop_builder_context( $context )
{
return isset( $context[ 'essential-blocks/isLoopBuilder' ] ) &&
$context[ 'essential-blocks/isLoopBuilder' ] === true;
}
/**
* Get post data based on context (Loop Builder or normal)
*
* @param array $context
* @param bool $is_in_loop_builder
* @return array
*/
private function get_post_data( $context, $is_in_loop_builder )
{
if ( $is_in_loop_builder ) {
// In Loop Builder context - use context post data
$post_id = isset( $context[ 'essential-blocks/postId' ] ) ?
$context[ 'essential-blocks/postId' ] :
( isset( $context[ 'postId' ] ) ? $context[ 'postId' ] : get_the_ID() );
$post_type = isset( $context[ 'essential-blocks/postType' ] ) ?
$context[ 'essential-blocks/postType' ] :
( isset( $context[ 'postType' ] ) ? $context[ 'postType' ] : get_post_type() );
// Ensure we have a valid post ID before trying to get the post
$current_post = ( $post_id && $post_id > 0 ) ? get_post( $post_id ) : null;
} else {
// Normal context - use current queried object
$current_post = get_queried_object();
// Fallback to global $post if queried object is not a post
if ( ! $current_post || ! isset( $current_post->ID ) ) {
global $post;
$current_post = $post;
}
$post_id = $current_post ? $current_post->ID : get_the_ID();
$post_type = $current_post ? $current_post->post_type : get_post_type();
}
return [
'post' => $current_post,
'post_id' => $post_id,
'post_type' => $post_type
];
}
/**
* Block render callback.
*
* Handles both normal post meta display and Loop Builder context.
* When in Loop Builder context, uses the post data from the loop iteration
* instead of the current queried object.
*
* @param mixed $attributes Block attributes
* @param mixed $content Block content (unused but required by WP)
* @param mixed $block Block object containing context
* @return mixed Rendered HTML
*/
public function render_callback( $attributes, $content, $block = null )
{
if ( is_admin() ) {
return;
}
$attributes = wp_parse_args( $attributes, $this->default_attributes );
$className = isset( $attributes[ "className" ] ) ? $attributes[ "className" ] : "";
$classHook = isset( $attributes[ 'classHook' ] ) ? $attributes[ 'classHook' ] : '';
// Check if we're in a Loop Builder context
$context = isset( $block->context ) ? $block->context : [ ];
$is_in_loop_builder = $this->is_in_loop_builder_context( $context );
// Get the appropriate post data based on context
$post_data = $this->get_post_data( $context, $is_in_loop_builder );
// Extract post data
$current_post = $post_data[ 'post' ];
$post_id = $post_data[ 'post_id' ];
$post_type = $post_data[ 'post_type' ];
// Check if we have a valid post object
if ( ! $current_post || ! isset( $current_post->post_author ) ) {
// Return empty data if no valid post is available
return '';
}
// Get author name
$author_name = get_the_author_meta( 'display_name', $current_post->post_author );
// Get author avatar URL
$author_avatar_url = get_avatar_url( $current_post->post_author, array( 'size' => 96 ) );
// Get author URL
$author_url = get_author_posts_url( $current_post->post_author );
// Get published date with WordPress date format
$date_format = get_option( 'date_format' );
$publish_date = isset( $current_post->post_date ) ? date( $date_format, strtotime( $current_post->post_date ) ) : '';
// Get product SKU if applicable
$product_sku = '';
if ( $post_type === 'product' && function_exists( 'wc_get_product' ) ) {
$product = wc_get_product( $post_id );
if ( $product ) {
$product_sku = $product->get_sku();
}
}
$author_icon = sprintf(
'%1$s',
Helper::eb_render_icon( Helper::eb_get_icon_type( $attributes[ 'authorIcon' ] ), 'eb-post-metadata-icon', $attributes[ 'authorIcon' ] )
);
$date_icon = sprintf(
'%1$s',
Helper::eb_render_icon( Helper::eb_get_icon_type( $attributes[ 'dateIcon' ] ), 'eb-post-metadata-icon', $attributes[ 'dateIcon' ] )
);
$sku_icon = sprintf(
'%1$s',
Helper::eb_render_icon( Helper::eb_get_icon_type( $attributes[ 'skuIcon' ] ), 'eb-post-metadata-icon', $attributes[ 'skuIcon' ] )
);
$data = [
'author' => $author_name,
'author_avatar_url' => $author_avatar_url,
'author_url' => $author_url,
'date' => $publish_date,
'product_sku' => $product_sku,
'show_meta_icon' => $attributes[ 'showMetaIcon' ],
'author_icon' => $author_icon,
'date_icon' => $date_icon,
'sku_icon' => $sku_icon,
'is_in_loop_builder' => $is_in_loop_builder,
'post_id' => $post_id,
'post_type' => $post_type
];
ob_start();
Helper::views( 'post-meta', array_merge( $attributes, [
'className' => $className,
'classHook' => $classHook,
'meta_data' => $data,
'block_object' => $this
] ) );
return ob_get_clean();
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Accordion.php | File | 1.03 KB | 0640 |
|
| AccordionItem.php | File | 335 B | 0640 |
|
| AddToCart.php | File | 3.43 KB | 0640 |
|
| AdvancedHeading.php | File | 5.73 KB | 0640 |
|
| AdvancedImage.php | File | 2.77 KB | 0640 |
|
| AdvancedNavigation.php | File | 703 B | 0640 |
|
| AdvancedTabs.php | File | 886 B | 0640 |
|
| AdvancedVideo.php | File | 1021 B | 0640 |
|
| Breadcrumbs.php | File | 11.37 KB | 0640 |
|
| Button.php | File | 3.82 KB | 0640 |
|
| CallToAction.php | File | 365 B | 0640 |
|
| Column.php | File | 220 B | 0640 |
|
| CountDown.php | File | 605 B | 0640 |
|
| DualButton.php | File | 666 B | 0640 |
|
| FeatureList.php | File | 332 B | 0640 |
|
| FlexContainer.php | File | 371 B | 0640 |
|
| FlipBox.php | File | 648 B | 0640 |
|
| FluentForms.php | File | 3.77 KB | 0640 |
|
| Form.php | File | 5.72 KB | 0640 |
|
| FormTextField.php | File | 246 B | 0640 |
|
| GoogleMap.php | File | 2.55 KB | 0640 |
|
| Icon.php | File | 323 B | 0640 |
|
| ImageComparison.php | File | 620 B | 0640 |
|
| ImageGallery.php | File | 2.26 KB | 0640 |
|
| InfoBox.php | File | 761 B | 0640 |
|
| InstagramFeed.php | File | 5.89 KB | 0640 |
|
| InteractivePromo.php | File | 321 B | 0640 |
|
| LottieAnimation.php | File | 608 B | 0640 |
|
| NftGallery.php | File | 649 B | 0640 |
|
| Notice.php | File | 580 B | 0640 |
|
| NumberCounter.php | File | 598 B | 0640 |
|
| Openverse.php | File | 480 B | 0640 |
|
| ParallaxSlider.php | File | 664 B | 0640 |
|
| PopUp.php | File | 625 B | 0640 |
|
| PostBlock.php | File | 1.57 KB | 0640 |
|
| PostCarousel.php | File | 4.62 KB | 0640 |
|
| PostGrid.php | File | 5.79 KB | 0640 |
|
| PostMeta.php | File | 7.24 KB | 0640 |
|
| PricingTable.php | File | 333 B | 0640 |
|
| ProductDetails.php | File | 3.51 KB | 0640 |
|
| ProductImages.php | File | 2.83 KB | 0640 |
|
| ProductPrice.php | File | 4.75 KB | 0640 |
|
| ProductRating.php | File | 2.97 KB | 0640 |
|
| ProgressBar.php | File | 604 B | 0640 |
|
| Row.php | File | 455 B | 0640 |
|
| ShapeDivider.php | File | 602 B | 0640 |
|
| Slider.php | File | 1.09 KB | 0640 |
|
| Social.php | File | 352 B | 0640 |
|
| SocialShare.php | File | 3.89 KB | 0640 |
|
| Tab.php | File | 214 B | 0640 |
|
| TableOfContents.php | File | 17.38 KB | 0640 |
|
| Taxonomy.php | File | 4.92 KB | 0640 |
|
| TeamMember.php | File | 361 B | 0640 |
|
| Testimonial.php | File | 373 B | 0640 |
|
| Text.php | File | 5.17 KB | 0640 |
|
| ToggleContent.php | File | 613 B | 0640 |
|
| TypingText.php | File | 594 B | 0640 |
|
| WPForms.php | File | 2.92 KB | 0640 |
|
| WooProductGrid.php | File | 8.39 KB | 0640 |
|
| Wrapper.php | File | 359 B | 0640 |
|
| price.php | File | 239 B | 0640 |
|