Support » Plugin: New Nine Adaptive Images » Doesn't work automatically if you install WP in a subfolder (FIX included)

  • Hi,

    By default, the plugin doesn’t work if you diverge at all from the standard WordPress installation of:

    /wordpress
    /wordpress/wp-content/
    /wordpress/wp-content/plugins

    The plugin initially tries to load WordPress and it looks for it by breaking apart the url, assuming it’ll see wp-content somewhere in there (near line 25). My install is like the increasingly common git based WP installs so there is no wp-content folder:

    /my-site/wordpress
    /my-site/app/
    /my-site/app/plugins
    /my-site/app/themes

    I initially hard-coded the path to get it to work but tried to drum a fix that would work for most people. If the plugin were on github I’d fork and pull request but instead I’ll just paste it in here in case anyone else goes searching. 🙂

    In adaptive-images.php…7
    Replace:

    /*---Find and load wp-load so we can access the database---*/
    $parse_uri = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
    $wp_load = $parse_uri[0].'wp-load.php';
    require_once($wp_load);

    with:

    function fs_get_wp_path()
    {
        $path = false;
    	$document_root  = $_SERVER['DOCUMENT_ROOT'];
    
        if (@file_exists($document_root . "/wp-load.php")) {
            $path = $document_root;
        }
        else if (@file_exists($document_root . "/wordpress/wp-load.php")) {
            $path = $document_root . "/wordpress/";
        }
        else if (@file_exists($document_root . "/wp/wp-load.php")) {
            $path = $document_root . "/wp/";
        }
        else {
    		$path = false;
    	}
    
        return $path;
    }
    $WPpath = fs_get_wp_path();
    
    /*---Find and load wp-load so we can access the database---*/
    $parse_uri = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
    $wp_load = $WPpath . 'wp-load.php';
    if ( ! $WPpath ){
    	$errorMessage = "We can't find your WordPress Install. Check line 50 of adaptive-images.php.";
    	sendErrorImage($errorMessage);
    	die;
    }
    require_once($wp_load);

    Those are the three most common WP installation directories so it would hopefully cover most installs. This code may suck, I dunno but it worked for me! A note on the installation page to let people know (to use this or hardcode it) would really help.

    Thanks for the plugin.

    PS. This guide on github helped me to sort out the issues https://github.com/MattWilcox/Adaptive-Images/issues/22#issuecomment-19578982

    http://wordpress.org/plugins/new-nine-adaptive-images/

  • The topic ‘Doesn't work automatically if you install WP in a subfolder (FIX included)’ is closed to new replies.