Support

Account

Home Forums ACF PRO Load ACF Pro from inside a plugin

Solving

Load ACF Pro from inside a plugin

  • Hello, I’m trying to get working ACF pro from inside a custom plugin I made for setting up a theme.

    It works without problems loading the ACF Pro from functions.php, as you describe here: http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/. For executing from my custom plugin I updated the paths, and I can see that the php files of ACF Pro are being loaded (if I echo something I can see it). But actually it’s like acf pro was not being loaded because I get the typical error: Fatal error: Call to undefined function get_field()

    This is the code of my plugin (the plugin is working allright apart of the ACF integration) :

    
    <?php  
    /* 
    Plugin Name: -- CGS Theme Functionality --
    Plugin URI: http://
    Version: 1.0
    Author: Roy
    Description: This plugin implent all functionlaities 
    */
    
    //////// Register Custom Post Type and Taxonomies
    require_once('inc/cpt-taxonomies.php');
    
    //////// Functions for setting-up the theme
    require_once('inc/theme-startup.php');
    
    //////// Load ACF-Pro and meta-fields
    require_once('acf/acf-include.php');
    require_once('acf/acf-meta-fields-Theme-Setings.php');
    require_once('acf/acf-meta-fields-Tiles-Setings.php');
    
    //////// Run on activation
    function to_do_on_activation() {
    
        cgs_create_page();
        set_static_front_page();
        cptui_register_my_cpt_frontiles();
        cptui_register_my_taxes_tiles_categories();
        insert_term();
        cgs_create_tiles();
        cgs_create_page();
        set_static_front_page();
        updateTheme('Creative_Grid');
    }
    
    register_activation_hook( __FILE__, 'to_do_on_activation' );
    
    ?>
    

    and this is the code in acf-include.php:

    
    <?php 
    // INCLUDES ACF ///////////////////////
    // ACF plugin and ACF meta-fields-export
    // 1. customize ACF path
    
      add_filter('acf/settings/path', 'my_acf_settings_path');
     
      function my_acf_settings_path( $path ) {
     
        // update path
        $path = plugins_url( '/acf-pro/', __FILE__ );
    
        // $path = get_stylesheet_directory() . '/acf-pro/';
        
        // return
          return $path;
        
      }
    // 2. customize ACF dir
      add_filter('acf/settings/dir', 'my_acf_settings_dir');
     
      function my_acf_settings_dir( $dir ) {
     
        // update path
        $dir = plugins_url( '/acf-pro/', __FILE__ );
        
        // return
          return $dir;
        
      }
    // 3. Hide ACF field group menu item
      add_filter('acf/settings/show_admin', '__return_false');
    // 4. Include ACF
      require_once('/acf-pro/acf.php');
    ?>
    

    Would be great if someone could help to understand what I’m doing wrong.

    Thanks

  • bump!, some help with this would be great 🙂

  • Did you ever figure this out? I’m currently struggling with the same thing…

  • If you haven’t already figured this out try using dirname(__FILE__) instead of only __FILE__ when using plugins_url()

    so instead of this:
    plugins_url( '/acf-pro/', __FILE__ )

    Try this:
    plugins_url( '/acf-pro/', dirname(__FILE__) )

  • Also might try changing:

    require_once('/acf-pro/acf.php');

    to:
    require_once( plugin_dir_path( dirname(__FILE__) ) . 'acf-pro/acf.php' );

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

The topic ‘Load ACF Pro from inside a plugin’ is closed to new replies.