Support

Account

Home Forums Add-ons Options Page Combine Two PHP Scripts Reply To: Combine Two PHP Scripts

  • Does each user have their own options page? Or that is what you’re looking for, so that each person can create their own values for all the options?

    In order to have all those custom field names you’d have to create them dynamically in the first place. First you need to export the field group from ACF and then make modification to it.

    So, first you’d need to generate all the field groups dynamically based on the logged in user.

    
    <?php 
     
     $username = 'user_1'; // whatever code you use to get the user name
     
     if(function_exists('register_field_group')) {
      $field_group = array(
       'id' => 'acf_adwords',
       'title' => 'Adwords',
       'fields' => array(
        array(
         'key' => '_key_adwords_cost_for_'.$username,
         'label' => 'Adwords Cost For '.$username,
         'name' => 'adwords_cost_for_'.$username,
         'type' => 'text',
         'default_value' => '',
         'placeholder' => '',
         'prepend' => '',
         'append' => '',
         'formatting' => 'none',
         'maxlength' => '',
        ),
       ),
       'location' => array(
        array(
         array(
          'param' => 'options_page',
          'operator' => '==',
          'value' => 'acf-options-my-options-page',
          'order_no' => 0,
          'group_no' => 0,
         ),
        ),
       ),
       'options' => array(
        'position' => 'normal',
        'layout' => 'no_box',
        'hide_on_screen' => array(),
       ),
       'menu_order' => 0,
      );
      register_field_group($field_group);
     }
     
    ?>
    

    Now that you’ve generated a dynamic option name based on the logged in user you can retrieve the value based on the logged in user.

    That’s going to make for a lot of options in your option table.