Unable to filter stylesheet_directory
-
Hi,
We have a plugin which use the stylesheet_directory filter to return different path for a given theme. When ACF is active we are unable to use this filter.function get_stylesheet_directory() { global $wp_stylesheet_path; if ( null === $wp_stylesheet_path ) { .... $wp_stylesheet_path = $stylesheet_dir; } return $wp_stylesheet_path; }
When you call get_stylesheet_directory() the return value is cached in the global variable. As ACF calls this function before the plugins_loaded action, we are unable to filter it.
Test code:
add_action('plugins_loaded', function(){ add_filter('stylesheet_directory', function ($stylesheet_dir, $stylesheet) { return '/test/path/to/aaa'; }, 10, 2); var_dump('Output', get_stylesheet_directory()); exit; });
Expected output for get_stylesheet_directory() call: /test/path/to/aaa
Wrong output: /path/wp-content/themes/twentytwentyfour
Call stack:
#0 get_stylesheet_directory() called at [/path/wp-content/plugins/advanced-custom-fields/includes/local-json.php:31] #1 ACF_Local_JSON->__construct() called at [/path/wp-content/plugins/advanced-custom-fields/includes/acf-utility-functions.php:23] #2 acf_new_instance(ACF_Local_JSON) called at [/path/wp-content/plugins/advanced-custom-fields/includes/local-json.php:514] #3 include_once(/path/wp-content/plugins/advanced-custom-fields/includes/local-json.php) called at [/path/wp-content/plugins/advanced-custom-fields/includes/acf-utility-functions.php:154] #4 acf_include(includes/local-json.php) called at [/path/wp-content/plugins/advanced-custom-fields/acf.php:175] #5 ACF->initialize() called at [/path/wp-content/plugins/advanced-custom-fields/acf.php:778] #6 acf() called at [/path/wp-content/plugins/advanced-custom-fields/acf.php:784] #7 include_once(/path/wp-content/plugins/advanced-custom-fields/acf.php) called at [/path/wp-settings.php:473] #8 require_once(/path/wp-settings.php) called at [/path/wp-config.php:96] #9 require_once(/path/wp-config.php) called at [/path/wp-load.php:50] #10 require_once(/path/wp-load.php) called at [/path/wp-admin/admin.php:34] #11 require_once(/path/wp-admin/admin.php) called at [/path/wp-admin/plugins.php:10] #0 get_stylesheet_directory() called at [/path/wp-content/plugins/advanced-custom-fields/includes/local-json.php:32] #1 ACF_Local_JSON->__construct() called at [/path/wp-content/plugins/advanced-custom-fields/includes/acf-utility-functions.php:23] #2 acf_new_instance(ACF_Local_JSON) called at [/path/wp-content/plugins/advanced-custom-fields/includes/local-json.php:514] #3 include_once(/path/wp-content/plugins/advanced-custom-fields/includes/local-json.php) called at [/path/wp-content/plugins/advanced-custom-fields/includes/acf-utility-functions.php:154] #4 acf_include(includes/local-json.php) called at [/path/wp-content/plugins/advanced-custom-fields/acf.php:175] #5 ACF->initialize() called at [/path/wp-content/plugins/advanced-custom-fields/acf.php:778] #6 acf() called at [/path/wp-content/plugins/advanced-custom-fields/acf.php:784] #7 include_once(/path/wp-content/plugins/advanced-custom-fields/acf.php) called at [/path/wp-settings.php:473] #8 require_once(/path/wp-settings.php) called at [/path/wp-config.php:96] #9 require_once(/path/wp-config.php) called at [/path/wp-load.php:50] #10 require_once(/path/wp-load.php) called at [/path/wp-admin/admin.php:34] #11 require_once(/path/wp-admin/admin.php) called at [/path/wp-admin/plugins.php:10] plugins_loaded action happens here -> string(78) "/path/wp-content/themes/twentytwentyfour"
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Unable to filter stylesheet_directory’ is closed to new replies.