Carbon-fields: Carbon_Fields::directory_to_url() does not resolve URL properly if Carbon field is installed under a symlinked directory

Created on 28 Jan 2018  路  10Comments  路  Source: htmlburger/carbon-fields

Version

  • Carbon Fields: 2.1.1
  • WordPress: 4.9.1
  • PHP: 7.1

Expected Behavior

I expect Carbon's assets URL-s to be like: http://mysite.dev/wp-content/plugins/my-plugin/vendor/htmlburger/carbon-fields/assets/dist/{asset_name}

Actual Behavior

Paths URL are like: http://mysite.dev/dist/{asset_name}

Container definition

Doesn't matter

Steps to Reproduce the Problem

I'm developing a WordPress plugin

  1. Install WordPress in any directory, for example in ~/htdocs/wordpress/
  2. Create a plugin under a directory that's outside WordPress, for example ~/htdocs/my-plugin/
  3. Create a symlink ln -s ~/htdocs/my-plugin/ ~/htdocs/wordpress/wp-content/plugins/my-plugin
  4. A plugin is recognized by WordPress, plugin's files are loaded properly, plugin's assets are loaded properly
  5. Carbon assets are not loaded. Their paths are incorrect. Probably the Carbon_Fields::directory_to_url() method is not able to deal with symlinked directories.

Comments

I know that this is not the most popular setup ;) ... but still, it looks like a bug that can potentially cause some issues on more standard setups.

[type] bug

Most helpful comment

For themes, I'm using define('Carbon_Fields\URL', get_template_directory_uri() . '/vendor/htmlburger/carbon-fields'); as the workaround.

All 10 comments

Hi @wujekbogdan and thank you for the report!

If you need a workaround, you can define the Carbon_Fields\URL constant before including autoload.php which should resolve the issue for you.

For themes, I'm using define('Carbon_Fields\URL', get_template_directory_uri() . '/vendor/htmlburger/carbon-fields'); as the workaround.

I have the same problem.
Thanks, it helped.

My vendor folder is outside the document_root, as I don'' want to allow direct web access to my dependencies. It seems that it is not possible to use Carbon Fields in this setup (without changing server configuration), as it requires the web server to be able to resolve URLs to files inside the vendor folder.

My vendor folder is outside the document_root, as I don'' want to allow direct web access to my dependencies. It seems that it is not possible to use Carbon Fields in this setup (without changing server configuration), as it requires the web server to be able to resolve URLs to files inside the vendor folder.

I'm in the same situation. Only solution I could come up with was to define Carbon_FieldsURL and configure a server redirect specifically for the carbon fields directory. Hacky.

@luishdz1010 @peteshilling haven't tested if this works in 3.0 as well but here is how it can be done in 2.2:
https://carbonfields.net/docs/guides-bedrock-support-2/?crb_version=2-2-0

@atanas-angelov-dev Thanks! The custom directory installer plugin did the trick.

{
  "require": {
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "htmlburger/carbon-fields": "3.0.2",
    "htmlburger/carbon-fields-plugin": "3.0.2"
  },
  "extra": {
    "installer-paths": {
      "./public/wp-content/plugins/{$name}/": ["type:wordpress-plugin"],
      "./public/wp-content/plugins/carbon-fields/": ["htmlburger/carbon-fields"]
    }
  }
}

Does the above tweak still works (using composer/installers)?
According to https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md: You cannot use this to change the path of any package. This is only applicable to packages that require composer/installers and use a custom type that it handles..

I tried;

  • "web/app/plugins/{$name}/": ["type:wordpress-plugin", "htmlburger/carbon-fields"]
    and
  • "web/app/plugins/carbon-fields/": ["htmlburger/carbon-fields"]
    without success.

Does the above tweak still works (using composer/installers)?
According to https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md: You cannot use this to change the path of any package. This is only applicable to packages that require composer/installers and use a custom type that it handles..

I tried;

  • ` "web/app/plugins/{$name}/": ["type:wordpress-plugin", "htmlburger/carbon-fields"]
    and
  • "web/app/plugins/carbon-fields/": ["htmlburger/carbon-fields"]
    without success.
"extra": {
    "installer-paths": {
      "./web/wp-content/plugins/carbon-fields/": [
        "htmlburger/carbon-fields"
      ]
    }
  }

works for me

Does the above tweak still works (using composer/installers)?
According to https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md: You cannot use this to change the path of any package. This is only applicable to packages that require composer/installers and use a custom type that it handles..

I tried;

  • "web/app/plugins/{$name}/": ["type:wordpress-plugin", "htmlburger/carbon-fields"]
    and
  • "web/app/plugins/carbon-fields/": ["htmlburger/carbon-fields"]
    without success.

Make sure to require mnsami/composer-custom-directory-installer

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaleidoscopique picture kaleidoscopique  路  3Comments

ArekZw picture ArekZw  路  4Comments

ittikorns picture ittikorns  路  3Comments

MDSilviu picture MDSilviu  路  3Comments

dmhendricks picture dmhendricks  路  3Comments