I need to get username, password etc from the wp-config
file to connect to a custom PDO database.
Currently I have another file where I have this info, but I would like to only use the wp-config
.
So how can I read the different properties of wp-config
?
I have even defined my own constants in in wp-config.php and managed to retrieve them in theme without any includes.
wp-config.php
functions.php
outputs DEFAULT_ACCESS :employee
Here’s some same code.
I would just include the file then I would have access to the variable in it varibales.
This is assuming you’re on the same server and you can access wp-config.php through the file system.
If you’re doing this for a plugin, these values are already available. You won’t need to include the file again.
You can get all the global constants from wp-config.php simply echo the const like that:
Here is a function to read all WP DB defines:
this returns an array like this:
If you want to connect to DB, for current versions of PHP, using mysqli extention is recommended (mysql extention is going to deprecate):
Just add required wp-load.php file.
you can use all wordpress functionality like
get_recent_posts() and many more…