Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End include_once issue

  • This topic is empty.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #144117
    asiek
    Participant

    I 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 :/

    #144124
    chrisburton
    Participant

    You 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’); ?>

    #144128
    asiek
    Participant

    @chrisburton Hello Chris thanks for your time :)
    I just tried out both of those but I still get the error messages :(

    #144133
    chrisburton
    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

    http://localhost/wordpress/wp-content…etc

    #144136
    asiek
    Participant

    I used this//

    include_once( 'http://domain[.]com/test/wp-content/mu-plugins/metaboxes/meta_box.php' );

    But no luck.

    #144143
    chrisburton
    Participant

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

    #144148
    chrisburton
    Participant

    @traq

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

    #144166
    asiek
    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/&#8221;)

    Which looks to me like a solution…but I wasn’t able to get it to work.
    *sigh*

    #144167
    asiek
    Participant

    Here 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' ); 
    }
    #144168
    asiek
    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_urlhttp://codex.wordpress.org/Function_Reference/content_url&#8221;), 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!

    #144169
    asiek
    Participant

    oops I meant I was trying to get the file from my theme’s directory the whole entire time*…

    #144177
    chrisburton
    Participant

    So it’s solved?

    #144232
    asiek
    Participant

    @chrisburton Yes lol I stated in my last comments that instead of using get_template_directory_uri() I needed to use content_url() .

    I am not sure how to mark this post as solved…

Viewing 13 posts - 1 through 13 (of 13 total)
  • The forum ‘Back End’ is closed to new topics and replies.