Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - Best Practices for Making Simple Web Services

I am creating a simple web service using WordPress without any plugin or any third party just simple php file placed in site root that receive params and connect directly to WP database via

require_once('../wp-load.php');

and query all data from database via

global $wpdb, $live_site;
$data = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '".$sessionData['userID']."' AND meta_key='last_login_time'")); 

Now every thing is going well but including wp-load.php file will load all wp site with all installed plugins and lots of php files included that really not needed.

I need a way to enhance that "Web Services" by implement YAGNI (You aren't gonna need it)

Basically How to include global $wpdb, $live_site; and all wp functions without load any other unnecessary files?

like image 303
HMagdy Avatar asked Nov 01 '22 02:11

HMagdy


1 Answers

I'd suggest that you check out the WordPress REST API which is proposed for Core inclusion in WordPress 3.9. This way you don't need to hack your own stuff but will get a well tested API that is maintained by the WordPress devs. From what you read the guys over at wordpress.com would like to migrate their own API to the core and they will make sure no terrible performance issues hit their servers.

like image 73
wedi Avatar answered Nov 12 '22 19:11

wedi