• I thought to inquire here opposed to Trello Board as others “may” chime in.
    I don’t know if this actually “extends” ACF but has been requested of ACF developer for 7 YEARS now and you would think would already be done without so many requesting for it. Flush Unused Custom Fields

    The issue is whenever you create a form, add fields, and submit data. Obviously ACF creates entries in the DB and populates with data.
    Now, when you (in WP admin) delete said form.. the DB entries AND data remain in the DB with NO way of deleting this data! Sure you can phpmyadmin or use Navicat and try and figure out where these numerous entries are (many have tried), but the way data is written to the DB and not knowing specifically where it is is a real problem!

    Now imagine developing a site and creating forms for a client while using all kinds of testing data, fake user names and all kinds of fake form fields / slugs. There could easily be hundreds or even thousands of entries depending on what you are developing!
    Can you imagine the DB bloat this causes?

    Now, when you pass this site onto client and realize ALL of that fake data / entries are still in the DB EVEN THOUGH you have deleted all of the test / development forms.
    And unlike many other well developed plugins that have a setting that when you delete the plugin it gives you the option to delete / clean up it’s data.

    Here is where we have asked for this basic functionality for 7 YEARS:

    https://support.advancedcustomfields.com/forums/topic/flush-unused-custom-fields/
    https://support.advancedcustomfields.com/forums/topic/how-to-flush-old-unused-custom-fields-on-database/

    The Response:

    Thanks for the topic. At the moment, there is no way for ACF to β€˜clean’ up the old data, but perhaps this is a good feature request I should add to the to-do.
    Maybe an admin menu page where you can search for unused values.

    So after 7 years, ACF still leaves your DB full of unused data and no clear and safe way to delete it.

    Is there an ACF Extended “tool” or “setting” that can be created to actually delete the data from DB when THAT form is deleted?

    • This topic was modified 4 years, 9 months ago by bernardberry646. Reason: grammar
    • This topic was modified 4 years, 9 months ago by bernardberry646. Reason: grammar
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    As you mentioned, this is an old topic in the ACF community. First, I would like to tell you that I totally understand your point here. I worked as a lead developer in a WordPress agency where we heavily relied on ACF for our clients websites, before going full-time on ACF Extended. So yeah, I experienced the examples you mentioned.

    TL:DR

    This feature will come in the next ACF Extended release, which introduce a new module called “Scripts UI”. This new module allows developers to run any kind of script on dozens/hundreds/thousands posts without server/DB restriction.

    The module is packed with 2 useful builtin scripts, which include a “Orphan Meta Cleaner”, as mentioned on the Trello Board.

    Additionally, note that it will be possible to clean orphan meta from each posts/terms/users/options pages individually, with the upcoming enhancement of the Developer Mode.

    Long story

    I also thought the same while developing websites with ACF, and while it looks insane that there is no native feature to do such operations, the more I worked on ACF Extended (and by extension the more I learnt from the ACF source code), the more I understood why it is not in the core, even after 7 years. I will try to explain the reasons, in my opinion, and I will try to not be too technical because this topic is related to many aspects of both ACF & WordPress logic. Before starting, some few notes:

    • Other plugins have similar logic and never clean post meta left behind
    • WordPress doesn’t provide any solution to make this operation easier
    • Deleting data is always a sensitive topic, as it can lead to unwanted data loss

    The first major issue here is that there is no way to deal with mass deletion in WordPress, as such operations depend on server limitation (allowed execution time, resources needed etc…). While it can be pretty easy to cleanup data on dozen of posts, it’s a completely different topic to do it on hundreds or thousands of posts. As explained earlier, the server will probably throw an error as the execution time will be reached pretty easily. You can try it by yourself, simply delete hundreds of posts at once from your admin UI, you’ll see that you’ll receive an error.

    In the case of ACF, a solution would be that if a user delete a field from a Field Group UI, and save the Field Group, ACF would go thru all Posts, Terms, Users, Options Pages, and look for the said field to delete it. This could lead to very heavy DB requests on large websites. To get around that problem, ACF could delegate that task into splitted background processes, so the deletion are made without the user even noticing it. But that solution is far more complex to implement, and WordPress doesn’t provide any native framework for such case.

    Assuming ACF goes that way, it would not be compatible with the Local Field Groups declaration which are widely used by advanced developers on large websites. If a developer delete a Local Field Group in PHP, ACF would not be aware of it, so it couldn’t launch the deletion process. To get around that problem, ACF could return the logic upside down, and start from the Posts, Terms, Users, Options Pages instead from the Field Group UI. But even there, it is facing a new issue, as metadata saved on each posts are tied to field groups, but not to the Field Group Location logic.

    For example, let’s say you create a Field Group on the Post Type “Post”. You create few blog posts with those new meta, and then decide to change the location of the Field Group and move it on the Post Type “Page”. The deletion would not work in that case since the field still exists in the Field Group, but isn’t valid on that specific “Post Type: Post” location. That means we have to add an another level complexity in the deletion process, and check if the field is supposed to be displayed on the blog post or not. Here there is a major issue, since ACF doesn’t have any way get the location validity of a field individually (this is due to internal logic of field group display, saving process etc…). On top of that we have to deal additional edge cases, like the Clone Field which allow to clone a Field Group that is independant of that “Location” validity logic, since any field that can clone anything (a field group with an another location rule, or an another field).

    Anyways, I won’t go deeper in the rabit hole, I think you understood it’s a really complex topic, and that’s probably why it’s not part of the core.

    I hope the answer will be informative for you, and any other ACF developer who come by πŸ™‚

    Have a nice day!

    Regards.

    Thread Starter bernardberry646

    (@bernardberry646)

    I totally get it! Except for two things:
    #1 You managed to do it (clean out orphaned data from the DB) with your script(s).. why couldn’t they do the same thing over 7 years? By the way, while watching your video on the Trello Board I noticed you can accomplish wayyyy more than just cleaning up orphaned data! I’m still in wow of being able to convert posts, users, taxs, even options meta into a SINGLE meta! I wish I had not seen that this early lol.. Brother PLEASE have these in the next patch!

    #2 Back to ACF, I see where WP Reset Pro creates just clones your tables and adds a 6 character prefix. Then it is able to do things like create byte for byte snapshots, allow you to return to a previous stage and alot more. My point is why (rhetorical) cant ACF do the same when a person wants to completely delete a field group?
    1. create a new table(s) of the non deleted field groups
    2. prefix the tables that the person wants to be deleted, and IF, like you said its a large amount of data, execute the deletion over time as to not error out.

    That way this non used data can then be sectioned off as prefixed entries / tables not affecting the site while the admin user is still working on the site. Even have a “confirmation” for the person “You are about to delete the field group XYZ, this will delete all entries / data / meta attached to it” maybe even list what is relying on THAT meta. I know that is a reach, but in 7 years time I’m sure that isn’t that difficult.
    Hell, even with the prefix on the tables method, one could even optionally ‘bring back’ those fields at a later time lol if they chose to not DELETE them but say TRASH them.

    But I do get what your saying, it is alot of work.. but for a premium plugin like ACF, I kinda expect it to clean up after itself especially in regards to the data it leaves behind all the while the average user not even knowing it.. what if it were sensitive data.

    I do sooo much look forward to your developer scripts!

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    1. Yes, as explained in my previous answer, this feature will come in the next patch. Also as you mentioned, Scripts UI is a fully-fleshed script launcher which goes far beyond the “Orphan Meta Cleaner” task alone. It could be a standalone plugin on its own. Writing a solution to perform recursive ajax requests for database maintenance is something I wanted in ACF Extended, but it’s not necessarily within the ACF bounds/vision. Each plugins authors decide to allocate their resources to the priority they define. Maybe the time spent on the DB Cleanup feature would have delayed other awesome ACF features.

    2. Comparing a plugin dedicated to DB Clone/Maintenance to ACF is a bit unfair. Managing database tables requires a lot of time/work/debug, especially in a environment where you deal with millions of users, retrocompatibility etc… Also, the solution you describe would not work with local PHP Field Groups as I explained earlier. So it would essentially make it a half-working feature. Which is never suitable since users will complain about it. If you decide to publish such feature, it must work with everything else in the plugin (well at least that’s my vision).

    Also note that premium/free plugins that are not specialized in DB maintenance/cleanup (in contrary of the WP Reset you mentioned) don’t clean posts meta they add, for the reasons I explained before. Maybe there’s some exceptions, but I don’t think I’ve ever found one.

    Finally I’ll would like to add that ACF is a very complex piece of software, and after spending countless sleepless nights in the source code, I can tell you that Elliot (yes, the ACF developer is alone) is one of the smartest developer I’ve ever seen. The amount of thinking/creativity/work that has been put in that plugin is simply insane. So if that feature isn’t in the core, that’s probably because of reasons that are beyond us. That’s something we must respect IMO.

    Regards.

    Thread Starter bernardberry646

    (@bernardberry646)

    @hwk-fr
    Understood.. well now that deliciousbrains now owns ACF this issue may finally get addressed πŸ™‚

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Yep, maybe πŸ™‚

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Feature Request – Free & Pro’ is closed to new replies.