Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

directory_to_url() returning empty string #1218

Open
RBFraphael opened this issue Feb 16, 2024 · 1 comment
Open

directory_to_url() returning empty string #1218

RBFraphael opened this issue Feb 16, 2024 · 1 comment

Comments

@RBFraphael
Copy link

Version

  • Carbon Fields: 3.6.3
  • WordPress: 6.4.3
  • PHP: 8.3.3

Expected Behavior

Calling \Carbon_Fields\Carbon_Fields\directory_to_url(<dir>) returns corresponding URL to a directory inside the theme.

Actual Behavior

The function is returning an empty string.

Container definition

add_action("after_setup_theme", "BootCarbonFields");

function BootCarbonFields()
{
    Carbon_Fields::boot();
    var_dump(\Carbon_Fields\DIR);
    var_dump(__DIR__);
    var_dump(\Carbon_Fields\Carbon_Fields::directory_to_url(\Carbon_Fields\DIR));
    die;
}

Steps to Reproduce the Problem

  1. Install Carbon Fields on your theme
  2. Call Carbon_Fields::boot()
  3. Try to use \Carbon_Fields\Carbon_Fields::directory_to_url() with any directory of your theme as parameter

Comments

First, I'm not using this method for any purpose directly on my theme. The problem started after I've noticed my Wordpress wasn't loading any fields on admin, and, when verifying the Console, it is showing 404 errors for some css and js files:

  • core/Libraries/Sidebar_Manager/assets/css/app.css?ver=3.6.3
  • core/Libraries/Sidebar_Manager/assets/js/app.js?ver=3.6.3
  • build/classic/core.min.css?ver=3.6.3
  • build/classic/metaboxes.min.css?ver=3.6.3
  • build/classic/vendor.min.js?ver=3.6.3
  • build/classic/core.min.js?ver=3.6.3
  • build/classic/metaboxes.min.js?ver=3.6.3

All of them are tried to load directly from the root of my website, instead of loading from theme's Carbon Field. When verifying the source code, I've found that those files are prefixed with \Carbon_Fields\URL constant, which is empty. And, when searching for the declaration of that constant, it uses the directory_to_url() method, which, after some tests, I've noticed that is always returning an empty string.

@RBFraphael
Copy link
Author

A possible workaround for that problem is to manually set the constant before calling Carbon_Fields::boot().

add_action("after_setup_theme", "BootCarbonFields");
function BootCarbonFields()
{
   define("Carbon_Fields\URL", get_template_directory_uri()."/vendor/htmlburger/carbon-fields/");
   Carbon_Fields::boot();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant