Programming an php api with wordpress functions
-
Hello everyone!
I want to programm an plugin for my website, which should be actually an api which returns for every user his own specific data (json files in the filesystem). For user access I want to use built-in functions and functions delivered from other plugins has_user_access(user, area) for example from an other plugin. So if I want to use those wordpress functions I cant write only a .php file and place it somewhere, because the wordpress functions are not included here.
So I found 3 solutions around at the moment:
1. Somewhere I found, that you can write a .php file and include wp_load.php. But that method seems not to be recommended.
2. Next I thought about writing a custom page template, which includes only my php code and does not use page content functions like header, footer, the_content and bind that page to a subpage. So when that subpage is called for example website/myapi the php code inside the page template handles the request and gives only back the json file and I can use the wordpress functions I need inside it.
3. Use the official Wordpres Rest API Plugin. But it seems a little bit overkill for the purpose to give json files from the filesystem back since I can do the user control with existing functions and not need the authentication methods of the Rest API?
1 seems to be really bad so I will choose 2 or 3. What do you think about solution 2. Are there any disadvantages? Should I better use solution 3?
Best regards,
- The topic ‘Programming an php api with wordpress functions’ is closed to new replies.