My question title might be little confuse. Here is the scenario, For example: I am giving an API service from my wordpress site.
Using it others can know few information. Like if they send a User ID in query URL then i'll send them user phone number.
For Example: If they access the site with www.example.com/?cuid=23
Now on init
hook i'll check if cuid
is present in $_GET
variable, if it is present then i'll get phone number and die the function with phone number. Since init
hook is the earliest hook i choose to use it.
function tell_phone_num(){
if(isset($_GET['cuid'])){
//some one wants the service
//I'll get the phone number and show it -> $user_phone
//setting response format, like json etc
die($user_phone);
}
}
add_action('init','tell_phone_num');
This works fine. When site is accessed with cuid
then only this function will work.
This is just an example but phone number is not my real information. I don't need authentication because the information i am giving in are not sensitive.
Here is my question. Is this correct way to do or should I do some other best practice method.