Include files for a plugin not including

I have a plugin which I need to include a file in but it doesn’t include.

Here’s the example of the tree:

plugin folder
    /themes
    /folder2
    /somefiles
    /includeme.php

Within themes is

/default
/theme2

Then within each theme are the files
E.g.

Header.php
Footer.php

The plugin simply switches these themes via the admin.

Now in header.php I added

<?php include('includeme.php'); ?>

Which didn’t work.

A friend told me since it is two levels up the tree I should actually add

<?php include('/../../includeme.php'); ?>.

Both didn’t work.

I googled something that said to try.

<?php include([$_SERVER]['DOCUMENT_ROOT']'./wp-content/plugins/plugin-name/includeme.php'); ?>.

That also didn’t work.
This is a basic plugin which renders theme based on admin settings combined with user agent detection.

Any suggestions or further code required?

The code is located at http://pastebin.com/A3buAA0R

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

In your main plugin file, use plugin_dir_path to define a constant that you can then use in all of your includes. see the example on the above codex page.

// define the constant in your main plugin file
define( 'MYPLUGINNAME_PATH', plugin_dir_path(__FILE__) );

then, to include your file:

include MYPLUGINNAME_PATH . 'includeme.php';


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x