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

Resources do not load with custom WP_CONTENT_DIR & WP_CONTENT_URL #27

Closed
cnasikas opened this issue Sep 6, 2014 · 29 comments
Closed

Resources do not load with custom WP_CONTENT_DIR & WP_CONTENT_URL #27

cnasikas opened this issue Sep 6, 2014 · 29 comments

Comments

@cnasikas
Copy link

cnasikas commented Sep 6, 2014

First of all thanks for your time and your effort creating this awesome framework.

I had installed Wordpress with yeoman wordpress generator. The wordpress installtion folder is different from the content folder.

Wordpress version : 4.0
CMB2 version : 2.0.0-beta
Localhost enviroment : Windows 7 SP1, XAMPP 3.2.1

wp-config.php

if (!defined('WP_SITEURL')) {
define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/ai/cms');
}
if (!defined('WP_HOME')) {
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME'] . '/ai');
}
if (!defined('WP_CONTENT_DIR')) {
define('WP_CONTENT_DIR', dirname(FILE) . '/content/');
}
if (!defined('WP_CONTENT_URL')) {
define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/ai/content');
}

I tried to add a metabox and the resources do not load. Specifically the cmb2.min.css, jquery.timePicker.min.js, cmb2.min.js. I get a 404 error.

The problem occurs on the resources path. A trailing slash is missing at the end of the WP_CONTENT_URL.

It is http://localhost/ai/contentthemes/ai/inc/admin/cmb2/css/cmb2.min.css?ver=4.0 and should be http://localhost/ai/content/themes/ai/inc/admin/cmb2/css/cmb2.min.css?ver=4.0

If I add at the end of WP_CONTENT_URL a trailing slash is working but all permalinks have two trailing slashes.

Thanks in advance.

@brunoramalho
Copy link
Contributor

Please @cnasikas, share with us the folder structure on your wordpress instalation.

@cnasikas
Copy link
Author

Hi

First of all I want to say that on my host environment everything is working fine. Only localhost I have this problem. I guess due to different OS ?

My folder structure:

Root(C:\xampp\htdocs\ai) ->
-cms -> (all wordpress folders and files of a typical installation including wp-content)
-content->
- plugins
- themes (my theme is here with CBM2 inside)
- upgrade
- uploads

Haven't install CMB2 as plugin but I load it with require_once 'cmb2/init.php';

If you need anything else or my description is not enough please tell me.

Thanks!

@brunoramalho
Copy link
Contributor

Ok, I'll try to reproduce your setup in my Window and Mac environments, and try to identify the problem.

How do you use the yeoman is easier to reproduce the environment, if you can give me only the configuration file yeoman for the settings remain identical, would help a lot.

@cnasikas
Copy link
Author

I use this generator https://github.com/wesleytodd/YeoPress

.yeopress file:

{
"wpVer": "4.0",
"url": "http://localhost/ai",
"tablePrefix": "wp_",
"dbHost": "localhost",
"dbName": "ai",
"dbUser": "ai",
"dbPass": "ai",
"git": false,
"customDirs": true,
"wpDir": "cms",
"contentDir": "content",
"installTheme": false,
"saltKeys": ""
}

I removed the saltKeys value because it was too long for the editor

Thanks!

@cfoellmann
Copy link

I have the same problem.
Running my dev env on VVV with wp-config.php:

define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/../wp-content' );

plus the corresponding change to the vhost to grap the files from the correct directory.
Asset urls resolve as https://site8.wpmu-trunk.dev/srv/www/wp-content/plugins/cmb2/css/cmb2.css?ver=4.1-alpha-20141015 while srv/www/ is part of the path and has nothing to do with the url.

I described the same issue here reduxframework/redux-framework#1566 in some more detail.

@zabatonni
Copy link

same here, on windows localhost im getting wrong url for css and js files

@zabatonni
Copy link

for now i'm using filter hook like this

add_filter('cmb2_meta_box_url','zaba_filter_cmb2_url');
function zaba_filter_cmb2_url() {
return plugins_url('CMB2/');
}

btw you should consider using plugins_url, it works on all platforms...

@jtsternberg
Copy link
Member

CMB2 is not always in the plugins directory. It can be bundled w/ other plugins, themes, or placed in mu-plugins. Are you using the most recent version (on github)?

@zabatonni
Copy link

thats true, i never thought about it that way..
yup, using most recent version from github

@wesdekoninck
Copy link

I am having a similar problem on my local hosted version of sites (Windows 7 + XAMPP). I was able to resolve the issue by modifying the cmb2_dir() function in the CMB2.php directory. It appears there is an issue with the wp_normalize_path() function that is messing with the localhost file locations. When I remove this function for the return call of cmb2_dir() the issue is resolved and all necessary files load as expected.

Here is the modified function:

function cmb2_dir( $path = '' ) {
    return trailingslashit( dirname( __FILE__ ) ) . $path ;
}

Not sure if that helps at all, but it worked for me.

@jtsternberg
Copy link
Member

tagging @pmgarman, as he's hopefully going to do some extensive testing in windows environments.

@johnenriquez
Copy link

zabatonni's filter worked perfectly for me. thank you so much! pmgarman, please keep us updated on the status of this - your hard work is appreciated!

@ravensorb
Copy link

Has this issue been resolved?

@jtsternberg
Copy link
Member

@ravensorb it will likely always be an issue if using a non-standard WP installation, but that is the purpose for the 'cmb2_meta_box_url' filter: https://github.com/WebDevStudios/CMB2/wiki/Troubleshooting#cmb2-urls-issues

@ravensorb
Copy link

Have you considered using something like the plugin_urls() method?

https://codex.wordpress.org/Function_Reference/plugins_url

@zabatonni
Copy link

@ravensorb just read above

@ravensorb
Copy link

ravensorb commented Apr 20, 2016

Ok, I missed the one post on using the plugins_url. It still might be worth using that as the default and then maybe providing a way to override it so that other packages to set a "root path" or "path prefix" if needed.

@jtsternberg
Copy link
Member

@ravensorb I've pushed an update to the trunk branch that checks if CMB2 is in the plugins or mu-plugins dir, and uses plugins_url by default if so. That should address some of the issues in this thread, but please test and let me know. thank you.

jtsternberg added a commit that referenced this issue Apr 20, 2016
…bizarre cases. Also include normalize_path wrapper for back-compat. Fixes #27, Fixes #432
@jtsternberg
Copy link
Member

This issue should be solved for almost all use-cases now (without need to filter). If any of you are able to test with the trunk branch, please do so.

@karwanmino
Copy link

i use a metabox to pick fontawesome Icon into post types - it works perfectly in local host with all plugins - WP 4.7.5 but when i run on my Host it freezes and dont respond the functionality with WP 4.7.4 with all the same plugins.

@karwanmino
Copy link

Please any help ? what should be the main cause ? for more info i used different Tiny MCE and CMB2 plugins in the same theme ..

any help will be appreciated ..

<3

@tw2113
Copy link
Contributor

tw2113 commented May 23, 2017

I'd do some inspecting with your browser's developer tools to check for any issues in the console and network tabs. It's really hard for us to say at all what's going on without any other information.

@karwanmino
Copy link

look at the left side of any post in my /blog page here http://zax.themecompiler.com/blog/ there we have a logo that logo can be added or no in my dashboard post editor with my integrated metabox section , but that not active to work on this server right now that logo added as default but in my local host it works perfectly with all the same installations.

is it clear now ?

@tw2113
Copy link
Contributor

tw2113 commented May 28, 2017

The only logos I'm seeing on the left are the skype logo with the first one shown. With dev tools, I noticed that there is a but it's not showing anything. It also appears to be missing the generic "fa" class. Is this what's supposed to show something for the second post?

Not really seeing anything wrong regarding paths here, but I may be wrong. Network tab for my browser dev tools isn't showing anything for 404 errors or similar, so everything trying to be loaded, is succeeding.

@karwanmino
Copy link

karwanmino commented May 28, 2017 via email

@tw2113
Copy link
Contributor

tw2113 commented May 28, 2017

I am still curious what you're seeing with your browser dev tools and what may or may not be getting held up with the requests to the browser. This is something that can be checked on and screenshot without setting up any sort of team viewer session.

Providing the code you're using on all parts may present something as well. Also anything in error logs that look suspicious or related would also help.

@zdenekhatak
Copy link

zdenekhatak commented May 31, 2018

I'm using the latest stable version and still facing this issue. I'm using custom WP folder structure (different WP_CONTENT_DIR).

Using the cmb2_meta_box_url filter helps though. I'm using this code to fix this - just defining a constant in wp-config and using it.

function update_cmb2_meta_box_url( $url ) {
	if (defined('TCH_CMB_URL_PREFIX')) {
		return str_replace(TCH_CMB_URL_PREFIX, '', $url);
	} 

	return $url;
}

// fix cmb2 assets error due to custom wp folder structure
add_filter( 'cmb2_meta_box_url', 'update_cmb2_meta_box_url' );```

@tw2113
Copy link
Contributor

tw2113 commented May 31, 2018

Pretty much what the filter is for, to help aid for alternative locations or simply when CMB2 itself can't accurately locate the proper place.

@jtsternberg
Copy link
Member

I'm using custom WP folder structure

Please post a new issue, listing exact duplication instructions, and possibly others on windows systems can create a PR to address the situation. As it is now, you're commenting on a closed issue and not providing much for others to test with.

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