0

I have a plugin which needs to update the WP database; however the critical function to do this is NOT on a WP page (it's called from a JS function in the background) so it doesn't have the WP Config file already loaded.

At the moment I've hardcoded the DB name/user/pass into the php function page but I'd rather access the WP config.php file and get these details directly in case the site is moved or the DB credentials are changed in future.

My config.php file is in the root of the directory; is there a simple way to access the DB credentials held there?

1

1 Answer 1

0

You can with a JS file, do an AJAX function that calls a PHP file that can retrieve the information from wp-config.php

In your php File

echo DB_NAME
echo DB_USER
echo DB_PASSWORD
echo DB_HOST
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.