- This topic is empty.
-
AuthorPosts
-
July 22, 2013 at 7:15 pm #144117
asiek
ParticipantI am trying to include a file located in wp-content/mu-plugins
I placed this line of code inside of my mu-plugins.php file:
include_once( 'metaboxes/meta_box.php' );
Added my custom post type & meta box, but I keep getting these error messages:
_Warning: include_once(/home/domain/public_html/metaboxes/) [function.include-once]: failed to open stream: No such file or directory in /home/domain/public_html/test/wp-content/mu-plugins/metaboxes/meta_box.php on line 3_
_Warning: include_once() [function.include]: Failed opening ‘/home/domain/public_html/metaboxes/’ for inclusion (include_path=’.:/usr/local/php52/pear’) in /home/domain/public_html/test/wp-content/mu-plugins/metaboxes/meta_box.php on line 3_
_Warning: Cannot modify header information – headers already sent by (output started at /home/domain/public_html/test/wp-content/mu-plugins/metaboxes/meta_box.php:3) in /home/domain/public_html/test/wp-content/plugins/woocommerce/classes/class-wc-session-handler.php on line 63_
When I include the file in my functions.php file everything works…
But, how exactly can I include it from my /mu-plugins/mu-plugins.php file/directory?Please help :/
July 22, 2013 at 7:54 pm #144124chrisburton
ParticipantYou need to set the correct file path. That’s why you’re getting those errors.
I’m don’t recall WordPress’s structure so it could be something like:
<?php include_once(‘../pluginfile.php’); ?>
or
<?php include_once(‘../../pluginfile.php’); ?>
July 22, 2013 at 8:13 pm #144128asiek
Participant@chrisburton Hello Chris thanks for your time :)
I just tried out both of those but I still get the error messages :(July 22, 2013 at 8:21 pm #144133chrisburton
Participant@Keilowe That’s because it was just an example. Reply with the absolute URL to the file and also the absolute file path where you used
include_once
and got an error.Absolute URL’s look like this:
http://localhost/wordpress/wp-content…etc
or
July 22, 2013 at 8:42 pm #144136asiek
ParticipantI used this//
include_once( 'http://domain[.]com/test/wp-content/mu-plugins/metaboxes/meta_box.php' );
But no luck.
July 22, 2013 at 9:06 pm #144143chrisburton
ParticipantOk so the following is the file you want to include:
http://domain[.]com/test/wp-content/mu-plugins/metaboxes/meta_box.php
Now, what is the path to the file where you’re placing the
include_once
?Also, I just noticed the HEADER error. Did you change any core files?
July 22, 2013 at 9:36 pm #144148chrisburton
ParticipantIt’s not an absolute URL you need
I was trying to figure out where exactly the file was located and how her WordPress was setup.
July 22, 2013 at 11:31 pm #144166asiek
Participant@chrisburton @traq I found part of the issue
in the file I was trying to include I replaced a line a while ago with this//
include_once $_SERVER['DOCUMENT_ROOT'] . "/metaboxes/";
(Why? I have no idea…)Replacing that line with the original “define” code did the trick:
define( 'CUSTOM_METABOXES_DIR', get_template_directory_uri() . '/metaboxes' );
Then I used this inside of my must-use.php file:
include_once( 'metaboxes/meta_box.php' );
Now it works except my whole point in using must-use.php for my CPT is so I wouldn’t have to register the PT for every single theme I create…
This line:define( 'CUSTOM_METABOXES_DIR', get_template_directory_uri() . '/metaboxes' );
Gets the directory from my theme’s folder…
But if I delete “metaboxes” the css and javascript gets disabled from my post type edit screen…How can I define “/metaboxes” from my mu-plugins folder?
I found this post:
[http://youneedfat.com/get-the-mu-plugin-directory-url/](http://youneedfat.com/get-the-mu-plugin-directory-url/ “http://youneedfat.com/get-the-mu-plugin-directory-url/”)Which looks to me like a solution…but I wasn’t able to get it to work.
*sigh*July 22, 2013 at 11:36 pm #144167asiek
ParticipantHere is what I tried to use from reading that post//
add_action('init', 'mu_plugin_urls'); function mu_plugin_urls() { define( 'MU_PLUGIN_URL', plugins_url( 'mu-plugins' , dirname( __FILE__ ) ) ); define( 'MU_MB_URL', MU_PLUGIN_URL . '/metaboxes' ); define( 'MU_MB_CSS_URL', MU_MB_URL . '/css' ); define( 'MU_MB_IMG_URL', MU_MB_URL . '/images' ); define( 'MU_MB_JS_URL', MU_MB_URL . '/js' ); }
July 22, 2013 at 11:59 pm #144168asiek
Participant@chrisburton @traq FINALLY found the main issue ^.^
I was trying to get a file from wp-content/plugins the whole entire time…
I found [this page](http://codex.wordpress.org/Function_Reference/content_url “http://codex.wordpress.org/Function_Reference/content_url”), and there ya have it!
content_url()
is what I should’ve been using!!!I used this line to get everything from /metaboxes directory:
define( 'CUSTOM_METABOXES_DIR', content_url() . '/mu-plugins/metaboxes' );
NOW, I can register all CPT and Metaboxes from my must-use file instead of using my functions file…
Thanks for your time guys!
July 23, 2013 at 12:14 am #144169asiek
Participantoops I meant I was trying to get the file from my theme’s directory the whole entire time*…
July 23, 2013 at 1:58 am #144177chrisburton
ParticipantSo it’s solved?
July 23, 2013 at 9:13 am #144232asiek
Participant@chrisburton Yes lol I stated in my last comments that instead of using
get_template_directory_uri()
I needed to usecontent_url()
.I am not sure how to mark this post as solved…
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.