Linux + Wordpress:如何从 Linux Cron 作业中触发一个函数? [英] Linux + Wordpress: how to fired a function from a Linux Cron job?

查看:31
本文介绍了Linux + Wordpress:如何从 Linux Cron 作业中触发一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 Linux Cron 作业,例如:

0 0 * * * home/www/wp-content/themes/my_theme/functions.php

文件 wp-content/themes/my_theme/functions.php 具有我需要从 cron 作业调用的函数:do_something().

如您所见,命令是:home/www/wp-content/themes/my_theme/functions.php 是错误的,因为我需要指定我的函数:do_something().

我的问题是:如何更改作业命令以执行函数 do_something().

解决方案

(1) 如果您有要使用的 wordpress 特定功能,请不要直接调用 functions.php 文件进行 cron 作业,但首先使用我提到的两个命令设置 wordpress 环境您之前发布的问题.


(2) 如果您的 do_something() 函数不用于任何与 wordpress 相关的任务,只需复制该函数并在您的 cron 文件中使用它,例如 mycron.php

(3) 你问过把这个建议的代码放在哪里.将建议的代码放在 mycron.php 文件的顶部.

I created a Linux Cron Job like:

0 0 * * * home/www/wp-content/themes/my_theme/functions.php

The file wp-content/themes/my_theme/functions.php has the function I need to call from the cron job: do_something().

As you can see the command is: home/www/wp-content/themes/my_theme/functions.php is wrong, since I need to specify my function: do_something().

My question is: how do chage the job command to execute the function do_something().

解决方案

(1) Do not call functions.php file directly for cron job if you have wordpress specific function to use but setup wordpress environment first with two commands I mentioned in the previous question you had posted.

<?php 
define('WP_USE_THEMES', false);
require('./wp-blog-header.php'); 
//ensure correct *path* for your wp-blog-header.php file
//now you can use function you want from functions.php file directly
do_something();
?>


(2) If your do_something() function is not for any wordpress related task, just copy that function and use it in your cron file, say mycron.php

(3) You had asked where to put this suggested code. Put suggested code at the top of your mycron.php file.

这篇关于Linux + Wordpress:如何从 Linux Cron 作业中触发一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