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

_global_head is being called 3 times - breaks have_fields_and_multi #111

Open
delicado54 opened this issue Oct 3, 2016 · 10 comments
Open

Comments

@delicado54
Copy link

delicado54 commented Oct 3, 2016

Using WP 4.6.1 and wpalchemy 1.6.1, I find that using have_fields_and_multi produces 3 new groups every time I click add (that is, $('[class*=docopy-]').click(function(e) on line 1354 seems to be being triggered 3 times even though I have only one item with a class of docopy-.... I assumed this was my error but I found it also happens with the out-of-the-box full-meta.php.

If I revert to 1.5.x or earlier, it works again, but I get a bunch of deprecation notices.

After a bit of digging around I realised that the javascript block is being printed out on the page 3 times - so it looks like the function _global_head() is being triggered 3 times.

It looks like I have a temporary fix by inserting e.stopImmediatePropagation(); on line 1356 after e.preventDefault(). But this might cause other issues and obviously isn't a real solution.

@delicado54 delicado54 changed the title have_fields_and_multi - add creates 4 new fields _global_head is being called 3 times - breaks have_fields_and_multi Oct 3, 2016
@delicado54
Copy link
Author

As suggested in the comment on line 460 ("// todo: when first run define a constant to prevent other instances from running again ..."), I was able to prevent this 3-times outputting with the following code:

if(!defined('HEAD_CALLED')): add_action( 'admin_head', array( $this, '_global_head' ) ); define('HEAD_CALLED', true); endif;

@stratboy
Copy link

Thank you very much @delicado54! I had the same issue and was able to fix swapping line 460 with yours. Should be a pull request.

@masterbip
Copy link

masterbip commented Mar 7, 2018

You have just saved my life. 5 days and this is the ONLY reference we got related to this repeating fields issue. Thanks!!!

BTW: This must be added to MetaBox.php original file

@stratboy
Copy link

stratboy commented Mar 7, 2018

BTW: I finally started using Advanced Custom Fields plugin. After several years of wpalchemy. I'll never go back. Since wpalchemy isn't maintained, I strongly suggest the switch to everyone. This is not a spot, just developer to developer help..

@delicado54
Copy link
Author

Glad to have helped, masterbip!

I also switched to Advanced custom fields over the past year. A bit of a departure to have the forms etc defined via a GUI and stored in the database, but it's a very powerful plugin!

@masterbip
Copy link

I try to avoid using plugins as much as possible, but I'll try that someday. Many thanks for the suggestion!

@stratboy
Copy link

stratboy commented Mar 7, 2018

Same here, but in this case, really, saying it's really well done is not enough...

And keep in mind that wpalchemy IS a plugin, indeed. And that you're now loosing time for the very same reason you probably fear plugins: dependency and reliability. So... :)

@farinspace
Copy link
Owner

With any piece of software comes maintenance, and as many have noticed, wpalchemy has gone unmaintained for a long time now (my apologies).

I think plugins are great, in most of my day-to-day dev, we use plugins .. publicly available (vetted and curated) and our own private ones. Again the idea here is maintenance and repeatable success.

While I enjoy solving problems, it is not fun to have to touch code for mundane tasks, plugins with decent UI's help solve this. So, I too encourage the use of plugins :-)

@delicado54
Copy link
Author

Dimas - many thanks for wp alchemy and all your work on it!

@rebecaescandon
Copy link

@delicado54 I added a Pull request with your suggestion, it's working on our project , thank you!
#120
@farinspace Could you please take a look? Thank you.

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

5 participants