soderlind / acf-field-date-time-picker

Date and Time Picker field for Advanced Custom Fields v3 and v4
GNU General Public License v2.0
65 stars 27 forks source link

After acf Update class acf_field_date_time_picker is declared more than once #103

Closed sixmonkey closed 8 years ago

sixmonkey commented 8 years ago

I just updated Adavanced Custom Fields to version 5.3.9 and get the following error: Cannot redeclare class acf_field_date_time_picker in content/plugins/acf-field-date-time-picker/date_time_picker-v5.php on line 0.

danielsteginga commented 8 years ago

Hi,

I have the same problem on multiple websites right now. Also after updating ACF Pro.

ozziexsh commented 8 years ago

+1, brought a few of our sites down.

Ours says line 405 though, which happens to be just the closing brace of the class. However the new acf_field_date_time_picker(); is next a few lines down.

Perhaps the file is being included more than once somewhere?

danielsteginga commented 8 years ago

ACF Pro added a Date Time field, which uses the same name: https://www.advancedcustomfields.com/resources/date-time-picker/ I think that could be (part of) the problem

DTChristie commented 8 years ago

I have the same problem with ACF 5.3.9. It would be good to know how compatible the ACF version and the Soderlind version are, particularly concerning date/time conversions! Unfortunately there doesn't seem to be anything noted on the ACF website, even about the name clash!

garretthyder commented 8 years ago

Hey Guys,

So far so good on disabling the plugin before update, seems the field types are all mapped identically in the ACF update so the plugin isn't needed any longer. Done on two sites now without issues.

Steps;

  1. Deactivate Date Time Add-on plugin
  2. Update ACF
  3. Delete Date Time Add-on plugin
  4. Check field groups and front end for issues.

Hope that allays any fears with dropping it. Appears the data is stored in the same format so nothing gets lost on transition.

Cheers

DTChristie commented 8 years ago

HIya

I got the following response from Elliott (ACF):

Hi David

Thanks for the email.

I've just installed this 3rd party plugin and can see this error when active:

Fatal error: Cannot redeclare class acf_field_date_time_picker in /Users/elliotcondon/Dropbox/Work/Sites/acf5/wp-content/plugins/acf-field-date-time-picker/date_time_picker-v5.php on line 405

The plugin author has not wrapped his class definition within an if statement, and has used a class name exactly like ACF would. This is why we have ended up using the same name and the error occurs.

In theory you should be able to deactivate the 3rd party field type plugin, edit your field groups and change the existing field types to the new ACF date_time or time picker fields.

ACF saves the values to the DB in the most standardized format: YYYY-MM-DD hh:ii:ss

If the existing plugin saved in a similar format, the 2 should be completely compatible and no change will occur to your website.

Thanks, Elliot | Influx http://influx.com/?utm_source=customer&utm_medium=email&utm_campaign=acf support@advancedcustomfields.com mailto:support@advancedcustomfields.com

It’s a little bit naughty to complain that the Third Party plugin, which has filled this gap well for quite some time and was even advertised in the past by ACF, clashes with the new field type that ACF has only just added! Anyhow, it seems that the built-in field type should (more or less) work compatibly as mentioned by Garrett.

Cheers, David

