Support

Account

Home Forums Backend Issues (wp-admin) PHP Export Option update

Solved

PHP Export Option update

  • Hey Elliott!

    Is there anyway the PHP Export Option can:
    1. Include the add-on code for purchase items.
    2. Turn the array into a variable. This will help to DO MORE scripting! 🙂
    Sort of like for example:

    Heres is a normal export:

    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_page-options',
    		'title' => 'Page Options',
    		'fields' => array (
    			array (
    				'key' => 'field_52a100d5265e0',
    				'label' => 'Type',
    				'name' => '',
    				'type' => 'tab',
    			),
    			array (
    				'key' => 'field_51c336e778cce',
    				'label' => 'Page Type',
    				'name' => 'page_type',
    				'type' => 'radio',
    				'instructions' => 'Select a type.',
    				'choices' => array (
    					'none' => 'None',
    					'image' => 'Image',
    					'video' => 'Video',
    				),
    				'other_choice' => 0,
    				'save_other_choice' => 0,
    				'default_value' => 'none',
    				'layout' => 'horizontal',
    			),
                            ),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'post',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    			
    		),
    		'options' => array (
    			'position' => 'acf_after_title',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    }

    But if I wanted to add in IF STATEMENTS, I can’t 🙁
    BUT. If the export looked like this:

    // CREATE THE BASIC FIELDS ARRAY
    $fields[] = array  
    ( 
      'key'   => 'field_52a100d5265e0',
      'label' => 'Type',
      'name'  => '',
      'type'  => 'tab',
    );
    
    // IF SOMETHING SIGNALS US, ADD ANOTHER ELEMENT TO THE FIELDS ARRAY
    // NOTICE THE IF STATEMENT/
    
    if ($something == 0)
    {
        $fields[] = array  
        ( 
            'key' => 'field_51c336e778cce',
            'label' => 'Page Type',
            'name' => 'page_type',
    	'type' => 'radio',
    	'instructions' => 'Select a type.',
    	'choices' => array (
    		'none' => 'None',
    		'image' => 'Image',
    		'video' => 'Video',
    				),
    	'other_choice' => 0,
    	'save_other_choice' => 0,
    	'default_value' => 'none',
    	'layout' => 'horizontal',
        );
    }
     
    // CREATE THE MULTIDIMENSIONAL ARRAY FOR THE FUNCTION CALL
    $multi_array = array 
    ( 
    'id'     => 'acf_page-options',
    'title'  => 'Page Options',
    'fields' => $fields 
    'location' => array (
         array (
    	array (
    	'param' => 'post_type',
    	'operator' => '==',
    	'value' => 'post',
    	'order_no' => 0,
    	'group_no' => 0,
    	),
         ),
     ),
     'options' => array (
    	'position' => 'acf_after_title',
    	'layout' => 'default',
    	'hide_on_screen' => array (
    	 ),
      ),
      'menu_order' => 0,
    );
    
    // CALL THE FUNCTION USING THE VARIABLES WE CREATED
    register_field_group($multi_array);

    So Elliot as you can see, if the php exports as this way, we would be able to add all kinds of conditional statements allowing us to do much more with the code. We can even use options addon to control whats shown and anytime!!! 😀

    Please consider this update!

    *SAMJCO

  • Hi @[email protected]

    Thanks for the topic, but this request would only confuse many of the ACF users.
    If you wish to write some logic surrounding the fields, please simply copy and paste out the ‘fields’ array and paste it into a variable.

    Also, by forcing a variable, ACF would be using more memory on all exports and potentially causing variable name conflicts.

    Thanks
    E

  • I would think you would only use 2 variables:
    $acf_all_fields[]
    $acf_field_group_multi_array

    Besides, I don’t think the PHP export wouldn’t confuse us.

    The only difference would be each array group will terminate with ; instead of , .

    With this we can do custom conditions using php!

  • Just to be clear :).
    I was only speaking on the way the PHP export prints out.
    Not a major change in variables/function etc. 😛

  • Hi @[email protected]

    Thanks for the follow up. I am not convinced this feature will be a successful addition to the plugin.

    You can easily copy / paste the array code into a variable for your own conditional work.

    Thanks
    E

  • Well would you be interest in simply creating a checkbox “Enable variable PHP output”?

    IF box is checked and user goes to export PHP, it will print the variable version.

    I can copy and paste, but I use the export feature alot and having to rework all field arrays into variable working ones, would take all day each time.

    I am pretty sure the ACF community would support this idea. It’s for the advanced coder and will give all sort of creation power to any coder, thus broadening the flexibility of this already awesome product called ACF!

    E,
    Please consider the potential of having this added, like, using the ACF Option add-on to globally control the elements.

  • Hi @Samjco

    Thanks for the follow up.
    Yes, I will definitely consider it.

    Thanks again

    Cheers
    E

  • Ha Ha….. after all these years!!
    You finally implemented it!
    https://www.advancedcustomfields.com/resources/register-fields-via-php/

    Thanks Elliot!

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

The topic ‘PHP Export Option update’ is closed to new replies.