Support

Account

Home Forums ACF PRO Integrate ACF PRO in a theme

Solved

Integrate ACF PRO in a theme

  • Hello,

    I have a little theme with ACF 4.x integrated and everything works like a charm.

    I’m trying to integrate ACF PRO but I can’t make it…

    I’m using the code from the docs with some modifications from some topics of the forums.

    Here is the code:

    include_once( 'includes/acf-pro/acf.php' );
    
    add_filter('acf/settings/path', 'my_acf_settings_path');
     
    function my_acf_settings_path( $path ) {
     
    	// update path
    	$path = get_bloginfo('stylesheet_directory') . '/includes/acf-pro/';
    	
    	// return
    	return $path;
    	
    }
    
    add_filter('acf/settings/dir', 'my_acf_settings_dir');
     
    function my_acf_settings_dir( $dir ) {
     
    	// update path
    	$dir = get_stylesheet_directory_uri() . '/includes/acf-pro/';
    	
    	
    	// return
    	return $dir;
    	
    }

    All the references are OK, but if I activate debug mode in WordPress, I get this errors:

    Warning: include_once(api/api-helpers.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/wordpress/wp-content/themes/hg_framework/includes/acf-pro/acf.php on line 82
    
    Warning: include_once(): Failed opening 'api/api-helpers.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.5.3/lib/php') in /Applications/MAMP/htdocs/wordpress/wp-content/themes/hg_framework/includes/acf-pro/acf.php on line 82
    
    Fatal error: Call to undefined function acf_get_path() in /Applications/MAMP/htdocs/wordpress/wp-content/themes/hg_framework/includes/acf-pro/acf.php on line 86

    I’m in localhost using MAMP. ACF 4.x works perfect.

    Any ideas?

    Thanks in advance!

    • Elliot

    • July 31, 2014 at 11:34 am

    Hi @hectorgarrofe

    Can you please double check that the paths (in the PHP error) are correct paths to files?

  • Hello Elliot,

    The paths in the PHP error are correct. acf.php is located at this path.

    Maybe:

    // include helpers
    include_once('api/api-helpers.php');

    I don’t have an api folder inside ACF PRO plugin folder. I downloaded the plugin a few days ago.

  • I downloaded the plugin again, with this directory (I don’t know why isn’t there) and everything seems to be working.

    By the way, when I want to create a new custom field, I can only write the title. The Location and Options, are empty.

    Thanks in advance!

    • rsb91

    • August 7, 2014 at 7:36 pm

    I’ve got the same problem. After Integrate this plugin into my theme the field are empty. It’s possible to create a group but then its empty.

    I hope someone had an solution.

    Thanks!

    • Elliot

    • August 14, 2014 at 1:33 pm

    Hi @rsb91

    If you install the ACF PRO as a plugin, does the issue go away?

    • rsb91

    • August 14, 2014 at 5:55 pm

    Hi @elliot,

    Yes, if I install the plugin normally everything works properly. But thats not what i want. I try to get it in my theme folder.

    I have now added the plugin with the TGM plugin. But it is better to integrate the plugin directly in the theme.

    Thanks!

    • Elliot

    • September 3, 2014 at 10:26 am

    Hi @hectorgarrofe

    Does it make a difference if you define the filters before including the acf.php file?

    • Elliot

    • September 3, 2014 at 10:27 am

    Also, you may be using the wrong function to set the path. Please use the code here: http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

    You may find that get_stylesheet_directory() returns a different result to get_bloginfo('stylesheet_directory')

    Thanks
    E

  • I am having the same problem, I’m including the plugin in my theme as below:

    /* Include Advanced Custom Fields */
    include_once("_includes/acf-pro/acf.php");
    
    add_filter('acf/settings/path', 'my_acf_settings_path');
    function my_acf_settings_path( $path ) {
        // update path
        $path = get_stylesheet_directory() . "/_includes/acf-pro/";
        // return
        return $path;
    }

    I have also tried get_template_directory_uri() and get_bloginfo('stylesheet_directory').

    The plugin is included and activated but I am getting 404 erros for the ACF stylesheets. This happens if (as above) I define the filter underneath the include function. If I put the filter above it then Custom Fields dissappears from the WP admin sidebar.

    404 Errors

    It works fine if I put the folder in plugins but this is not ideal.

    Please help!

    • Elliot

    • September 30, 2014 at 10:23 am

    Hi @stormtrooper

    Can you please copy/paste the URL shown in the JS error and test if the file can be found? Perhaps there is a mistake in the URL?

  • It can’t exist at that URL.
    http://localhost/fs/website_name/wp-content/plugins/Users/Storm/Sites/fs/website_name/wp-content/themes/theme_name/_includes/acf-pro/inc/datepicker/jquery-ui-1.10.4.custom.min.css?ver=5.0.8

    As you can see above, the first part of the URL looks into the /plugins dir. Then the URL starts at /Users after that, which is the URL that $path is returning with get_stylesheet_directory(). It should wipe that whole URL and just start from http://

    To see what was going with $path, I tested the following:

    $path = get_stylesheet_directory() . "/_includes/acf-pro/";
    print_r($path)

    returns
    /Users/Storm/Sites/fs/swiftcarbon/wp-content/themes/swiftcarbon-theme/_includes/acf-pro/

    $path = get_template_directory_uri() . "/_includes/acf-pro/";
    print_r($path)

    returns
    http://localhost/fs/website_name/wp-content/themes/theme_name/_includes/acf-pro/

    With get_template_directory_uri(), there are no errors reported, so presumably it’s finding the files it needs, but then Custom Fields menu item disappears from the WP admin sidebar.

    • Elliot

    • October 2, 2014 at 3:17 pm

    Hi @stormtrooper

    Thanks for the info. Your debugging shows that your code is creating the correct $path variable.

    Have you added the other filter to modify the dir? This is also documented in
    http://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

    Can you please attach your full PHP to include ACF / modify settings?

  • Aaaaaahhhhh… I didn’t customize the ACF dir. How embarrassing. It’s working perfectly now.

    Thank you so much for your help!

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.