Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a project with WP, a bit like a plugin, but not quite one.

I'm encountering an issue, when trying to include a file that contains some custom SQL functions in a class, in a completely different file, I get redirected to http://example.com/folder1/file.php/wp-admin/install.php

Which states that I've already installed WP and I need to uninstall it before I can install it again.. But I'm not trying to install/re-install WP.

^ That sounds kinda complicated, let me give an example:

I have file1.php and file2.php. file1.php contains many SQL functions that I wrote to access the DB which WP uses.

And file2.php contains a class that includes file1.php, so I can use some of the SQL functions in the class.

Now, I first tested it with calling some SQL functions (from file1.php) in the class and came across this issue. After some debugging (removing lines, one by one), the issue was the line that includes file1.php (the file with all the SQL functions in it)

So for some reason, everytime I include file1.php in file2.php I get redirected to: http://example.com/folder1/file2.php/wp-admin/install.php

Any ideas why this is happening and how I can fix it?

Forgot to mention something:

file1.php (with all the SQL functions) does include wp-config.php to get the DB info, which could be related to this issue, right?

share|improve this question
add comment

2 Answers 2

Forgot to mention something:

file1.php (with all the SQL functions) does include wp-config.php to get the DB info, which could be related to this issue, right?

Dollars to doughnuts, this is your problem. You should never, ever, ever need to load wp-config.php directly.

Are you trying to access WordPress functions from outside WordPress?

Edit

To access WordPress functions from outside the normal WordPress environment, you want to include wp-load.php, not wp-config.php.

Basic example:

<?php
require( 'path/to-wordpress/wp-load.php' );
?>

Edit 2

I don't [need to access WordPress functions]. Just the DB info (host,user,password). The app I'm working on installs some extra tables in the WP db. The app will not need to touch any of WP's data. IT just uses the DB info to access its own data, in its own tables just using the same Database as the one WP uses. I would prefer to just make my own DB in the users MySQL but most users wont have permission to do so. So I have to use WP's database, but my own tables. Although the app requires WP to be installed, I don't need to access any of WP's functions ATM.

In this case, you don't need to load WordPress. You're simply accessing the database. Just omit the line entirely.

share|improve this answer
    
"Are you trying to access WordPress functions from outside WordPress?" if by that, you mean, file1.php and file2.php are not in the WP directory, then yes. But I'm trying to execute file2.php outside. Not in the WP GUI. How would I access the DB info then? Thanks. –  navnav Jan 25 '12 at 16:37
    
I mean outside of the WordPress environment - i.e. external to the normally running WordPress script, which appears to be the case, based on your comment. You need to use wp-load.php, not wp-config.php. See updated answer. –  Chip Bennett Jan 25 '12 at 16:42
    
I just tired replacing with wp-config.php with wp-load.php and the same thing is happening. When i remove the line completly, it works. So the issues does lie within including a wp-...php file but its not just the wp-config.php. wp-load.php is doing the same thing too. –  navnav Jan 25 '12 at 16:57
    
Question: why do you need to access WordPress functions? –  Chip Bennett Jan 25 '12 at 17:00
    
I don't. Just the DB info (host,user,password). The app I'm working on installs some extra tables in the WP db. The app will not need to touch any of WP's data. IT just uses the DB info to access its own data, in its own tables just using the same Database as the one WP uses. I would prefer to just make my own DB in the users MySQL but most users wont have permission to do so. So I have to use WP's database, but my own tables. Although the app requires WP to be installed, I don't need to access any of WP's functions ATM. –  navnav Jan 25 '12 at 17:03
show 5 more comments

The bare essentials

If you're about loading only the parts of WP that access the DB, then there's a constant there for you:

define( 'SHORTINIT', true )

Simply combine that with a custom query var, so you can turn it on/off from your wp-config.php file:

if ( 
    isset( $_GET['shortinit'] )
    AND 'true' === $_GET['shortinit']
)
    define( 'SHORTINIT', true )

This allows you to append ?shortinit=true to your URl to run WP without all that shine and glitter. If you need some other API functions, simply extend that wrapper in your config file and include the responsible files too.

But you'll have to set the globals $wp, $wp_query, $wp_the_query yourself. That isn't too hard if you take a look an where and how core does this.

Routing

I also wrote about how you can add non WP rewrite rules in this answer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.