linux - 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 特定功能,请不要直接为 cron 作业调用 functions.php 文件,而是首先使用我在您发布的上一个问题中提到的两个命令设置 wordpress 环境。
<?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) 如果您的 do_something() 函数不适用于任何与 wordpress 相关的任务,只需复制该函数并在您的 cron 文件中使用它,例如 mycron.php
(3) 您曾询问将建议的代码放在哪里。将建议的代码放在 mycron.php 文件的顶部。
推荐阅读
- html - WordPress 安装后会改变我的整个网页设计吗?
- azure - 如何提前访问 Azure 应用服务中的配置?
- reactjs - 为什么 console.log("hello) 在 React hooks 中打印了六次
- xml - 使用 XSLT 格式化时间
- php - infusionsoft api - 如何通过使用联系人 ID 作为过滤器来获取联系人详细信息
- python - 如何使用python从单独的文件中删除一行
- javascript - Merge JS Together - 数据文本交换并复制到剪贴板
- c++ - 如何在批处理文件中传递文件位置
- python - Tensorflow 不工作:无法加载动态库“nvcuda.dll”;dlerror:未找到 nvcuda.dll
- flutter - 在监听 ObservableList 的 mobx 反应上获得相同的值