From: Garrett Hyder [mailto:notifications@github.com] Sent: Mittwoch, 15. Juni 2016 18:24 To: soderlind/acf-field-date-time-picker acf-field-date-time-picker@noreply.github.com Cc: DTChristie david@thechristies.ch; Comment comment@noreply.github.com Subject: Re: [soderlind/acf-field-date-time-picker] After acf Update class acf_field_date_time_picker is declared more than once (#103)

Hey Guys,

So far so good on disabling the plugin before update, seems the field types are all mapped identically in the ACF update so the plugin isn't needed any longer. Done on two sites now without issues.

Steps;

  1. Deactivate Date Time Add-on plugin
  2. Update ACF
  3. Delete Date Time Add-on plugin
  4. Check field groups and front end for issues.

Hope that allays any fears with dropping it. Appears the data is stored in the same format so nothing gets lost on transition.

Cheers

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/soderlind/acf-field-date-time-picker/issues/103#issuecomment-226241357 , or mute the thread https://github.com/notifications/unsubscribe/AGbxbFRFAmTjyCwd-Pr8etUfqp-zjrzzks5qMCcVgaJpZM4I1Esi . https://github.com/notifications/beacon/AGbxbK7GH6v9ZEUQyiwq8cYVgkmeM0tlks5qMCcVgaJpZM4I1Esi.gif

petertwise commented 8 years ago

It’s a little bit naughty to complain that the Third Party plugin, which has filled this gap well for quite some time and was even advertised in the past by ACF, clashes with the new field type that ACF has only just added!

Totally agree. There's only a handful of great 3rd party plugins that are popular and really filling gaps in ACFs existing functionality. The ACF team should be aware of them and plan for compatibility when they release similar functionality.

petertwise commented 8 years ago

ACF support forums just sent me this:

Hi @squarecandy

The ACF date time picker plugin is not supposed to be used with the newest version of ACF as it has the similar feature. It’s the same as the premium add-ons that are not supposed to be used with the PRO version. So you should disable that add-on to get the date time picker field working correctly.

That being said, I guess the plugin author forgot to add a compatibility with the old add-on. Could you please open a new ticket so it can be passed directly to the plugin author? You can open it here: https://support.advancedcustomfields.com/new-ticket.

Thanks 🙂

Please open a ticket if you have a pro ACF account and ask them to add compatibility with https://wordpress.org/support/plugin/acf-field-date-time-picker and to consider compatibility with 3rd party plugins that fill current gaps in ACF when launching new features in the future.

elliotcondon commented 8 years ago

HI guys

Elliot here - ACF dev.

Firstly, allow me to apologize for any downtime you have experienced due to this PHP error. Please know it is never my intention to break any functionality or website. My intention is the complete opposite, to help web developers make awesome websites easier.

The issue here is that both ACF PRO and acf-field-date-time-picker are using the same class name for the field type. This is just pure coincidence.

@soderlind - please consider wrapping your field class in an if statement to prevent such an issue. This will help prevent this issue occurring on future updates. For example:

if( ! class_exists('acf_field_date_time_picker') ) :
class acf_field_date_time_picker extends acf_field {

}
endif;

Please note that the field classes within ACF PRO are all wrapped in if statements.

I'll consider changing the field class name from my end to fix this issue temporarily, however, this may cause the same issue with another existing 3rd party field type (unlikely but possible).

Unfortunately, these kinds of errors will happen from time to time, and are not malicious, but just an accident between 2 individual codes.

Let me know if you have any feedback or ideas for a solution.

elliotcondon commented 8 years ago

Hi guys,

Just an update on this issue. I've gone ahead and changed the class name from 'acf_field_date_time_picker' to 'acf_field_date_and_time_picker'. This should completely avoid the collision and fix the issue.

I've also checked for other date time field types and this change shouldn't conflict with others.

@soderlind - it would still be great if you could add in a conditional check around your field type. Check out another date time picker class here for an example: https://wordpress.org/plugins/acf-date-time-picker/. This would allow me to change the class name back in the future (say in 6 months) when there is little chance of the conflict occurring.

Thanks again for your help notifying me of the issue. Hope everything else runs super smoothly from here on out.

Thanks E

garretthyder commented 8 years ago

Note: To those who did update to the ACF version and dropped this plugin. Beware if you were using the Time Picker and storing in linux time format then you'll have to update all that information as the new Time Picker type added by ACF doesn't support that format. @elliotcondon Can ACF Time Picker be updated to pick up linux time so as to support this data? Thanks

elliotcondon commented 8 years ago

Hi @garrett-eclipse

Thanks for the reply. Yes, I've added in compatibility with unix timestamp values. The date, datetime and time pickers will now be able to load and format previous values as expected.

Please re-download the plugin to make sure you have the latest code. I'll reply back soon with a new documentation link on how to redownload the ACF PRO plugin

garretthyder commented 8 years ago

Thanks @elliotcondon that's awesome, seems we're in clear waters now so should be smooth sailing from here on. I appreciate the update. Enjoy your weekend.

ethanclevenger91 commented 8 years ago

Just a note, if you need to update existing database values to MySQL style datetime rather than have ACF save out the datetime in UNIX, the following query should get you started:

UPDATE wp_postmeta SET meta_value = FROM_UNIXTIME(meta_value) WHERE meta_key = "acf_field_slug"

Might also consider AND meta_value != '' if you had it set to optional. If you've already added new events that are in the correct format, use AND post_id < x to prevent it from touching those, as it'll fail trying to format them.

The above implied that you could have it save to the database in Unix, but I'm not finding that to be the case. It'll return unix, but still goes into the database as MySQL datetime. Correct me if I'm wrong.

soderlind commented 8 years ago

The lastest release fixes the compatibility problems with ACF PRO, ie: