CMB2 / CMB2

CMB2 is a developer's toolkit for building metaboxes, custom fields, and forms for WordPress that will blow your mind.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resources do not load with custom WP_CONTENT_DIR & WP_CONTENT_URL

cnasikas opened this issue · comments

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.

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

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!

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.

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!

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.

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

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...

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)?

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

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.

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

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!

commented

Has this issue been resolved?

@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

commented

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

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

@ravensorb just read above

commented

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.

@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.

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.

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.

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

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.

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 ?

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.

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.

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' );```

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.

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.