Make WordPress Core

Opened 8 years ago

Last modified 3 months ago

#44394 new defect (bug)

Error when trying to get the columns of a three-columns gallery.

Reported by: virginthumb's profile virginthumb Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.6
Component: Gallery Keywords: has-patch changes-requested reporter-feedback
Focuses: Cc:

Description

It seems the get_post_gallery function fails to retrieve the column count if it's 3.

First, create a gallery. Then, insert 2 or 3 or any number of images and set its column to 3.

Then, run this code in the context of a post (content.php / single.php will do):

<?php
$gallery = get_post_gallery( $post->ID, False );
$gallery_images = explode( ',', $gallery['ids'] );
var_dump( $gallery['columns'] );

It will come out as:

<b>Notice</b>:  Undefined index: columns in <b>C:\file.php</b> on line <b>45</b>

Attachments (1)

patch.diff (505 bytes) - added by saimonh 8 years ago.

Download all attachments as: .zip

Change History (4)

#1 @virginthumb
8 years ago

Big update.

Turns out this bug only happens when there are 2 galleries. Removing the second gallery fixes it, but still, get_post_gallery should get the first / "featured" gallery only.

Version 0, edited 8 years ago by virginthumb (next)

#2 @saimonh
8 years ago

  • Keywords has-patch added; needs-patch removed
  • Severity changed from minor to normal
  • Version set to 4.9.6

Yes, I can confirm this bug and have included a patch for this issue. Please have a look.

@saimonh
8 years ago

#3 @ozgursar
3 months ago

  • Keywords changes-requested reporter-feedback added; needs-testing removed

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://core.trac.wordpress.org/attachment/ticket/44394/patch.diff

Environment

  • WordPress: 7.0-alpha-61215-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 143.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-One 2.7
  • MU Plugins: None activated
  • Plugins:
    • Classic Editor 1.6.7
    • Test Reports 1.2.1

Steps to Reproduce

  1. Install and active classic editor
  2. Add a new post
  3. Create a gallery with 3 images and choose 3 columns
  4. Add the following snippet to single.php
$gallery = get_post_gallery( $post->ID, False );
$gallery_images = explode( ',', $gallery['ids'] );
var_dump( $gallery['columns'] );

Actual Results

  1. ❌ Issue did not resolve with patch.

Additional Notes

  • When I test the use case code provided by the reporter, I get the same error before and after applying the patch.

Supplemental Artifacts

Before applying patch:
https://i.imgur.com/ZmBwdbD.png

https://i.imgur.com/RTpYWEQ.png

https://i.imgur.com/A6Xsktx.png

After applying patch:
https://i.imgur.com/AX1tkRA.png

Note: See TracTickets for help on using tickets.