diff --git a/easy-image-gallery.php b/easy-image-gallery.php index a03e4f8..b4f9522 100644 --- a/easy-image-gallery.php +++ b/easy-image-gallery.php @@ -3,7 +3,7 @@ Plugin Name: Easy Image Gallery Plugin URI: https://devrix.com/ Description: An easy to use image gallery with drag & drop re-ordering -Version: 1.5.4 +Version: 1.5.5 Author: DevriX Author URI: https://devrix.com/ Text Domain: easy-image-gallery diff --git a/includes/metabox.php b/includes/metabox.php index bdf9df4..40087d7 100644 --- a/includes/metabox.php +++ b/includes/metabox.php @@ -100,7 +100,7 @@ function easy_image_gallery_metabox() { $get_galleries = array( array( array( - 'SHORTCODE' => wp_rand( 100, 999 ), + 'SHORTCODE' => (string) wp_rand( 100000, 999999999 ), 'DATA' => $get_gallery_old_data, 'OPEN_IMAGES' => $get_open_images[0], ), @@ -110,8 +110,21 @@ function easy_image_gallery_metabox() { $gallery_count = -1; if ( isset( $get_galleries ) && ! empty( $get_galleries ) ) { + $existing_shortcodes = array(); + foreach ( $get_galleries[0] as $gallery ) { $gallery_count = $gallery_count + 1; + + $gallery_shortcode = easy_image_gallery_sanitize_gallery_id( $gallery['SHORTCODE'] ); + if ( '' === $gallery_shortcode || in_array( $gallery_shortcode, $existing_shortcodes, true ) ) { + do { + $candidate = (string) wp_rand( 100000, 999999999 ); + } while ( in_array( $candidate, $existing_shortcodes, true ) ); + + $gallery_shortcode = $candidate; + } + + $existing_shortcodes[] = $gallery_shortcode; $get_attachments = $gallery['DATA']; // Convert attachements to string @@ -139,8 +152,8 @@ function easy_image_gallery_metabox() { Insert this shortcode in the content - - "> + + ">