• Resolved Gilles Vauvarin

    (@vauvarin)


    Hi,

    I just have discovered Carbon Fields and tried to create a simple widget to test this plugin.

    I have followed the instructions in the documentation (“Getting Started” chapter) to register my fields with the carbon_register_fields hook but it doesn’t works.

    I did this in a plugin so the code below is in my main plugin php file:

    
    add_action('carbon_register_fields', 'crb_register_custom_fields');
    function crb_register_custom_fields() {
        include_once( plugin_dir_path( __FILE__ ) . '/includes/widgets.php');
    }
    

    On the other side, if I do a simple include like this:

    
    include_once( plugin_dir_path( __FILE__ ) . '/includes/widgets.php');
    

    It’s works.

    What I did wrong to register my fields with the “crb_register_custom_fields” hook as explained in the documentation?

    You can download my little plugin to check the code by following this link

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author htmlBurger

    (@htmlburger)

    Hey @vauvarin

    Sorry for the late answer, but this somehow fell off the radar.

    Widgets are a bit special and need to be registered in an earlier hook. Try including the widgets.php file at after_setup_theme, for example:

    
    add_action( 'after_setup_theme', 'crb_setup_theme' );
    function crb_setup_theme() {
        include_once( plugin_dir_path( __FILE__ ) . '/includes/widgets.php');
    }
    

    Also thanks for pointing this out, we will update the documentation to avoid confusion.

    Cheers!

    Plugin Author htmlBurger

    (@htmlburger)

    We updated the code so carbon_register_fields will now work with widgets, just keep in mind that this change will be present in the next version of the plugin (1.5).

    • This reply was modified 8 years ago by htmlBurger.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Register my fields with the carbon_register_fields hook’ is closed to new replies.