Support

Account

Home Forums Backend Issues (wp-admin) Distributing ACF in a free plugin

Solving

Distributing ACF in a free plugin

  • Hello

    I’m currently writing a free plugin using ACF free (4.4.12 from WP Repo)
    I followed https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/?version=4#instructions and I can create fields but my PHP register Fields doesn’t work: if(function_exists("register_field_group")) return false…

    ANy idea please?

  • Why not using acf_add_local_field_group? (Check here and here)

  • Unfortunately the same, I don’t succed to go through tje ‘if’ :-/

  • The function may not exist when you are trying to create your fields. When are you trying to create the field group? Is your code inside an action filter?

    The best time to do this in on “init” with a priority that will fire after ACF

    
    add_action('init', 'register_my_post_groups', 20);
    
  • Thanks for your reply but unfortunately not work

    If I ‘die’ just befor thee function_exists(), it dies… but I never go through :-/

    <?php
    if ( ! defined( 'ABSPATH' ) ){ exit; } // Exit if accessed directly
    
    	function wpcasama_create_acf_field() {
    	
    	
    		if ( function_exists( "acf_add_local_field_group" ) ) {
    			
    			acf_add_local_field_group( array(
    				'id'         => 'acf_mail-alert',
    				'title'      => 'Mail Alert',
    				'fields'     => array(
    					array(
    						'key'           => 'field_5ac3bb4effff5',
    						'label'         => 'Phone',
    						'name'          => 'wpcasama_phone',
    						'type'          => 'text',
    						'default_value' => '',
    						'placeholder'   => '',
    						'prepend'       => '',
    						'append'        => '',
    						'formatting'    => 'none',
    						'maxlength'     => '',
    					),
    					array(
    						'key'           => 'field_5ac3bb9adb144',
    						'label'         => 'city',
    						'name'          => 'wpcasama_city',
    						'type'          => 'text',
    						'default_value' => '',
    						'placeholder'   => '',
    						'prepend'       => '',
    						'append'        => '',
    						'formatting'    => 'html',
    						'maxlength'     => '',
    					),
    					array(
    						'key'           => 'field_5ac3bbc9db145',
    						'label'         => 'Minimum Price',
    						'name'          => 'wpcasama_min_price',
    						'type'          => 'number',
    						'default_value' => '',
    						'placeholder'   => '',
    						'prepend'       => '',
    						'append'        => '',
    						'min'           => 0,
    						'max'           => '',
    						'step'          => 1,
    					),
    					array(
    						'key'           => 'field_5ac3bbf8db146',
    						'label'         => 'Maximum Price',
    						'name'          => 'maximum_price',
    						'type'          => 'number',
    						'default_value' => '',
    						'placeholder'   => '',
    						'prepend'       => '',
    						'append'        => '',
    						'min'           => 0,
    						'max'           => '',
    						'step'          => 1,
    					),
    				),
    				'location'   => array(
    					array(
    						array(
    							'param'    => 'post_type',
    							'operator' => '==',
    							'value'    => 'wpcasa-mail-alerte',
    							'order_no' => 0,
    							'group_no' => 0,
    						),
    					),
    				),
    				'options'    => array(
    					'position'       => 'normal',
    					'layout'         => 'no_box',
    					'hide_on_screen' => array(),
    				),
    				'menu_order' => 0,
    			) );
    		}
    	}
    	
    	add_action('init', 'wpcasama_create_acf_field', 200);
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Distributing ACF in a free plugin’ is closed to new replies.