WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] relative paths stopped working in admin (4 posts)

  1. chrismichaels84
    Member
    Posted 1 year ago #

    I am developing a site that is partly built on top of CodeIgniter and the other part is using a hacked version of wordpress. So, what I've done is "injected" CI functionality into the wordpress by including a global bootstrap via a plugin. The bootstrap defines some constants, loads some functions and does the following to create a $CI object:

    [PHP]// Load it only for WordPress and Elgg
    if ( PN_ENVIRONMENT !== 'codeigniter' ) {
    ob_start();
    require(PN_COMMONPATH . '/ci-core/pn-ci-inject.php');
    ob_end_clean();
    $GLOBALS['CI'] = get_instance();
    }[/PHP]

    the pn-ci-inject file loads codeigniter using a blank controller. I then flush the buffer, which wonderfully allows me to use

    global $CI

    to access libraries, helpers, etc.

    However, when I did this, something strange broke. Now, in wordpress, my relative paths are not working. So,

    require('./admin.php');

    or

    require('../../whatever.php');

    produces fatal errors. However, when I replace the paths with constants I've set with the absolute paths, everything works wonderfully. Again, these relative paths worked fine until I created the $CI object.

    I really, really, don't want to go through all of wordpress and replace all relative with absolute paths. What did I do? Does anyone have any idea what this is about?

    Thanks all.

  2. bcworkz
    Member
    Posted 1 year ago #

    Sounds like the working directory got changed for some reason, though I can't imagine why. You can try echoing out getcwd() before and after to confirm. Regardless, you could chdir() to your WordPress directory to fix the relative links.

    FWIW, I'm not convinced you will find many relative links in WP core files, plugin and theme developers are encouraged to not use relative links because directory structures vary for various reasons. Regardless, changing relative paths in an installation is not a workable solution.

  3. chrismichaels84
    Member
    Posted 1 year ago #

    Thank you, that worked well. The only relative links I have found are many of the requires in wp-admin for whatever reason.

  4. chrismichaels84
    Member
    Posted 1 year ago #

    All works well.

Topic Closed

This topic has been closed to new replies.

About this Topic