HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-59-generic #61-Ubuntu SMP PREEMPT_DYNAMIC Fri Apr 11 23:16:11 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /opt/wpsites/datainsightnow.com/wp-content/plugins/essential-blocks/blocks/PostGrid.php
<?php
namespace EssentialBlocks\blocks;

use EssentialBlocks\Utils\Helper;

class PostGrid extends PostBlock {
    protected $frontend_scripts = ['essential-blocks-post-grid-frontend'];

    protected $frontend_styles = ['essential-blocks-frontend-style'];

    protected static $default_attributes = [
        'thumbnailSize'      => '',
        'loadMoreOptions'    => false,
        'showTaxonomyFilter' => false
    ];

    public function get_default_attributes() {
        return array_merge( parent::$default_attributes, self::$default_attributes );
    }

    /**
     * Unique name of the block.
     * @return string
     */
    public function get_name() {
        return 'post-grid';
    }

    /**
     * Register all other scripts
     * @return void
     */
    public function register_scripts() {
        $this->assets_manager->register(
            'post-grid-frontend',
            $this->path() . '/frontend/index.js'
        );
    }

    /**
     * Block render callback.
     *
     * @param mixed $attributes
     * @param mixed $content
     * @return mixed
     */
    public function render_callback( $attributes, $content ) {
        if ( is_admin() ) {
            return;
        }

        $queryData = $attributes["queryData"];

        //Query Result
        $result = $this->get_posts( $queryData );
        $query  = [];
        if ( isset( $result->posts ) && is_array( $result->posts ) && count( $result->posts ) > 0 ) {
            $query = apply_filters( 'eb_post_grid_query_results', $result->posts );
        }

        $attributes = wp_parse_args( $attributes, $this->get_default_attributes() );

        $className = isset( $attributes["className"] ) ? $attributes["className"] : "";
        $classHook = isset( $attributes['classHook'] ) ? $attributes['classHook'] : '';

        $_default_attributes = array_keys( parent::$default_attributes );
        $_essential_attrs    = [
            'thumbnailSize'   => $attributes["thumbnailSize"],
            'loadMoreOptions' => $attributes['loadMoreOptions']
        ];

        //set total posts
        if ( isset( $result->found_posts ) ) {
            if ( isset( $attributes['loadMoreOptions']['totalPosts'] ) ) {
                $attributes['loadMoreOptions']['totalPosts'] = $result->found_posts;
            }
            if ( isset( $_essential_attrs['loadMoreOptions']['totalPosts'] ) ) {
                $_essential_attrs['loadMoreOptions']['totalPosts'] = $result->found_posts;
            }
        }

        array_walk( $_default_attributes, function ( $key ) use ( $attributes, &$_essential_attrs ) {
            $_essential_attrs[$key] = $attributes[$key];
        } );

        ob_start();
        Helper::views( 'post-grid', array_merge( $attributes, [
            'essentialAttr' => $_essential_attrs,
            'className'     => $className,
            'classHook'     => $classHook,
            'posts'         => $query,
            'block_object'  => $this
        ] ) );

        return ob_get_clean();
    }
}