Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
philbirnie opened this issue Mar 26, 2021 · 3 comments
Assignees

Comments

@philbirnie
Copy link

philbirnie commented Mar 26, 2021

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.

@philbirnie philbirnie changed the title Unable to add a single import_images field. Unable to add a single import_images field without AddOn creating two sections. Mar 26, 2021
@joeguilmette
Copy link
Member

@cmdmcs

@cmdmcs
Copy link
Contributor

cmdmcs commented Apr 17, 2021

@philbirnie I was not able to replicate this with provided piece of code. Could you share the full code of the add-on you creating?

@cmdmcs
Copy link
Contributor

cmdmcs commented Apr 17, 2021

I understand the problem. I gave the same names the add-on and images section. So, this is expected behavior.

From the screenshots I see that first section - it's the add-on main section. It is named 'Variant Images' because it's how you named the add-on in this part:

$this->add_on = new RapidAddon( 'Variant Images', 'variant_gallery' );

The second section - it is images section and it is named 'Variant Images' because you gave it this name here:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants