Support

Account

Home Forums ACF PRO Installing ACF5 via Composer Reply To: Installing ACF5 via Composer

  • @bigskillet if you’re installing it as a “library”, it will be installed in vendor dir. The ACF plugin itself doesn’t utilize namespaces and autoloading so it’ll just sit there, doing nothing.

    It won’t be activated as a WordPress plugin, you need to load the library yourself and hook it into WordPress’ lifecycle + configure some internal ACF settings. You can do it in a form of plugin / mu-plugin or in functions.php. I prefer using muplugins_loaded hook instead of plugins_loaded to make sure ACF Pro is loaded before any plugins that rely on it:

    
    define( 'ACF_PATH', 'vendor/advanced-custom-fields/advanced-custom-fields-pro/' );
    define( 'ACF_ABSPATH', '/absolute/path/to/project/' . ACF_PATH );
    
    /**
     * Load ACF plugin as library managed by Composer.
     */
    function load_acf_library()
    {
        require_once ACF_ABSPATH . '/acf.php';
    }
    add_action( 'muplugins_loaded', 'load_acf_library' );
    
    /**
     * Configure ACF Settings in bulk.
     */
    function acf_settings()
    {
        // Absolute path to ACF plugin folder including trailing slash
        acf_update_setting( 'path', ACF_ABSPATH );
        // URL to ACF plugin folder including trailing slash
        acf_update_setting( 'dir', home_url( '/' ) . ACF_PATH );
    }
    add_filter( 'acf/init', 'acf_settings' );