admin管理员组

文章数量:1122832

I am interesting in setting up a Wordpress Website which needs to keep updating certain custom database tables after fetching data from RESTful Web Services, lets say once in a day.

I can achieve this by having a script to make request to REST API, process data and then store it into required tables.

However, I am not sure where to put this script file so cron can call it without any issues (security wise)

  • Can I place these script files at root level of wordpress directory (such as /script1.php, script2.php etc)?
  • Or I create a plugin of the script, would cron be able to access this file placed inside a plugins directory?

UPDATE

  1. There will be multiple scripts used by cron, therefore, I want to make plugins out of each script.. Would cron be table to access files in the plugins directory?

Anyone who can help?

I am interesting in setting up a Wordpress Website which needs to keep updating certain custom database tables after fetching data from RESTful Web Services, lets say once in a day.

I can achieve this by having a script to make request to REST API, process data and then store it into required tables.

However, I am not sure where to put this script file so cron can call it without any issues (security wise)

  • Can I place these script files at root level of wordpress directory (such as /script1.php, script2.php etc)?
  • Or I create a plugin of the script, would cron be able to access this file placed inside a plugins directory?

UPDATE

  1. There will be multiple scripts used by cron, therefore, I want to make plugins out of each script.. Would cron be table to access files in the plugins directory?

Anyone who can help?

Share Improve this question edited Oct 1, 2014 at 12:39 Ghazanfar Mir asked Oct 1, 2014 at 12:00 Ghazanfar MirGhazanfar Mir 1631 gold badge2 silver badges10 bronze badges 6
  • Use the script the WordPress API, the Cron of WordPress or functions? If not, leave outside the installation, is not in the context of this WP install. – bueltge Commented Oct 1, 2014 at 12:15
  • There will be multiple scripts used by cron, therefore, I want to make plugins out of each script.. Would cron be table to access files in the plugins directory? – Ghazanfar Mir Commented Oct 1, 2014 at 12:35
  • @bueltge: I am talking about Cron Jobs, not the wordpress cron. – Ghazanfar Mir Commented Oct 1, 2014 at 12:49
  • Then outside the web root, because security issues. Also is it not in the context with the installation. – bueltge Commented Oct 1, 2014 at 13:09
  • If you are running cron jobs then you should place those files outside web root. A place where these files cannot be accessed directly from browser. – Robert hue Commented Oct 1, 2014 at 13:51
 |  Show 1 more comment

1 Answer 1

Reset to default 0

Assuming you're running cron jobs under your user account, it will have access to any folder that your account has read access to. If you do not need them to be publicly accessible, and you have access to a folder outside your public web root, then for security purposes you should put them outside of the web root.

However, if you are on shared hosting, this may not be possible due to open_basedir restrictions. In that case, you can either create a subdirectory under your main Wordpress directory, or in your plugins folder. You can add an htaccess file to block access from the outside.

本文标签: plugin developmentBest place to keep files that are called by cron jobs