bug Include the plugin from your theme functions.php
-
https://ibb.co/Qr4GMSW
https://ibb.co/KrYnPZBI have included the plugin in the theme but there are bugs.
include_once( get_stylesheet_directory() . ‘/includes/advanced-custom-fields-font-awesome/acf-font-awesome.php’ );
the icons are not visible ( see image) also in the settings if I write my FontAwesome API Token it does not do the validation and does not show any kit.
instead if I install the plugin with the classic wordpress method it works.how can i include the plugin in the theme without these errors?
-
Hey @marcoc84,
I did a fresh test just now and I’m not seeing any issues with this plugin installed in my theme. For my test I have my plugin disabled from the plugins admin area, and I included the plugin at the very top of my functions.php in my active theme.
So it must be something more specific about your particular environment that is producing the issue. If you are able to help diagnose maybe we can figure it out together.
My first thought is if there is anything odd/different about your theme compared to a ‘standard’ theme? Like perhaps it is using a non-standard folder structure?
A good test would be to temporarily activate one of the stock WP themes (if you are able) and include this plugin in that theme, and test to see if you are still having the same issues as before. That would at least tell us if the problem is having to do with the theme, or something else in your environment.
Let me know if you are able to do some testing what you learn!
Matt Keys
-
This reply was modified 2 years ago by
Matt Keys.
thank you for your reply. i’m doing some tests, but i can tell you that i’m only using 3 plugins in my theme all integrated in the theme,I have no plugins installed in the plugin administration area: 1 ACF PRO , 2 ACF extended pro and yours, this is my code:
// Define path and URL to the ACF plugin. define( 'MY_ACF_PATH', get_stylesheet_directory() . '/third-part/plugins/acf/' ); define( 'MY_ACF_URL', get_stylesheet_directory_uri() . '/third-part/plugins/acf/' ); // Include the ACF plugin. include_once( MY_ACF_PATH . 'acf.php' ); // Customize the url setting to fix incorrect asset URLs. add_filter('acf/settings/url', 'my_acf_settings_url'); function my_acf_settings_url( $url ) { return MY_ACF_URL; } // (Optional) Hide the ACF admin menu item. //add_filter('acf/settings/show_admin', '__return_false'); // When including the PRO plugin, hide the ACF Updates menu add_filter('acf/settings/show_updates', '__return_false', 100); // define path and URL to the ACFE plugin define('MY_ACFE_PATH', get_stylesheet_directory() . '/third-part/plugins/acfe/'); define('MY_ACFE_URL', get_stylesheet_directory_uri() . '/third-part/plugins/acfe/'); // include the ACFE plugin include_once(MY_ACFE_PATH . 'acf-extended.php'); // customize the url setting to fix asset URLs add_filter('acfe/settings/url', 'my_acfe_settings_url'); function my_acfe_settings_url($url){ return MY_ACFE_URL; } include_once( get_stylesheet_directory() . '/third-part/plugins/advanced-custom-fields-font-awesome/acf-font-awesome.php' );
could there be a conflict with acf extended or something else?
Thanks for the update. It is certainly possible there is a conflict, probably not the most likely reason but worth testing to rule it out.
I’m still curious to know if there is anything odd about your theme structure, and if trying one of the default/stock themes that ship with WordPress still gives you the same issues?
I just copy/pasted your code into my local theme functions.php with exception to the ACF Extended plugin that I don’t have.
Everything worked as expected. So other than an odd conflict with ACFE I don’t think any of that is related to the problem you are seeing.
Aside from the diagnosis tests I mentioned above, check out your JS error console to see about any assets that aren’t loading correct. And you PHP error log to see if there is anything related in there.
it is curious that if I do not integrate it into the theme, it works.
i’m doing some tests with other themes found on the net. i’ll update hereHello,
ACF Extended developer here ??
I just stumbled upon this report, if you allow me to step-in.
I ran multiple tests trying the code provided by the user, and it doesn’t look like a compatibility issue with ACF Extended.
The issue seems to be related to the code that include ACF: FontAwesome from a custom path.
It can be reproduced by using ACF Pro (with or without ACF Extended) as a normal plugin, and including ACF: FontAwesome using the code provided by the user:
include_once( get_stylesheet_directory() . '/third-part/plugins/advanced-custom-fields-font-awesome/acf-font-awesome.php' );
Here is a video showing this issue being reproduced consistently (with or without ACF Extended).
As you can see, it looks like ACF: FontAwesome try to enqueue its related CSS/JS files from an URL which mix URL and absolute local path:
https://www.wordpress.dev/wp-content/plugins/C:/local/www/wordpress/wp-content/themes/blank/third-part/plugins/advanced-custom-fields-font-awesome/assets/js/input-v6.js?ver=4.0.4
I made these tests on a local development environment on Windows. But I guess this issue can be reproduced on a webserver (maybe it’s an IIS webserver issue only?).
Hope it helps!
Have a nice day!
Regards.
Hey Konrad thanks for adding your thoughts here, I haven’t been able to reproduce the issue so your screen-share provides a lot of helpful info.
I’ll have to do some more digging on why some environment are returning a garbled local/system path for those resources but my local environment returns a public URL for them.
-
This reply was modified 2 years ago by
Matt Keys.
Definitely something to do with this code block:
if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) { $stylesheet_dir = trim( get_stylesheet_directory(), '/' ); if ( stristr( __FILE__, $stylesheet_dir ) ) { define( 'ACFFA_THEME_INSTALLATION', true ); $basename_dir = trim( plugin_basename( __DIR__ ), '/' ); $theme_path = str_replace( $stylesheet_dir, '', $basename_dir ); $public_path = get_stylesheet_directory_uri() . trailingslashit( $theme_path ); } else { define( 'ACFFA_THEME_INSTALLATION', false ); $public_path = plugin_dir_url( __FILE__ ); } define( 'ACFFA_PUBLIC_PATH', $public_path ); }
I recall seeing how ACF handled ‘theme installs’ and thought there was a easier way to enable them. But clearly there was a reason for it.
Probably best to just make users define the path themselves.
-
This reply was modified 2 years ago by
Matt Keys.
Potential fix here for testing:
In acf-font-awesome.php, update the code blocks where ‘ACFFA_PUBLIC_PATH’ and ‘ACFFA_DIRECTORY’ are defined to match below:
if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) { $stylesheet_dir = trim( get_stylesheet_directory(), '/' ); if ( stristr( __FILE__, $stylesheet_dir ) ) { define( 'ACFFA_THEME_INSTALLATION', true ); if ( defined( 'MY_ACFFA_URL' ) ) { $public_path = MY_ACFFA_URL; } else { $basename_dir = trim( plugin_basename( __DIR__ ), '/' ); $theme_path = str_replace( $stylesheet_dir, '', $basename_dir ); $public_path = get_stylesheet_directory_uri() . trailingslashit( $theme_path ); } } else { define( 'ACFFA_THEME_INSTALLATION', false ); $public_path = plugin_dir_url( __FILE__ ); } define( 'ACFFA_PUBLIC_PATH', $public_path ); } if ( ! defined( 'ACFFA_DIRECTORY' ) ) { if ( defined( 'MY_ACFFA_PATH' ) ) { define( 'ACFFA_DIRECTORY', MY_ACFFA_PATH ); } else { define( 'ACFFA_DIRECTORY', dirname( __FILE__ ) ); } }
In your functions.php add:
define( 'MY_ACFFA_PATH', get_stylesheet_directory() . '/your-path-to-my-plugin-here/' ); define( 'MY_ACFFA_URL', get_stylesheet_directory_uri() . '/your-path-to-my-plugin-here/' );
If you can test that and let me know if it resolves the issues you are seeing I can get it incorporated into the next release of this plugin.
Hello,
In theory your fix works, however, on Windows slashes and backlashes might be mixed in some situations, like here (yeah weird logic).
In my case, your code from above never get in this condition:
if ( stristr( __FILE__, $stylesheet_dir ) ) {
Because my
__FILE__
and$stylesheet_dir
are like that:__FILE__ = C:\local\www\wordpress\wp-content\themes\blank\third-part\plugins\advanced-custom-fields-font-awesome\acf-font-awesome.php $stylesheet_dir = C:\local\www\wordpress/wp-content/themes/blank
To workaround these slashes issues on Windows, WordPress use
wp_normalize_path()
(See documentation).Using this function, I confirm you that the following code make your fix work:
if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) { $stylesheet_dir = trim( get_stylesheet_directory(), '/' ); $stylesheet_dir = wp_normalize_path($stylesheet_dir); // normalize windows $file = wp_normalize_path(__FILE__); // normalize windows if ( stristr( $file, $stylesheet_dir ) ) { // ... } }
So variables now look like this:
$file = C:/local/www/wordpress/wp-content/themes/blank/third-part/plugins/advanced-custom-fields-font-awesome/acf-font-awesome.php $stylesheet_dir = C:/local/www/wordpress/wp-content/themes/blank
As you pointed out, ACF has a nice logic to avoid all these issues.
It includes all its JS/CSS/images files using the
acf_get_url()
function. In/advanced-custom-fields-pro/includes/acf-utility-functions.php:135
.This function will allow to use the
ACF_URL
constant, or theacf/settings/url
filter (used by the user above) to override the base url of all its JS/CSS/Images includes.It also has a similar logic to includes its PHP files with
acf_include()
(which callacf_get_path()
), but it doesn’t need to be overridden, as Windows doesn’t have issues to include PHP files with mixed slashes.I copied that logic for ACF Extended, that’s why both of our “Custom Path Include” codes look similar.
Here is the final code with the fix included:
if ( ! defined( 'ACFFA_PUBLIC_PATH' ) ) { $stylesheet_dir = trim( get_stylesheet_directory(), '/' ); $stylesheet_dir = wp_normalize_path($stylesheet_dir); // normalize windows $file = wp_normalize_path(__FILE__); // normalize windows if ( stristr( $file, $stylesheet_dir ) ) { define( 'ACFFA_THEME_INSTALLATION', true ); if ( defined( 'MY_ACFFA_URL' ) ) { $public_path = MY_ACFFA_URL; } else { $basename_dir = trim( plugin_basename( __DIR__ ), '/' ); $theme_path = str_replace( $stylesheet_dir, '', $basename_dir ); $public_path = get_stylesheet_directory_uri() . trailingslashit( $theme_path ); } } else { define( 'ACFFA_THEME_INSTALLATION', false ); $public_path = plugin_dir_url( __FILE__ ); } define( 'ACFFA_PUBLIC_PATH', $public_path ); } if ( ! defined( 'ACFFA_DIRECTORY' ) ) { if ( defined( 'MY_ACFFA_PATH' ) ) { define( 'ACFFA_DIRECTORY', MY_ACFFA_PATH ); } else { define( 'ACFFA_DIRECTORY', dirname( __FILE__ ) ); } }
Hope it helps!
Have a nice day!
Regards.
I will try this solution
-
This reply was modified 2 years ago by
marcoc84.
Thanks @marcoc84 based on Konrad’s additional testing/explanation I understand what’s going on here. Konrad updated my fix with a solution that worked for him if you can test it also.
Konrad, appreciate you being so generous with your time and knowledge here, saved me a lot of time.
-
This reply was modified 2 years ago by
Matt Keys.
No problem, I would have loved that someone did the same for me in such specific situation ??
Keep up the great work!
Regards.
define( 'MY_ACFFA_PATH', get_stylesheet_directory() . '/third-part/plugins/advanced-custom-fields-font-awesome/acf-font-awesome.php' ); define( 'MY_ACFFA_URL', get_stylesheet_directory_uri() . '/third-part/plugins/advanced-custom-fields-font-awesome/acf-font-awesome.php' );
Is it sufficient to define only those in functions.php?
Those should be the path to the folder, but not to the file. So:
define( 'MY_ACFFA_PATH', get_stylesheet_directory() . '/third-part/plugins/advanced-custom-fields-font-awesome/' ); define( 'MY_ACFFA_URL', get_stylesheet_directory_uri() . '/third-part/plugins/advanced-custom-fields-font-awesome/' );
-
This reply was modified 2 years ago by
- The topic ‘bug Include the plugin from your theme functions.php’ is closed to new replies.