Support

Account

Home Forums General Issues Documentation to create fields with php code

Solving

Documentation to create fields with php code

  • Hi !

    I’m working on a WordPress Site As A Service (SASS) and I need to have a few custom fields available on all my subsites (WordPress Multisite). As the number of subsites will increase fast because visitors will be able to create their website in a few clicks, I can configure the same custom fields for each subsite. As each subsite can choose between a few themes, I don’t want to put the php code to generate the fiels directly in functions.php because I’ll have to copy/paste the php in each new theme.

    So I figure that the best way is to create a plugin that will be activated for the entire network. In this plugin, I’ll put the php code that will create my advanced custom fields. Are is that right ? Do you agree with the principle ?

    If yes, is it possible to have a documentation that explains us how to programmatically create each type of ACF custom fields and group of fields ? I don’t want to createthe field/group of fields inside the admin of a site and then export the code and copy/paste the piece of code in my plugin…

    This also could help developers…

    Thanks a lot,
    Cédric

  • “…I don’t want to create the field/group of fields inside the admin of a site and then export the code and copy/paste the piece of code in my plugin…”

    I think that is basically what you need to do. I’ve created a few plugins that use ACF fields. You use the function register_field_group() …

    Which I’m suddenly not finding any documentation on, I’m sure it used to be around here somewhere…

    you call this function on the action hook “acf/register_fields”… which I’m also not finding any documentation on.

    You could type out the array for the field group by hand, but it would be much easier to use ACF to create the fields and export the PHP code to copy into your plugin.

    But in the documentation that I can’t find it outlined the steps.

    
    add_action('acf/register_fields', 'my_register_fields_function');
    function my_register_fields_function() {
      if (function_exists('register_field_group')) {
        // use the field group you export from ACF for $my_field_group
        $my_field_group = array();
        register_field_group($my_field_group);
      }
    }
    
  • Hi @Hube2 !

    Thanks for your answer.

    I know I have to use the “register_field_group” function and the action “acf/register_fields”. What I’m asking here is a documentation that give us information about creating manually (through code) each type of field.

    Because I’m creating a SAAS where all the fields have to be created through a plugin which will be available on all subsite, I can’t (and don’t want to) use the front-end method.

    Thanks,
    Cédric

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Documentation to create fields with php code’ is closed to new replies.