Automate WordPress Install from python

2019-05-16 17:50发布

I have a python program that sets up a wordpress site on my server. It downloads the zip and unzips it into a directory, sets up the database and user, configures the config file. Now I would like to call the the wp_install function in wp-admin/include/upgrade.php and pass it the parameters it needs $weblog_title, $user_name, $admin_email ...

My question is how can I call this function from python? Can I do a urllib.urlopen and if so how do I call the wp_install function with the right parameters?

2条回答
一纸荒年 Trace。
2楼-- · 2019-05-16 18:22

It looks like wp_install() gets called inside of /wp-admin/install.php during step 1, and after form data has been validated. If you submit ?step=1& ... (all of the other required form fields) it should result in calling wp_install. So yes, you should be able to use urllib(2) for this.

查看更多
Evening l夕情丶
3楼-- · 2019-05-16 18:25

Urllib is an option, but because your script is running on the local machine anyway, I would probably use os.system. That way you can execute the php script like from a shell. You have to look into the php file on how to pass the parameters.

查看更多
登录 后发表回答