Plugin Directory

Changeset 3836554


Ignore:
Timestamp:
12/01/2026 04:25:31 AM (less than one hour ago)
Author:
hasanazizul
Message:

3.1.2

Location:
ar-vr-3d-model-try-on/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ar-vr-3d-model-try-on/trunk/ar-vr-3d-model-try-on.php

    r3829924 r3836554  
    1515 * Plugin URI:        https://atlasaidev.com/
    1616 * Description:       3D Model Viewer & WordPress AR Plugin lets you upload and display 3D models with built-in AR on iOS & Android—no extra apps needed.
    17  * Version:           3.1.1
     17 * Version:           3.1.2
    1818 * Author:            AtlasAiDev
    1919 * Author URI:        https://atlasaidev.com/
    … …  
    153153        public static function define_constants() {
    154154                if ( ! defined( 'ATLAS_AR_VERSION' ) ) {
    155                         define( 'ATLAS_AR_VERSION', apply_filters( 'ATLAS_AR_version', '3.1.1' ) );
     155                        define( 'ATLAS_AR_VERSION', apply_filters( 'ATLAS_AR_version', '3.1.2' ) );
    156156                }
    157157
  • ar-vr-3d-model-try-on/trunk/includes/AR_TRY_ON_Frontend.php

    r3774402 r3836554  
    3636        private static $tryon_done = array();
    3737
     38        /**
     39         * AR-192: this page's AtlasAR output, each waiting for its WooCommerce hook.
     40         *
     41         * @var array[] each: done (bool), print (callable), to ('gallery' | 'cart')
     42         */
     43        private static $waiting = array();
     44
     45        /** @var callable|null AR-192: prints the tab-only 3D view once (in the tab, else at the end of the page) */
     46        private static $tab_print = null;
     47
    3848        /** Called on `init` (atlas_ar_run). */
    3949        public static function init() {
    … …  
    4252                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'quiet_old_pro' ), 6 );
    4353                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'drop_old_pro_scripts' ), 21 );
     54                add_action( 'wp_footer', array( __CLASS__, 'print_waiting' ), 0 ); // AR-192: before enqueue_if_used
    4455                add_action( 'wp_footer', array( __CLASS__, 'enqueue_if_used' ), 1 );
    4556                add_filter( 'script_loader_tag', array( __CLASS__, 'no_optimize' ), 10, 2 );
    … …  
    223234                                case 'gallery3d':
    224235                                        // Printed after the gallery; atlas-ar-front.js moves it over the main image.
    225                                         add_action(
    226                                                 'woocommerce_before_single_product_summary',
     236                                        self::place_once(
     237                                                array( array( 'woocommerce_before_single_product_summary', 25 ) ),
    227238                                                function () use ( $post_id, $mode ) {
    228239                                                        $html = AR_TRY_ON_Viewer::render( $post_id, 'gallery' );
    … …  
    231242                                                        }
    232243                                                },
    233                                                 25
     244                                                'gallery'
    234245                                        );
    235246                                        break;
    236247                                case 'slide':
    237                                         add_action(
    238                                                 'woocommerce_product_thumbnails',
     248                                        self::place_once(
     249                                                array( array( 'woocommerce_product_thumbnails', 5 ) ),
    239250                                                function () use ( $post_id ) {
    240251                                                        $html = AR_TRY_ON_Viewer::render( $post_id, 'slide' );
    … …  
    243254                                                        }
    244255                                                },
    245                                                 5
     256                                                'cart' // no WooCommerce gallery ran, so no slider to join: the view shows by the cart form
    246257                                        );
    247258                                        break;
    … …  
    259270                                        break;
    260271                        }
     272                        if ( 'tab' === $mode ) {
     273                                // AR-192: the tab is the only place: a template without WooCommerce's tabs still shows it.
     274                                self::$tab_print = self::place_once(
     275                                        array(),
     276                                        function () use ( $post_id ) {
     277                                                AR_TRY_ON_Viewer::print_html( AR_TRY_ON_Viewer::render( $post_id, 'tab' ) );
     278                                        },
     279                                        'cart'
     280                                );
     281                        }
    261282                        if ( 'tab' === $mode || AR_TRY_ON_Settings::get( 'placement.product_tab' ) ) {
    262283                                add_filter( 'woocommerce_product_tabs', array( __CLASS__, 'add_tab' ) );
    … …  
    279300         * shops) gets no "Add to cart" form, so the form's hooks never fire: it also gets $callback late
    280301         * in the product summary, after where the form would be. Printed once, whichever runs first.
    281          * Products that can be bought keep the plain hook.
     302         * Products that can be bought keep the plain hook. AR-192: when none of them runs, at the end of
     303         * the page (place_once).
    282304         *
    283305         * @param string   $hook     action
    … …  
    287309         */
    288310        private static function hook_or_summary( $hook, $priority, $post_id, $callback ) {
     311                $hooks   = array( array( $hook, $priority ) );
    289312                $form    = array( 'woocommerce_before_add_to_cart_form', 'woocommerce_after_add_to_cart_form' );
    290313                $product = in_array( $hook, $form, true ) ? wc_get_product( $post_id ) : null;
    291                 if ( ! $product || ( $product->is_purchasable() && $product->is_in_stock() ) ) {
    292                         add_action( $hook, $callback, $priority );
     314                if ( $product && ! ( $product->is_purchasable() && $product->is_in_stock() ) ) {
     315                        $hooks[] = array( 'woocommerce_single_product_summary', 35 ); // add to cart is at 30, meta at 40
     316                }
     317                self::place_once( $hooks, $callback, 'cart' );
     318        }
     319
     320        /**
     321         * AR-192: print $print once, at the first of $hooks that runs. Page-builder product templates
     322         * (Impreza and others) skip some WooCommerce hooks (the summary, the tabs): what was hooked there
     323         * is printed at the end of the page instead (print_waiting) and atlas-ar-front.js moves it to
     324         * $to: 'gallery' (over the main image) or 'cart' (after the add-to-cart form).
     325         *
     326         * @param array[]  $hooks [ action, priority ] pairs
     327         * @param callable $print prints the output
     328         * @param string   $to    gallery | cart
     329         * @return callable prints it now, unless it was printed already
     330         */
     331        private static function place_once( array $hooks, $print, $to ) {
     332                $key                   = count( self::$waiting );
     333                self::$waiting[ $key ] = array(
     334                        'done'  => false,
     335                        'print' => $print,
     336                        'to'    => $to,
     337                );
     338                $once = function () use ( $key ) {
     339                        self::print_now( $key );
     340                };
     341                foreach ( $hooks as $hook ) {
     342                        add_action( $hook[0], $once, $hook[1] );
     343                }
     344                return $once;
     345        }
     346
     347        /** AR-192: print one waiting output, unless it was printed already. */
     348        private static function print_now( $key ) {
     349                if ( ! isset( self::$waiting[ $key ] ) || self::$waiting[ $key ]['done'] ) {
    293350                        return;
    294351                }
    295                 $done = false;
    296                 $once = function () use ( &$done, $callback ) {
    297                         if ( ! $done ) {
    298                                 $done = true;
    299                                 $callback();
    300                         }
    301                 };
    302                 add_action( $hook, $once, $priority );
    303                 add_action( 'woocommerce_single_product_summary', $once, 35 ); // add to cart is at 30, meta at 40
     352                self::$waiting[ $key ]['done'] = true;
     353                call_user_func( self::$waiting[ $key ]['print'] );
     354        }
     355
     356        /**
     357         * AR-192: on `wp_footer` (before the scripts are chosen), what no hook printed, each in a hidden
     358         * box that atlas-ar-front.js moves to its place and shows. Nothing when everything printed.
     359         */
     360        public static function print_waiting() {
     361                foreach ( array_keys( self::$waiting ) as $key ) {
     362                        if ( self::$waiting[ $key ]['done'] ) {
     363                                continue;
     364                        }
     365                        ob_start();
     366                        self::print_now( $key );
     367                        $html = trim( (string) ob_get_clean() );
     368                        if ( '' !== $html ) {
     369                                AR_TRY_ON_Viewer::print_html( '<div class="atlas-ar-moved" data-atlas-ar-to="' . esc_attr( self::$waiting[ $key ]['to'] ) . '" hidden>' . $html . '</div>' );
     370                        }
     371                }
     372        }
     373
     374        /** Forget this page's placed output (tests: a new page view in the same PHP run). */
     375        public static function forget() {
     376                self::$waiting    = array();
     377                self::$tryon_done = array();
     378                self::$tab_print  = null;
    304379        }
    305380
    … …  
    310385                        'priority' => 15,
    311386                        'callback' => function () {
     387                                if ( self::$tab_print ) {
     388                                        call_user_func( self::$tab_print ); // AR-192: the tab-only view, printed once
     389                                        return;
     390                                }
    312391                                AR_TRY_ON_Viewer::print_html( AR_TRY_ON_Viewer::render( (int) get_queried_object_id(), 'tab' ) );
    313392                        },
  • ar-vr-3d-model-try-on/trunk/includes/AR_TRY_ON_Viewer.php

    r3805400 r3836554  
    277277                /** Pro adds the attributes of its options (hotspots, dimensions, items, variants…). */
    278278                $viewer = (array) apply_filters( 'atlas_ar_viewer_allowed_attributes', $viewer );
    279                 $box    = array( 'class' => true, 'style' => true, 'hidden' => true, 'data-atlas-ar-start' => true, 'data-thumb' => true, 'data-thumb-alt' => true );
     279                $box    = array( 'class' => true, 'style' => true, 'hidden' => true, 'data-atlas-ar-start' => true, 'data-atlas-ar-to' => true, 'data-thumb' => true, 'data-thumb-alt' => true ); // data-atlas-ar-to: AR-192
    280280                return array(
    281281                        'atlasar-viewer' => $viewer,
  • ar-vr-3d-model-try-on/trunk/public/js/atlas-ar-front.js

    r3805400 r3836554  
    253253        }
    254254
     255        /* ------------------------------------------------------ AR-192: moved */
     256        // A page-builder product template (Impreza and others) skips some WooCommerce hooks, so the
     257        // server printed that output at the end of the page: put it in its place. "gallery": the gallery
     258        // view finds the main image itself (setupGallery); "cart" (or no gallery): after the add-to-cart
     259        // form, else after the gallery; else it stays where it is.
     260        function placeMoved() {
     261                Array.prototype.forEach.call(document.querySelectorAll('.atlas-ar-moved'), function (box) {
     262                        var gallery = document.querySelector('.woocommerce-product-gallery');
     263                        var form = document.querySelector('form.cart');
     264                        var anchor = box.getAttribute('data-atlas-ar-to') === 'gallery' && gallery ? null : (form || gallery);
     265                        if (anchor && anchor.parentNode) anchor.parentNode.insertBefore(box, anchor.nextSibling);
     266                        box.hidden = false;
     267                });
     268        }
     269
    255270        function start() {
     271                placeMoved();
    256272                Array.prototype.forEach.call(document.querySelectorAll('.atlas-ar-gallery'), setupGallery);
    257273                Array.prototype.forEach.call(document.querySelectorAll('.atlas-ar-slide'), setupSlideThumb);
  • ar-vr-3d-model-try-on/trunk/readme.txt

    r3829924 r3836554  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 3.1.1
     7Stable tag: 3.1.2
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.txt
    … …  
    210210== Changelog ==
    211211
     212= 3.1.2 ( 1 December 2026 ) =
     213* Fix: The 3D view and the 3D button show again on product pages built with a page builder or a theme's own product layout (for example Impreza). They had disappeared there after updating to AtlasAR 3, while your settings were fine.
     214
    212215= 3.1.1 ( 27 November 2026 ) =
    213216* Compatibility: Tested with WordPress 7.2. Nothing changes in how the plugin works.
    … …  
    570573== Upgrade Notice ==
    571574
     575= 3.1.2 =
     576Fixes the 3D view and 3D button missing on product pages built with a page builder or a theme's own product layout. Your settings stay as they are.
     577
    572578= 3.1.1 =
    573579Tested with WordPress 7.2. No other changes, safe to update.
Note: See TracChangeset for help on using the changeset viewer.