Plugin Directory

Changeset 3378879


Ignore:
Timestamp:
10/15/2025 12:21:05 PM (6 months ago)
Author:
shutterpressgallery
Message:

Update to version 1.7.7 from GitHub

Location:
shutterpress-gallery
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • shutterpress-gallery/tags/1.7.7/README.txt

    r3378680 r3378879  
    66Tested up to: 6.8
    77Requires PHP: 8.0
    8 Stable tag: 1.7.6
     8Stable tag: 1.7.7
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    119119
    120120== Changelog ==
     121
     122= 1.7.7 =
     123
     124* Fix - Gallery Block not rendering correctly
    121125
    122126= 1.7.6 =
  • shutterpress-gallery/tags/1.7.7/includes/blocks/shutterpress-gallery-block/shutterpress-gallery-block-render.php

    r3378680 r3378879  
    1919$gallery_attributes = [
    2020    'gallery_id' => isset($attributes['galleryId']) && intval($attributes['galleryId']) !== 0 ? intval($attributes['galleryId']) : '',
     21   
     22    'post_id' => isset($attributes['postId']) ? intval($attributes['postId']) : (isset($_GET['post']) ? intval($_GET['post']) : (get_the_ID() ? intval(get_the_ID()) : 0)),
    2123    'use_lightbox' => isset($attributes['useLightbox']) ? filter_var($attributes['useLightbox'], FILTER_VALIDATE_BOOLEAN) : filter_var($defaults['use_lightbox'], FILTER_VALIDATE_BOOLEAN),
    2224    'layout' => isset($attributes['galleryLayout']) ? sanitize_text_field($attributes['galleryLayout']) : sanitize_text_field($defaults['layout']),
     
    3941
    4042        $gallery_attributes = is_array($gallery_attributes) ? $gallery_attributes : [];
    41         $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : 0;
     43        $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : -1;
    4244
    4345        if ($gallery_id === -1) {
    4446           
    45             $gallery_id = (int) get_the_ID();
    46             $gallery_attributes['gallery_id'] = $gallery_id;
     47            $context_post_id = 0;
     48
     49            if (!empty($gallery_attributes['post_id'])) {
     50                $context_post_id = (int) $gallery_attributes['post_id'];
     51            }
     52
     53            if ($context_post_id <= 0 && isset($_GET['post'])) {
     54                $context_post_id = (int) $_GET['post'];
     55            }
     56
     57            if ($context_post_id <= 0 && isset($GLOBALS['post']) && $GLOBALS['post'] instanceof \WP_Post) {
     58                $context_post_id = (int) $GLOBALS['post']->ID;
     59            }
     60
     61            if ($context_post_id <= 0) {
     62                $context_post_id = (int) get_the_ID();
     63            }
     64
     65            if ($context_post_id > 0) {
     66                $gallery_id = $context_post_id;
     67                $gallery_attributes['gallery_id'] = $gallery_id;
     68               
     69                $linked_gallery_id = 0;
     70                $candidate_meta_keys = ['sp_gallery_id', '_sp_gallery_id', 'shutterpress_gallery_id', '_shutterpress_gallery_id', 'sp_post_gallery_id', '_sp_post_gallery_id'];
     71                foreach ($candidate_meta_keys as $mk) {
     72                    $val = (int) get_post_meta($context_post_id, $mk, true);
     73                    if ($val > 0) {
     74                        $linked_gallery_id = $val;
     75                        break;
     76                    }
     77                }
     78               
     79                if ($linked_gallery_id > 0) {
     80                    $gallery_id = $linked_gallery_id;
     81                    $gallery_attributes['gallery_id'] = $gallery_id;
     82                    $gallery_attributes['post_id'] = $context_post_id;
     83                } else {
     84                   
     85                    $gallery_attributes['post_id'] = $context_post_id;
     86                }
     87            }
    4788        }
    4889
    49         if ($gallery_id <= 0) {
     90        if ($gallery_id <= 0 && empty($gallery_attributes['post_id'])) {
    5091            return '<div ' . \get_block_wrapper_attributes() . '></div>';
    5192        }
     
    5495
    5596        if (!$renderer) {
    56             if (!isset($renderers[$gallery_id])) {
    57                 $renderers[$gallery_id] = new Shutterpress_Gallery_Gallery($gallery_id);
     97            $cache_key = (int) ($gallery_id > 0 ? $gallery_id : $gallery_attributes['post_id'] ?? 0);
     98            if ($cache_key <= 0) {
     99                $cache_key = 0;
    58100            }
    59             $renderer = $renderers[$gallery_id];
     101            if (!isset($renderers[$cache_key])) {
     102               
     103                $renderers[$cache_key] = new Shutterpress_Gallery_Gallery($gallery_id > 0 ? $gallery_id : 0);
     104            }
     105            $renderer = $renderers[$cache_key];
    60106        }
    61107
     
    64110            $output = '<div ' . \get_block_wrapper_attributes() . '>';
    65111
    66             if (method_exists($renderer, 'get_gallery_images') && !empty($renderer->get_gallery_images())) {
    67                 if (defined('REST_REQUEST') && REST_REQUEST && 'edit' === $_GET['context']) {
    68                     $gallery_attributes['infinite_scroll'] = '0';
    69                     $gallery_attributes['use_lightbox'] = '0';
    70                 }
     112            if (defined('REST_REQUEST') && REST_REQUEST && isset($_GET['context']) && 'edit' === $_GET['context']) {
     113                $gallery_attributes['infinite_scroll'] = '0';
     114                $gallery_attributes['use_lightbox'] = '0';
     115            }
    71116
    72                 if (method_exists($renderer, 'set_attributes')) {
    73                     $renderer->set_attributes($gallery_attributes);
    74                 }
     117            if (method_exists($renderer, 'set_attributes')) {
     118                $renderer->set_attributes($gallery_attributes);
     119            }
    75120
     121            if (method_exists($renderer, 'set_post_id') && !empty($gallery_attributes['post_id'])) {
     122                $renderer->set_post_id((int) $gallery_attributes['post_id']);
     123            }
     124            if (method_exists($renderer, 'set_is_post_gallery') && isset($linked_gallery_id) && (int) $linked_gallery_id === 0 && !empty($gallery_attributes['post_id'])) {
     125                $renderer->set_is_post_gallery(true);
     126            }
     127
     128            $has_images = method_exists($renderer, 'get_gallery_images') ? (array) $renderer->get_gallery_images() : [];
     129
     130            if (!empty($has_images)) {
    76131                if (method_exists($renderer, 'get_buttons')) {
    77132                    $output .= $renderer->get_buttons();
  • shutterpress-gallery/tags/1.7.7/shutterpress-gallery.php

    r3378680 r3378879  
    1111 * Plugin URI:        https://shutterpress.io
    1212 * Description:       WordPress photo gallery plugin for photographers and creatives. Build fast, responsive image galleries with Masonry, Justified, and Grid layouts, lightbox support, and Infinite Scroll.
    13  * Version:           1.7.6
     13 * Version:           1.7.7
    1414 * Author:            ShutterPress
    1515 * Author URI:        https://shutterpress.io
     
    2727 * Current plugin version.
    2828 */
    29 define('SHUTTERPRESS_GALLERY_VERSION', '1.7.6');
     29define('SHUTTERPRESS_GALLERY_VERSION', '1.7.7');
    3030
    3131define('SP_GALLERY_DIR', plugin_dir_path(__FILE__));
  • shutterpress-gallery/tags/1.7.7/src/admin/Shutterpress_Gallery_Admin.php

    r3378680 r3378879  
    105105        }
    106106
    107         $should_load = true;
    108         if (function_exists('wp_should_load_block_editor_scripts_and_styles')) {
    109             $should_load = wp_should_load_block_editor_scripts_and_styles();
    110         }
    111         if (!$should_load && !defined('SHUTTERPRESS_TESTING')) {
    112             return;
    113         }
    114 
    115107        wp_enqueue_style($this->plugin_name . '-public', SP_GALLERY_URL . 'includes/css/shutterpress-gallery-public.css', [], $this->version, 'all');
    116108
    117109        $vendor_base = SP_GALLERY_URL . 'includes/js/';
    118        
     110
    119111        wp_register_script('isotope', $vendor_base . 'isotope.pkgd.min.js', ['jquery'], '3.0.0', false);
    120112       
  • shutterpress-gallery/tags/1.7.7/src/shutterpress-gallery-block/shutterpress-gallery-block-render.php

    r3378680 r3378879  
    1919$gallery_attributes = [
    2020    'gallery_id' => isset($attributes['galleryId']) && intval($attributes['galleryId']) !== 0 ? intval($attributes['galleryId']) : '',
     21   
     22    'post_id' => isset($attributes['postId']) ? intval($attributes['postId']) : (isset($_GET['post']) ? intval($_GET['post']) : (get_the_ID() ? intval(get_the_ID()) : 0)),
    2123    'use_lightbox' => isset($attributes['useLightbox']) ? filter_var($attributes['useLightbox'], FILTER_VALIDATE_BOOLEAN) : filter_var($defaults['use_lightbox'], FILTER_VALIDATE_BOOLEAN),
    2224    'layout' => isset($attributes['galleryLayout']) ? sanitize_text_field($attributes['galleryLayout']) : sanitize_text_field($defaults['layout']),
     
    3941
    4042        $gallery_attributes = is_array($gallery_attributes) ? $gallery_attributes : [];
    41         $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : 0;
     43        $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : -1;
    4244
    4345        if ($gallery_id === -1) {
    4446           
    45             $gallery_id = (int) get_the_ID();
    46             $gallery_attributes['gallery_id'] = $gallery_id;
     47            $context_post_id = 0;
     48
     49            if (!empty($gallery_attributes['post_id'])) {
     50                $context_post_id = (int) $gallery_attributes['post_id'];
     51            }
     52
     53            if ($context_post_id <= 0 && isset($_GET['post'])) {
     54                $context_post_id = (int) $_GET['post'];
     55            }
     56
     57            if ($context_post_id <= 0 && isset($GLOBALS['post']) && $GLOBALS['post'] instanceof \WP_Post) {
     58                $context_post_id = (int) $GLOBALS['post']->ID;
     59            }
     60
     61            if ($context_post_id <= 0) {
     62                $context_post_id = (int) get_the_ID();
     63            }
     64
     65            if ($context_post_id > 0) {
     66                $gallery_id = $context_post_id;
     67                $gallery_attributes['gallery_id'] = $gallery_id;
     68               
     69                $linked_gallery_id = 0;
     70                $candidate_meta_keys = ['sp_gallery_id', '_sp_gallery_id', 'shutterpress_gallery_id', '_shutterpress_gallery_id', 'sp_post_gallery_id', '_sp_post_gallery_id'];
     71                foreach ($candidate_meta_keys as $mk) {
     72                    $val = (int) get_post_meta($context_post_id, $mk, true);
     73                    if ($val > 0) {
     74                        $linked_gallery_id = $val;
     75                        break;
     76                    }
     77                }
     78               
     79                if ($linked_gallery_id > 0) {
     80                    $gallery_id = $linked_gallery_id;
     81                    $gallery_attributes['gallery_id'] = $gallery_id;
     82                    $gallery_attributes['post_id'] = $context_post_id;
     83                } else {
     84                   
     85                    $gallery_attributes['post_id'] = $context_post_id;
     86                }
     87            }
    4788        }
    4889
    49         if ($gallery_id <= 0) {
     90        if ($gallery_id <= 0 && empty($gallery_attributes['post_id'])) {
    5091            return '<div ' . \get_block_wrapper_attributes() . '></div>';
    5192        }
     
    5495
    5596        if (!$renderer) {
    56             if (!isset($renderers[$gallery_id])) {
    57                 $renderers[$gallery_id] = new Shutterpress_Gallery_Gallery($gallery_id);
     97            $cache_key = (int) ($gallery_id > 0 ? $gallery_id : $gallery_attributes['post_id'] ?? 0);
     98            if ($cache_key <= 0) {
     99                $cache_key = 0;
    58100            }
    59             $renderer = $renderers[$gallery_id];
     101            if (!isset($renderers[$cache_key])) {
     102               
     103                $renderers[$cache_key] = new Shutterpress_Gallery_Gallery($gallery_id > 0 ? $gallery_id : 0);
     104            }
     105            $renderer = $renderers[$cache_key];
    60106        }
    61107
     
    64110            $output = '<div ' . \get_block_wrapper_attributes() . '>';
    65111
    66             if (method_exists($renderer, 'get_gallery_images') && !empty($renderer->get_gallery_images())) {
    67                 if (defined('REST_REQUEST') && REST_REQUEST && 'edit' === $_GET['context']) {
    68                     $gallery_attributes['infinite_scroll'] = '0';
    69                     $gallery_attributes['use_lightbox'] = '0';
    70                 }
     112            if (defined('REST_REQUEST') && REST_REQUEST && isset($_GET['context']) && 'edit' === $_GET['context']) {
     113                $gallery_attributes['infinite_scroll'] = '0';
     114                $gallery_attributes['use_lightbox'] = '0';
     115            }
    71116
    72                 if (method_exists($renderer, 'set_attributes')) {
    73                     $renderer->set_attributes($gallery_attributes);
    74                 }
     117            if (method_exists($renderer, 'set_attributes')) {
     118                $renderer->set_attributes($gallery_attributes);
     119            }
    75120
     121            if (method_exists($renderer, 'set_post_id') && !empty($gallery_attributes['post_id'])) {
     122                $renderer->set_post_id((int) $gallery_attributes['post_id']);
     123            }
     124            if (method_exists($renderer, 'set_is_post_gallery') && isset($linked_gallery_id) && (int) $linked_gallery_id === 0 && !empty($gallery_attributes['post_id'])) {
     125                $renderer->set_is_post_gallery(true);
     126            }
     127
     128            $has_images = method_exists($renderer, 'get_gallery_images') ? (array) $renderer->get_gallery_images() : [];
     129
     130            if (!empty($has_images)) {
    76131                if (method_exists($renderer, 'get_buttons')) {
    77132                    $output .= $renderer->get_buttons();
  • shutterpress-gallery/tags/1.7.7/vendor/composer/installed.php

    r3378680 r3378879  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'ee154d9281e430a177064ec382dda47bc35fbef9',
     6        'reference' => '8a9aecb868d4d8701c7225e6220bc9f9a2e2e09e',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    3535            'pretty_version' => 'dev-master',
    3636            'version' => 'dev-master',
    37             'reference' => 'ee154d9281e430a177064ec382dda47bc35fbef9',
     37            'reference' => '8a9aecb868d4d8701c7225e6220bc9f9a2e2e09e',
    3838            'type' => 'wordpress-plugin',
    3939            'install_path' => __DIR__ . '/../../',
  • shutterpress-gallery/trunk/README.txt

    r3378680 r3378879  
    66Tested up to: 6.8
    77Requires PHP: 8.0
    8 Stable tag: 1.7.6
     8Stable tag: 1.7.7
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    119119
    120120== Changelog ==
     121
     122= 1.7.7 =
     123
     124* Fix - Gallery Block not rendering correctly
    121125
    122126= 1.7.6 =
  • shutterpress-gallery/trunk/includes/blocks/shutterpress-gallery-block/shutterpress-gallery-block-render.php

    r3378680 r3378879  
    1919$gallery_attributes = [
    2020    'gallery_id' => isset($attributes['galleryId']) && intval($attributes['galleryId']) !== 0 ? intval($attributes['galleryId']) : '',
     21   
     22    'post_id' => isset($attributes['postId']) ? intval($attributes['postId']) : (isset($_GET['post']) ? intval($_GET['post']) : (get_the_ID() ? intval(get_the_ID()) : 0)),
    2123    'use_lightbox' => isset($attributes['useLightbox']) ? filter_var($attributes['useLightbox'], FILTER_VALIDATE_BOOLEAN) : filter_var($defaults['use_lightbox'], FILTER_VALIDATE_BOOLEAN),
    2224    'layout' => isset($attributes['galleryLayout']) ? sanitize_text_field($attributes['galleryLayout']) : sanitize_text_field($defaults['layout']),
     
    3941
    4042        $gallery_attributes = is_array($gallery_attributes) ? $gallery_attributes : [];
    41         $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : 0;
     43        $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : -1;
    4244
    4345        if ($gallery_id === -1) {
    4446           
    45             $gallery_id = (int) get_the_ID();
    46             $gallery_attributes['gallery_id'] = $gallery_id;
     47            $context_post_id = 0;
     48
     49            if (!empty($gallery_attributes['post_id'])) {
     50                $context_post_id = (int) $gallery_attributes['post_id'];
     51            }
     52
     53            if ($context_post_id <= 0 && isset($_GET['post'])) {
     54                $context_post_id = (int) $_GET['post'];
     55            }
     56
     57            if ($context_post_id <= 0 && isset($GLOBALS['post']) && $GLOBALS['post'] instanceof \WP_Post) {
     58                $context_post_id = (int) $GLOBALS['post']->ID;
     59            }
     60
     61            if ($context_post_id <= 0) {
     62                $context_post_id = (int) get_the_ID();
     63            }
     64
     65            if ($context_post_id > 0) {
     66                $gallery_id = $context_post_id;
     67                $gallery_attributes['gallery_id'] = $gallery_id;
     68               
     69                $linked_gallery_id = 0;
     70                $candidate_meta_keys = ['sp_gallery_id', '_sp_gallery_id', 'shutterpress_gallery_id', '_shutterpress_gallery_id', 'sp_post_gallery_id', '_sp_post_gallery_id'];
     71                foreach ($candidate_meta_keys as $mk) {
     72                    $val = (int) get_post_meta($context_post_id, $mk, true);
     73                    if ($val > 0) {
     74                        $linked_gallery_id = $val;
     75                        break;
     76                    }
     77                }
     78               
     79                if ($linked_gallery_id > 0) {
     80                    $gallery_id = $linked_gallery_id;
     81                    $gallery_attributes['gallery_id'] = $gallery_id;
     82                    $gallery_attributes['post_id'] = $context_post_id;
     83                } else {
     84                   
     85                    $gallery_attributes['post_id'] = $context_post_id;
     86                }
     87            }
    4788        }
    4889
    49         if ($gallery_id <= 0) {
     90        if ($gallery_id <= 0 && empty($gallery_attributes['post_id'])) {
    5091            return '<div ' . \get_block_wrapper_attributes() . '></div>';
    5192        }
     
    5495
    5596        if (!$renderer) {
    56             if (!isset($renderers[$gallery_id])) {
    57                 $renderers[$gallery_id] = new Shutterpress_Gallery_Gallery($gallery_id);
     97            $cache_key = (int) ($gallery_id > 0 ? $gallery_id : $gallery_attributes['post_id'] ?? 0);
     98            if ($cache_key <= 0) {
     99                $cache_key = 0;
    58100            }
    59             $renderer = $renderers[$gallery_id];
     101            if (!isset($renderers[$cache_key])) {
     102               
     103                $renderers[$cache_key] = new Shutterpress_Gallery_Gallery($gallery_id > 0 ? $gallery_id : 0);
     104            }
     105            $renderer = $renderers[$cache_key];
    60106        }
    61107
     
    64110            $output = '<div ' . \get_block_wrapper_attributes() . '>';
    65111
    66             if (method_exists($renderer, 'get_gallery_images') && !empty($renderer->get_gallery_images())) {
    67                 if (defined('REST_REQUEST') && REST_REQUEST && 'edit' === $_GET['context']) {
    68                     $gallery_attributes['infinite_scroll'] = '0';
    69                     $gallery_attributes['use_lightbox'] = '0';
    70                 }
     112            if (defined('REST_REQUEST') && REST_REQUEST && isset($_GET['context']) && 'edit' === $_GET['context']) {
     113                $gallery_attributes['infinite_scroll'] = '0';
     114                $gallery_attributes['use_lightbox'] = '0';
     115            }
    71116
    72                 if (method_exists($renderer, 'set_attributes')) {
    73                     $renderer->set_attributes($gallery_attributes);
    74                 }
     117            if (method_exists($renderer, 'set_attributes')) {
     118                $renderer->set_attributes($gallery_attributes);
     119            }
    75120
     121            if (method_exists($renderer, 'set_post_id') && !empty($gallery_attributes['post_id'])) {
     122                $renderer->set_post_id((int) $gallery_attributes['post_id']);
     123            }
     124            if (method_exists($renderer, 'set_is_post_gallery') && isset($linked_gallery_id) && (int) $linked_gallery_id === 0 && !empty($gallery_attributes['post_id'])) {
     125                $renderer->set_is_post_gallery(true);
     126            }
     127
     128            $has_images = method_exists($renderer, 'get_gallery_images') ? (array) $renderer->get_gallery_images() : [];
     129
     130            if (!empty($has_images)) {
    76131                if (method_exists($renderer, 'get_buttons')) {
    77132                    $output .= $renderer->get_buttons();
  • shutterpress-gallery/trunk/shutterpress-gallery.php

    r3378680 r3378879  
    1111 * Plugin URI:        https://shutterpress.io
    1212 * Description:       WordPress photo gallery plugin for photographers and creatives. Build fast, responsive image galleries with Masonry, Justified, and Grid layouts, lightbox support, and Infinite Scroll.
    13  * Version:           1.7.6
     13 * Version:           1.7.7
    1414 * Author:            ShutterPress
    1515 * Author URI:        https://shutterpress.io
     
    2727 * Current plugin version.
    2828 */
    29 define('SHUTTERPRESS_GALLERY_VERSION', '1.7.6');
     29define('SHUTTERPRESS_GALLERY_VERSION', '1.7.7');
    3030
    3131define('SP_GALLERY_DIR', plugin_dir_path(__FILE__));
  • shutterpress-gallery/trunk/src/admin/Shutterpress_Gallery_Admin.php

    r3378680 r3378879  
    105105        }
    106106
    107         $should_load = true;
    108         if (function_exists('wp_should_load_block_editor_scripts_and_styles')) {
    109             $should_load = wp_should_load_block_editor_scripts_and_styles();
    110         }
    111         if (!$should_load && !defined('SHUTTERPRESS_TESTING')) {
    112             return;
    113         }
    114 
    115107        wp_enqueue_style($this->plugin_name . '-public', SP_GALLERY_URL . 'includes/css/shutterpress-gallery-public.css', [], $this->version, 'all');
    116108
    117109        $vendor_base = SP_GALLERY_URL . 'includes/js/';
    118        
     110
    119111        wp_register_script('isotope', $vendor_base . 'isotope.pkgd.min.js', ['jquery'], '3.0.0', false);
    120112       
  • shutterpress-gallery/trunk/src/shutterpress-gallery-block/shutterpress-gallery-block-render.php

    r3378680 r3378879  
    1919$gallery_attributes = [
    2020    'gallery_id' => isset($attributes['galleryId']) && intval($attributes['galleryId']) !== 0 ? intval($attributes['galleryId']) : '',
     21   
     22    'post_id' => isset($attributes['postId']) ? intval($attributes['postId']) : (isset($_GET['post']) ? intval($_GET['post']) : (get_the_ID() ? intval(get_the_ID()) : 0)),
    2123    'use_lightbox' => isset($attributes['useLightbox']) ? filter_var($attributes['useLightbox'], FILTER_VALIDATE_BOOLEAN) : filter_var($defaults['use_lightbox'], FILTER_VALIDATE_BOOLEAN),
    2224    'layout' => isset($attributes['galleryLayout']) ? sanitize_text_field($attributes['galleryLayout']) : sanitize_text_field($defaults['layout']),
     
    3941
    4042        $gallery_attributes = is_array($gallery_attributes) ? $gallery_attributes : [];
    41         $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : 0;
     43        $gallery_id = isset($gallery_attributes['gallery_id']) ? (int) $gallery_attributes['gallery_id'] : -1;
    4244
    4345        if ($gallery_id === -1) {
    4446           
    45             $gallery_id = (int) get_the_ID();
    46             $gallery_attributes['gallery_id'] = $gallery_id;
     47            $context_post_id = 0;
     48
     49            if (!empty($gallery_attributes['post_id'])) {
     50                $context_post_id = (int) $gallery_attributes['post_id'];
     51            }
     52
     53            if ($context_post_id <= 0 && isset($_GET['post'])) {
     54                $context_post_id = (int) $_GET['post'];
     55            }
     56
     57            if ($context_post_id <= 0 && isset($GLOBALS['post']) && $GLOBALS['post'] instanceof \WP_Post) {
     58                $context_post_id = (int) $GLOBALS['post']->ID;
     59            }
     60
     61            if ($context_post_id <= 0) {
     62                $context_post_id = (int) get_the_ID();
     63            }
     64
     65            if ($context_post_id > 0) {
     66                $gallery_id = $context_post_id;
     67                $gallery_attributes['gallery_id'] = $gallery_id;
     68               
     69                $linked_gallery_id = 0;
     70                $candidate_meta_keys = ['sp_gallery_id', '_sp_gallery_id', 'shutterpress_gallery_id', '_shutterpress_gallery_id', 'sp_post_gallery_id', '_sp_post_gallery_id'];
     71                foreach ($candidate_meta_keys as $mk) {
     72                    $val = (int) get_post_meta($context_post_id, $mk, true);
     73                    if ($val > 0) {
     74                        $linked_gallery_id = $val;
     75                        break;
     76                    }
     77                }
     78               
     79                if ($linked_gallery_id > 0) {
     80                    $gallery_id = $linked_gallery_id;
     81                    $gallery_attributes['gallery_id'] = $gallery_id;
     82                    $gallery_attributes['post_id'] = $context_post_id;
     83                } else {
     84                   
     85                    $gallery_attributes['post_id'] = $context_post_id;
     86                }
     87            }
    4788        }
    4889
    49         if ($gallery_id <= 0) {
     90        if ($gallery_id <= 0 && empty($gallery_attributes['post_id'])) {
    5091            return '<div ' . \get_block_wrapper_attributes() . '></div>';
    5192        }
     
    5495
    5596        if (!$renderer) {
    56             if (!isset($renderers[$gallery_id])) {
    57                 $renderers[$gallery_id] = new Shutterpress_Gallery_Gallery($gallery_id);
     97            $cache_key = (int) ($gallery_id > 0 ? $gallery_id : $gallery_attributes['post_id'] ?? 0);
     98            if ($cache_key <= 0) {
     99                $cache_key = 0;
    58100            }
    59             $renderer = $renderers[$gallery_id];
     101            if (!isset($renderers[$cache_key])) {
     102               
     103                $renderers[$cache_key] = new Shutterpress_Gallery_Gallery($gallery_id > 0 ? $gallery_id : 0);
     104            }
     105            $renderer = $renderers[$cache_key];
    60106        }
    61107
     
    64110            $output = '<div ' . \get_block_wrapper_attributes() . '>';
    65111
    66             if (method_exists($renderer, 'get_gallery_images') && !empty($renderer->get_gallery_images())) {
    67                 if (defined('REST_REQUEST') && REST_REQUEST && 'edit' === $_GET['context']) {
    68                     $gallery_attributes['infinite_scroll'] = '0';
    69                     $gallery_attributes['use_lightbox'] = '0';
    70                 }
     112            if (defined('REST_REQUEST') && REST_REQUEST && isset($_GET['context']) && 'edit' === $_GET['context']) {
     113                $gallery_attributes['infinite_scroll'] = '0';
     114                $gallery_attributes['use_lightbox'] = '0';
     115            }
    71116
    72                 if (method_exists($renderer, 'set_attributes')) {
    73                     $renderer->set_attributes($gallery_attributes);
    74                 }
     117            if (method_exists($renderer, 'set_attributes')) {
     118                $renderer->set_attributes($gallery_attributes);
     119            }
    75120
     121            if (method_exists($renderer, 'set_post_id') && !empty($gallery_attributes['post_id'])) {
     122                $renderer->set_post_id((int) $gallery_attributes['post_id']);
     123            }
     124            if (method_exists($renderer, 'set_is_post_gallery') && isset($linked_gallery_id) && (int) $linked_gallery_id === 0 && !empty($gallery_attributes['post_id'])) {
     125                $renderer->set_is_post_gallery(true);
     126            }
     127
     128            $has_images = method_exists($renderer, 'get_gallery_images') ? (array) $renderer->get_gallery_images() : [];
     129
     130            if (!empty($has_images)) {
    76131                if (method_exists($renderer, 'get_buttons')) {
    77132                    $output .= $renderer->get_buttons();
  • shutterpress-gallery/trunk/vendor/composer/installed.php

    r3378680 r3378879  
    44        'pretty_version' => 'dev-master',
    55        'version' => 'dev-master',
    6         'reference' => 'ee154d9281e430a177064ec382dda47bc35fbef9',
     6        'reference' => '8a9aecb868d4d8701c7225e6220bc9f9a2e2e09e',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    3535            'pretty_version' => 'dev-master',
    3636            'version' => 'dev-master',
    37             'reference' => 'ee154d9281e430a177064ec382dda47bc35fbef9',
     37            'reference' => '8a9aecb868d4d8701c7225e6220bc9f9a2e2e09e',
    3838            'type' => 'wordpress-plugin',
    3939            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.