Closed BAProductions closed 5 months ago
Hi, please update your original post to include the details necessary to evaluate your issue.
For example, the code referenced in the warning message you provided does not align with the latest release (v2.9.3). Ensuring you are using the latest release is recommended, as it may include fixes for issues in older versions.
Also, SLB_Lightbox::activate_galleries()
is currently only used with WordPress' get_post_galleries()
function, which passes an array
to this function. The warning message you provided indicates that a string
is being passed to this function, which sounds like something else may be going on as well.
Hi, please update your original post to include the details necessary to evaluate your issue.
For example, the code referenced in the warning message you provided does not align with the latest release (v2.9.3). Ensuring you are using the latest release is recommended, as it may include fixes for issues in older versions.
Also,
SLB_Lightbox::activate_galleries()
is currently only used with WordPress'get_post_galleries()
function, which passes anarray
to this function. The warning message you provided indicates that astring
is being passed to this function, which sounds like something else may be going on as well.
Can I post my gallery override code to see if it's the cause of the bug?
Sure, in addition to the previously-requested details, please include any other details that you think may be helpful in evaluating your issue.
Replace this: // Check galleries for HTML output
$gallery = reset( $galleries );
if ( is_array( $gallery ) ) {
return $galleries;
}
With this:
// Check galleries for HTML output
if ( is_array( $galleries ) ) {
return reset($galleries);
}
Fixes this: Warning: reset() expects parameter 1 to be array, string given in /home/wwd/public_html/WP_Portfoilo/wp-content/plugins/simple-lightbox/controller.php on line 681
But Then again I'm using gallery_shortcode to render the gallery in place of the post thumbnail for post format gallery / image & the function activate_galleries is complaining, because gallery_shortcode & my gallery code are not sending an array of gallery. reather 1 gallery per post.
**<?php**
**if**( !defined('ABSPATH') ){
**die**('You cannot be here');
}
**class** WPG_Slider_Gallery_Override {
public **function** init() {
add_filter('post_gallery', **array**($this, 'wpg_gallery_override'), 10, 99999);
}
public **function** wpg_gallery_override($output, $attr) {
_// Retrieve the post object_
$post = get_post();
_// Increment the instance counter_
**static** $instance = 0;
$instance++;
_// Determine 'ids' attribute_
$include_ids = !**empty**($attr['ids']) ? explode(',', $attr['ids']) : '';
_// Determine 'size' attribute_
$size = !**empty**($attr['size']) ? $attr['size'] : 'medium';
$speed = 'data-wpgs-ap-speed="' **.** get_option('wpgs_ap_speed', 6000) **.** '"';
$auto_play = 'data-wpgs-auto-play="' **.** get_option('wpgs_enabled_auto_play','true') **.**'"';
_// Start building the gallery markup_
$gallery_markup = '<div id="wpg-slider-' **.** esc_attr( $instance ) **.** '" class="wpg-slider" ' **.** $speed **.** ' ' **.** $auto_play **.** ' style="background-color: ' **.** esc_attr( wpgs_get_bg_color() ) **.** '; color: ' **.** esc_attr( wpgs_get_text_color() ) **.** ';">';
$gallery_markup **.**= '<section class="wpg-slider-items">';
_// Loop through each attachment and generate markup_
**foreach** ($include_ids **as** $id) {
$image_description = wp_get_attachment_caption($id);
_// Construct the image output_
$image_output = '<figure id="wpg-slider-item-' **.** esc_attr($id) **.** '" class="wpg-slider-item">';
$image_output **.**= '<a ' **.** wpgs_get_gallery_image_link($id, $attr['link']) **.** ' class="wpg-slider-item-inner">';
_// Construct the <img> tag properly with escaped attributes, including width, height, alt, title, and sizes_
$image_output **.**= wpgs_get_attachment_image($id, $size);
**if** (!**empty**($image_description) && trim($image_description)) {
$image_output **.**= '<figcaption class="wpg-slider-content" style="background-color: ' **.** esc_attr(wpgs_get_content_bg_color()) **.** '; color: ' **.** esc_attr(wpgs_get_text_color()) **.** ';" title="' **.** esc_attr($image_description) **.** '">';
$image_output **.**= esc_html($image_description);
$image_output **.**= '</figcaption>'; _// .wpg-slider-content_
}
$image_output **.**= '</a>';
$image_output **.**= '</figure>';
_// Append the image output to the gallery markup_
$gallery_markup **.**= $image_output;
}
_// Close the slider items wrapper_
$gallery_markup **.**= '</section>';
_// Add slider controls if $include_ids > 1_
**if** (count($include_ids) > 1) {
$gallery_markup **.**= '<nav class="wpg-slider-controls">';
$gallery_markup **.**= '<div class="wpg-slider-button wpg-slider-button-previous" aria-label="' **.** esc_attr__( 'Previous Slide', 'your-text-domain' ) **.** '" title="' **.** esc_attr__( 'Previous Slide', 'your-text-domain' ) **.** '" alt="' **.** esc_attr__( 'Previous Slide', 'your-text-domain' ) **.** '">';
$gallery_markup **.**= '<i class="wpg-slider-arrow wpg-slider-arrow-left" aria-hidden="true"></i>';
$gallery_markup **.**= '</div>';
$gallery_markup **.**= '<div></div>';
$gallery_markup **.**= '<div class="wpg-slider-button wpg-slider-button-next" aria-label="' **.** esc_attr__( 'Next Slide', 'your-text-domain' ) **.** '" title="' **.** esc_attr__( 'Next Slide', 'your-text-domain' ) **.** '" alt="' **.** esc_attr__( 'Next Slide', 'your-text-domain' ) **.** '">';
$gallery_markup **.**= '<i class="wpg-slider-arrow wpg-slider-arrow-right" aria-hidden="true"></i>';
$gallery_markup **.**= '</div>';
$gallery_markup **.**= '</nav>';
}
$gallery_markup **.**= '</div>';
**if** (function_exists('slb_activate')) {
_// Return the final gallery markup_
**return** slb_activate($gallery_markup);
} **else** {
_// Return the final gallery markup_
**return** $gallery_markup;
}
}
}
$wpg_slider_gallery_override = **new** WPG_Slider_Gallery_Override();
$wpg_slider_gallery_override->init();
Also dactiving my plugin, dos not fix the error. Error show regardless of my gallery override plugin.
Hi, the previously-requested details have not yet been provided. Please update your original post to include the necessary details for your issue to be evaluated further.
Replace this: // Check galleries for HTML output
$gallery = reset( $galleries ); if ( is_array( $gallery ) ) { return $galleries; }
With this:
// Check galleries for HTML output if ( is_array( $galleries ) ) { return reset($galleries); }
Fixes this: Warning: reset() expects parameter 1 to be array, string given in /home/wwd/public_html/WP_Portfoilo/wp-content/plugins/simple-lightbox/controller.php on line 681
Those two code snippets do completely different things and would break get_post_galleries()
as it sends invalid data back to it.
Also, the WPG_Slider_Gallery_Override
code you provided does not appear to be valid PHP (many invalid characters, etc.). Please update that comment with valid PHP so that it can be evaluated. Make sure to copy the code from a standard plain text editor to avoid any formatting characters from being included.
Also dactiving my plugin, dos not fix the error. Error show regardless of my gallery override plugin.
If the error persists after deactivating your override code, then another plugin may be supplying invalid data to the get_post_galleries
filter. Here are instructions for identifying plugins/themes causing conflicts.
This ticket has been closed due to inactivity. If you are still experiencing this issue, please provide the previously-requested details and I would be glad to reopen the ticket and take a look.
@archetyped uninstalling & reinstalling the plugin fixed the error.
Description of Problem
Warning: reset() expects parameter 1 to be array, string given in /home/wwd/public_html/WP_Portfoilo/wp-content/plugins/simple-lightbox/controller.php on line 681
Warning: Invalid argument supplied for foreach() in /home/wwd/public_html/WP_Portfoilo/wp-content/plugins/simple-lightbox/controller.php on line 688
(Clearly describe the issue you are experiencing here, and fill in the necessary details below)
Details