mustardBees / cmb_field_map

Google Maps field type for Custom Metaboxes and Fields for WordPress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work inside a theme

famfam opened this issue · comments

I'm trying to put it inside theme but doesn't work.

CMB works ok.
Others metaboxes are showing fine.

This one doesn't show map and reviewing with Firebug find this error inside script.js called:
You don't have permission to access ...addresstomytheme.../inc/metaboxes/cmb_field_map/js/script.js
on this server.

When I comment this line define( 'PW_GOOGLE_MAPS_URL', plugin_dir_url( FILE ) ); and replace by define( 'PW_GOOGLE_MAPS_URL', trailingslashit( get_stylesheet_directory_uri() . '/inc/metaboxes/cmb_field_map/cmb-field-map.php' ) );

I found this error: Fatal error: Call to undefined function add_filter() in ...addresstomytheme...\inc\metaboxes\cmb_field_map\cmb-field-map.php on line 30

I’m aware that a number of people bundle the field within their theme. I will update the installation instructions I quickly put together with a note regarding usage within themes.

Your thinking is correct. The PW_GOOGLE_MAPS_URL path needs updating to reflect your themes directory structure. Try:

define( 'PW_GOOGLE_MAPS_URL', get_stylesheet_directory_uri() . '/inc/metaboxes/cmb_field_map/' );

Let me know if you have any further trouble.

I think this is important, the ability of CMB2 to be used inside a theme without a plugin is a great functionality

Hi @danieljulia. If you're going to include this field directly in your theme, you just need to ensure the scripts and styles are loaded from the correct location.

There is an alternative which I recommend you look into. Check out TGM Plugin Activation. Not only can you define plugin dependencies from the WordPress plugin directory, you can also bundle a plugin's ZIP file in with your theme. However, this does add an extra step for the end user to install the required plugins.

great, i fixed it changing the location, but i think it would be really nice if it could work out of the box inside a theme without plugins, for instance in a multisite installation sometimes is complicated to activate plugins.

Thanks for your work! it's great