I am not sure how relevant this is,i am working with Java based web-application, so in some cases we need to define some properties which can be used in entire web application like

  1. Google API Key
  2. Any other such key value

We tend to define a property file with extension .properties and than JAVA API provide a way to read this file, all we need to pass key name to the API and it wil return the value.

While working with WordPress API, i need to have such use case where i want to define such properties so that i can read them where ever i need those values, i am aware that WordPress read data from its config file but not sure how.

This is what i am trying

  1. Define a file in my theme folder say customProperties
  2. Define some key value pairs inside the file

and than where i need them, all i need to pass the key and it should return me the value associated with it.

I am sure this can be done with the help of DB, but i am looking for file based approach.
One option which seems relevant to me is to define those in my theme’s function.php file

any pointer for this?

2 Answers
2

You certainly could define those values as PHP constants and/or global variables in, for instance, functions.php.

I understand you would, at this point, rather go with a “file based approach” than using the database, but nonetheless, I have to mention that that would be both the standard as well as the best way of doing things.

Have a look at the WordPress Options API.

I haven’t quite understood whether you’re developing a plugin or a theme (you’ve tagged the question plugin-development, but in the question itself you speak of your theme’s files).
At any rate, options would be the way to go.

Leave a Reply

Your email address will not be published. Required fields are marked *