• Resolved EmanueleT

    (@emanuelet)


    Hi there,

    i am writing cos lately the NFT Gallery plugin stopped working.

    The API ùis correct, the ETH wallet selcted.

    What could be?

    Anyone with this issue?

    Ty

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter EmanueleT

    (@emanuelet)

    I’ve noticed that the plugin is calling API V1, but it seems that since ?last?Dec 14, 2023?it is deprecated – read?here. I think that the plugin code should migrate to the new V2 endpoints which can be found here:?https://docs.opensea.io/reference/list_nfts_by_collection
    Ty

    Plugin Author Nick Weisser

    (@openstream)

    Hi Emanuele,

    I fixed this by updating to the new v2 endpoint in /wp-content/plugins/nft-gallery/inc/shortcodes.php and can now display NFTs from a single wallet Ethereum address. To show a collection needs a little more work, which I would be willing to put in, if the plugin author will add me as a contributor to the plugin.

    In case you wanna give this a shot, here’s the updated shortcodes.php code:

    <?php
    /**
    * NFT Gallery - shortcodes.php
    *
    * In this file,
    * you will find all functions related to the shortcodes that are available on the plugin.
    *
    * @author   Hendra Setiawan
    * @version  1.0.0
    */
    
    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }
    
    function nftgallery_function( $atts ){ 
            wp_enqueue_style( 'nftgallery' );
            wp_enqueue_style( 'justifiedGallery' );
            wp_enqueue_script( 'nftgallery' );
            wp_enqueue_script( 'justifiedGallery' );
    
            $args = array(
                'headers'     => array(
                    'accept' => 'application/json',
                    'x-api-key' => get_option('nftgallery-api')
                )
            );
    
            $type = get_option('nftgallery-type');
            $limit = get_option('nftgallery-limit');
            $id = get_option('nftgallery-id');
            $style = get_option('nftgallery-style');
    
            $request = wp_remote_get('https://api.opensea.io/api/v2/chain/ethereum/account/'.$id.'/nfts', $args);
            
            ob_start();
            $nfts = '';
    
            if( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) != 200 ) {
                $nfts .= '<pre>No NFTs detected! Please check the wallet address or the collection slug.</pre>';
            } else {
                $body = wp_remote_retrieve_body( $request );
    
                $data = json_decode( $body );
    
                if( ! empty( $data ) ) {
                    if($style == 'grid') {
                        wp_enqueue_style( 'flexbox' );
                        $nfts .= '<div class="row nftgallery">';
                        foreach( $data->nfts as $asset ) {
                            if($asset->name) { $title = $asset->name; } else { $title = '#'.$asset->identifier; }
                            
                            $nfts .= '<div class="col-xs-6 col-sm-6 col-md-6 col-lg-4 nftgallery-wrapper">';
                                $nfts .= '<div class="nft" data-url="'.$asset->opensea_url.'">';
                                $nfts .= '<div class="image" style="background-image: url('.$asset->image_url.');"></div>';
                                $nfts .= '<div class="desc">
                                            <div class="collection">'.$asset->collection.'</div>
                                            <h2>'.$title.'</h2>
                                          </div>';
                                $nfts .= '</div>';
                            $nfts .= '</div>';
                        
                        }
                        if($type == 'collection'):
    
                            $nfts .= '<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 os-button-wrapper"><a  class="view-opensea" target="_blank">View '.$asset->collection->name.' on OpenSea</a></div>';
                        
                        endif;
                        $nfts .= '</div>';
                    } else if($style == 'photography') {
                        wp_enqueue_style( 'lightgallery' );        
                        wp_enqueue_style( 'lightgalleryzoom' );
                        wp_enqueue_style( 'lightgallerythumbnail' );
                        wp_enqueue_style( 'lightgallerytransition' );
    
                        wp_enqueue_script( 'lightgallery' );
                        wp_enqueue_script( 'lightgallerythumbnail' );
                        wp_enqueue_script( 'lightgalleryzoom' );      
                                               
                        $nfts .= '<div class="gallery-container nftgallery" id="lightgallery">';
                        $no = 1;
                        foreach( $data->assets as $asset ) {
                            $basename = basename($asset->image_url);
                            if($asset->name) { $title = $asset->name; } else { $title = $asset->token_id; }
                            $title = strip_tags($title);
                            $title = preg_replace('#[^\w()/.%\-&]#'," ",$title);
                            
                            $nfts .= '<a data-src="'.$asset->image_url.'" data-download-url="false" class="gallery-item" data-sub-html=".caption'.$no.'">';
                            $nfts .= '<img class="img-fluid" src="'.$asset->image_preview_url.'" />';
                            $nfts .= '<div class="caption caption'.$no.'"><p class="nft-title">'.$title.'</p><p>Minted by <strong>'.$asset->creator->user->username.'</strong> in <strong>'.$asset->collection->name.'</strong></p><button class="openseaBtn" data-url="'.$asset->permalink.'">View on OpenSea</button></div>';
                            $nfts .= '</a>';
                            $no++;
                        }
                        $nfts .= '</div>';
                    }
                }
            }
            
            echo wp_kses_post($nfts);
            return ob_get_clean(); 
    }
    add_shortcode('nftgallery', 'nftgallery_function');

    But bear in mind that this only works with Ethereum NFTs, probably because the v1 API did not support other chains. Those could be added easily to the plugin configuration page, though.

    Plugin Author Nick Weisser

    (@openstream)

    Finally released a new version of the plugin that supports v2 of the OpenSea API.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘NFT Collection not loading’ is closed to new replies.