__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ 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\Core\Block;
class Button extends Block
{
protected $frontend_styles = [ 'essential-blocks-fontawesome', 'essential-blocks-hover-css' ];
/**
* Unique name of the block.
*
* @return string
*/
public function get_name()
{
return 'button';
}
/**
* Check if we're in a Loop Builder/Post Template 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;
}
/**
* Block render callback.
* If the button is inside the Post Template (Loop Builder) context, update the link
* to the current post permalink and force the button text to "Read More".
*
* @param array $attributes
* @param string $content
* @param \WP_Block|null $block
* @return string
*/
public function render_callback( $attributes, $content, $block = null )
{
if ( is_admin() ) {
return;
}
// Only modify when we have content and block context is available
if ( empty( $content ) || ! $block ) {
return $content;
}
$context = isset( $block->context ) ? $block->context : [];
$is_in_loop_builder = $this->is_in_loop_builder_context( $context );
if ( ! $is_in_loop_builder ) {
// Not in Loop Builder, keep original content
return $content;
}
// Determine the post ID from context (fallback to global)
$post_id = isset( $context['essential-blocks/postId'] ) ? intval( $context['essential-blocks/postId'] ) : 0;
if ( $post_id <= 0 ) {
$post_id = get_the_ID();
}
if ( ! $post_id ) {
return $content;
}
$permalink = get_the_permalink( $post_id );
$read_more = esc_html__( 'Read More', 'essential-blocks' );
// Safely update the anchor href and button text using DOMDocument
$html = '<!DOCTYPE html><html><head><meta charset="' . esc_attr( get_bloginfo( 'charset' ) ) . '"></head><body>' . $content . '</body></html>';
$dom = new \DOMDocument();
libxml_use_internal_errors( true );
if ( ! $dom->loadHTML( $html ) ) {
libxml_clear_errors();
return $content;
}
libxml_clear_errors();
$xpath = new \DOMXPath( $dom );
// Find the anchor element rendered by the Button block
$anchorNodes = $xpath->query( "//a[contains(concat(' ', normalize-space(@class), ' '), ' eb-button-anchor ')]" );
if ( $anchorNodes && $anchorNodes->length > 0 ) {
/** @var \DOMElement $anchor */
$anchor = $anchorNodes->item( 0 );
$anchor->setAttribute( 'href', esc_url( $permalink ) );
// Update the text node inside .eb-button-text if present
$textNodes = $xpath->query( ".//*[contains(concat(' ', normalize-space(@class), ' '), ' eb-button-text ')]", $anchor );
if ( $textNodes && $textNodes->length > 0 ) {
/** @var \DOMElement $textEl */
$textEl = $textNodes->item( 0 );
// Remove all children and set text content
while ( $textEl->firstChild ) {
$textEl->removeChild( $textEl->firstChild );
}
$textEl->appendChild( $dom->createTextNode( $read_more ) );
}
}
// Extract body innerHTML back
$body = $dom->getElementsByTagName( 'body' )->item( 0 );
$updated = '';
foreach ( $body->childNodes as $child ) {
$updated .= $dom->saveHTML( $child );
}
return $updated ?: $content;
}
}
| 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 |
|