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
?
Here is a function to read all WP DB defines:
this returns an array like this:
Here's some same code.
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...
You can get all the global constants from wp-config.php simply echo the const like that:
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