Skip to content

Unable to add a single import_images field without AddOn creating two sections. #38

@philbirnie

Description

@philbirnie

Problem

I am unable to add a single Import Images field without the add-on creating an superfluous section above -- for example, this code:

		$this->add_on = new RapidAddon( 'Variant Images', 'variant_gallery' );
		$this->add_on->import_images( 'variant_gallery', 'Variant Images', 'images', [ $this, 'variant_images' ] );

Renders two sections that both say "Variant Images."

Screen Shot 2021-03-26 at 1 21 26 PM

The first contains the following error (because there not any fields associated with it):

Warning: Invalid argument supplied for foreach() in [[PATH]]/rapid-addon.php on line 425
Warning: Invalid argument supplied for foreach() in [PATH]]/rapid-addon.php on line 432 

The second section renders correctly with the proper image settings as shown in the screenshot above.

To Solve

I have modified the code at line 420 to check if fields exist before adding the section, and this correct the issue i.e.:

			if($this->fields) {
				echo $this->helper_metabox_top($this->name);

				$visible_fields = 0;

				foreach ($this->fields as $field_slug => $field_params) {
					if ($field_params['is_sub_field']) continue;
					$visible_fields++;
				}

			...
			}

However, if I am using the API incorrectly to add the images field, please let me know.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions