Just getting involved with ACF Pro.
Quick summary of scenario… Looking to build a premium theme; therefore, meaning as the theme gets used, multiple customers will obviously have this and I am looking about setting things up right from the get-go so that I reduce any issues and time when I release future theme updates.
With that being said, I will be using Flexible Content as “content blocks” kinda like a page builder. Let’s say though in my next theme update, I want to add 3 new layouts to the Flexible Content I have already setup. How do I go about getting these to show when the theme update is being done on the customer websites? I do not want to have a solution that required me to do something manually on a site by site basis. Want to somehow implement that into the update. Thoughts?
Also, if I need to change an existing layout setting (not the field_name), how do I apply these changes? Will it impact the value already save by the customer?
Lastly, with this approach above for using Flexible Content, is there a template feature I can use with it? Where I have a few example pages made already and they can easily create the page from that.
Thanks in advance
Have to looked at this feature of ACF Pro https://www.advancedcustomfields.com/resources/local-json/
ACF can save the field groups as JSON files that can be automatically loaded. JSON files can be loaded from multiple places, for example if you don’t want the person that purchases the them to have the ability to alter them in the ACF interface. They can also be loaded manually, as an example you can look at this https://github.com/Hube2/ssi-standard-features/blob/master/acf-loader.php. I have this set up so that I can work on the field groups on my dev site in the ACF admin. I then copy the JSON files into my plugin. The loader will load the field groups only if they are not already defined, which means on my dev site the JSON files are ignored and on sites where I have the plugin install the JSON files are loaded.
Changing settings is a little more difficult, if the field is not backwards compatible. Some examples: If you change the default value this could alter the way that it work. Altering the field type would be a problem. Or changing the values so that something that could be selected in the paste is no longer possible. There is nothing in ACF that will automatically update old values to new values. If this is something that needs to be done then you’d need to build an update function that takes care of the details.
Creating default pages that can be modified is something else that you need to do on your own. You’ll need to create a theme activation action that checks for and/or inserts the posts into WP and adds all the necessary values to the ACF fields.
Thanks for the thorough explanation John!
For the loader you brought up, this means on my dev version I add say 3 new layouts and get the JSON file for that Flexible Content, I can then put that JSON file into the client’s JSON folder (which would be a child theme of my premium theme) and the loader will ignore all the existing field_names and add only the new layouts? Please confirm, as I would hate for their values they saved to be replaced with my dev values.
Lastly, on the template inquiry. To make sure I stated it right. I was hoping to have a way that I can easily populate the ACF Flexible Content fields of a page from an example I have already done. Therefore, have layouts already completed in the order and values I pre-determined. This is merely to save me or them from having to select the layouts and values to match my example page.
If you’re going to have a parent/child theme layout, if this was me I’d actually put the JSON in the parent theme and either add a load location or load them manually. But that would be your call. I personally think the less code that’s needed in a child theme the better.
If there is already and existing page to use as an example you could use ACF to get the values from a “Template” post and insert them into the new post when it’s created. Or you could output all of the values from a “Template” post and hard code them into an array and then use that array to generate a new post. To be honest there’s a lot of ways that something like this could be done, but I don’t think there is any automatic way to copy everything from one post to another when a new post is created… well, there is, but nothing that I know of that can be called from code when someone clicks on “Add New” https://wordpress.org/plugins/duplicate-post/
I was thinking about your template question some more. You can do all this by setting default values for most fields, and for things like repeaters and flex fields you can use acf/load_field and acf/load_value filters to dynamically generate default rows and content. There have been questions here on these forums about doing this.
Thanks John, you have been very helpful!
For the template, I was hoping for something maybe along the lines of exporting the setup on a particular page setup and then merely importing it on a different install. Would this not be similar to the JSON feature?
You could probably do something like that. Maybe you should look into that plugin and how they do it. Like I said, there’s nothing that I know of that will let you automatically insert data when someone clicks the “Add New” link in WP and there’s nothing build into ACF that will let you do this. Whatever that plugin or theme is doing is doing it using code to add the values.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.