I have recently updated my Wordpress sites to PHP 8.1 — and I have run into a problem with a plugin that I am using on several sites. The plugin is no longer being actively maintained – but I would like to keep it, and I think the problem is fixable, but I don’t have the coding skill needed to do it.
Here’s the issue – I’m seeing this error:
PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in [name of file]:250
Here is the code section of the file that throwing the error:
public function additional_fields_meta_box_output( $post ) {
$values = $this->get_additional_field_values( $post->ID );
$names = simple_links()->get_additional_fields();
if ( is_array( $names ) ) {
foreach ( $names as $key => $value ) {
if ( empty( $values[ $value ] ) ) {
[250] $values[ $value ] = null;
}
printf(
'<p>%s: <input type="text" name="%s[%s]" value="%s" size="70" class="SL-additonal-input">',
esc_html( $value ),
esc_attr( self::ADDITIONAL_FIELDS ),
esc_attr( $value ),
esc_attr( $values[ $value ] )
);
}
}
if ( isset( $this->meta_box_descriptions['additional_fields'] ) ) {
echo '<p>' . wp_kses( $this->meta_box_descriptions['additional_fields'], array( 'code' => array() ) ) . '</p>';
The line throwing the error is #250 (noted above)
So basically, PHP 8.1 wants to see something different than null.
The code is creating meta boxes that can be edited with extra information on the back end; everything is still working on the front end, but the error is generated on the edit screen for the post type created by this plugin.
So if anyone can suggest specific changes I can make to the code to fix this… I would be very appreciative.