PHP 8.3+ error for gallery block
-
Bug Description
When attempting to transition from the legacy Document Gallery shortcode to the new Document Gallery Gutenberg Block, the site throws a PHP Fatal TypeError.
This happens because the block editor passes taxonomy data as a
stdClassobject instead of a comma-separated string to thesetTaxa()method, which strict PHP 8.3 types reject when handled byexplode(). Environment- WordPress Version: 7.0
- PHP Version: 8.3.x
- Plugin: Document Gallery
Steps to Reproduce
- Ensure the site is running PHP 8.3+.
- Edit a page/post and add the Document Gallery Block (or convert an existing shortcode to the block).
- Attempt to render or preview the block.
Error Log / Stack Trace
[24-Jun-2026 22:38:23 UTC] PHP Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, stdClass given in /public_html/wp-content/plugins/document-gallery/src/inc/class-gallery.php:338
Stack trace:
#0 /public_html/wp-content/plugins/document-gallery/src/inc/class-gallery.php(338): explode(',', Object(stdClass))
#1 /public_html/wp-content/plugins/document-gallery/src/inc/class-gallery.php(270): DG_Gallery->setTaxa(Array)
#2 /public_html/wp-content/plugins/document-gallery/src/inc/class-gallery.php(244): DG_Gallery->getAttachments()
#3 /public_html/wp-content/plugins/document-gallery/src/inc/class-document-gallery.php(26): DG_Gallery->__construct(Array)
#4 /public_html/wp-content/plugins/document-gallery/document-gallery.php(149): DocumentGallery::doShortcode(Array)
#5 /public_html/wp-includes/class-wp-block.php(596): document_gallery_block_render_callback(Array, '', Object(WP_Block))
#6 /public_html/wp-includes/blocks.php(2438): WP_Block->render()
#7 /public_html/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php(191): render_block(Array)
#8 /public_html/wp-includes/rest-api/class-wp-rest-server.php(1287): WP_REST_Block_Renderer_Controller->get_item(Object(WP_REST_Request))
#9 /public_html/wp-includes/rest-api/class-wp-rest-server.php(1120): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wp/v2/block-re...', Array, NULL)
#10 /public_html/wp-includes/rest-api/class-wp-rest-server.php(435): WP_REST_Server->dispatch(Object(WP_REST_Request))
#11 /public_html/wp-includes/rest-api.php(471): WP_REST_Server->serve_request('/wp/v2/block-re...')
#12 /public_html/wp-includes/class-wp-hook.php(341): rest_api_loaded(Object(WP))
#13 /public_html/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters('', Array)
#14 /public_html/wp-includes/plugin.php(570): WP_Hook->do_action(Array)
#15 /public_html/wp-includes/class-wp.php(418): do_action_ref_array('parse_request', Array)
#16 /public_html/wp-includes/class-wp.php(821): WP->parse_request('')
#17 /public_html/wp-includes/functions.php(1343): WP->main('')
#18 /public_html/wp-blog-header.php(16): wp()
#19 /public_html/index.php(17): require('/...')
#20 {main}
thrown in /public_html/wp-content/plugins/document-gallery/src/inc/class-gallery.php on line 338Technical Context from Gemini
In
src/inc/class-gallery.phpon line 338, the code assumes$termsis a string:$terms = $this->getTermIdsByNames( $taxon, explode( ',', $terms ) );The developer likely needs to add a type-check or cast
$termsbefore running it throughexplode()when it’s being invoked viadocument_gallery_block_render_callback.
I was able to switch back to the shortcode as a temporary measure, but wanted to notify you about the problem.
You must be logged in to reply to this topic.