wpalchemy icon indicating copy to clipboard operation
wpalchemy copied to clipboard

_global_head is being called 3 times - breaks have_fields_and_multi

Open delicado54 opened this issue 8 years ago • 10 comments

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 avatar Oct 03 '16 18:10 delicado54

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;

delicado54 avatar Oct 03 '16 19:10 delicado54

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.

stratboy avatar Oct 14 '16 15:10 stratboy

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

masterbip avatar Mar 07 '18 17:03 masterbip

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..

stratboy avatar Mar 07 '18 17:03 stratboy

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!

delicado54 avatar Mar 07 '18 17:03 delicado54

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

masterbip avatar Mar 07 '18 18:03 masterbip

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... :)

stratboy avatar Mar 07 '18 18:03 stratboy

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 :-)

farinspace avatar Mar 07 '18 18:03 farinspace

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

delicado54 avatar Mar 07 '18 18:03 delicado54

@delicado54 I added a Pull request with your suggestion, it's working on our project , thank you! https://github.com/farinspace/wpalchemy/pull/120 @farinspace Could you please take a look? Thank you.

rebecaescandon avatar Aug 27 '21 12:08 rebecaescandon