开发者 | lev0 |
---|---|
更新时间 | 2023年2月22日 11:28 |
PHP版本: | 7.0.0 及以上 |
WordPress版本: | 6.1.1 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
slashpress_command_${command}
slashpress_command
slashpress_help_${command}
slashpress_help
wp_schedule_single_event()
to run the task in the background and POST a status message back upon completion.
By itself, this plugin doesn't do anything. It is aimed at developers and maintainers to abstract away the boring plumbing and authentication, allowing you to keep your code DRY. It supports authentication by both tokens and HMAC signatures. There is no limit on the number of such integrations this endpoint can handle. Only POST method requests are accepted and sent so access logs are kept clean. The interactive help keyword is configurable.
There is no logging, metrics, analytics, nags, or anything that would violate your privacy or GDPR obligations contained in this plugin. It is not freemium; there is no 'Pro' version.
wp-content/plugins/
directory, or install the plugin through the WordPress Plugins screen directly.help
.Running any task any task that you want to start immediately from the comfort of your chat app. It's great for providing instant summaries, triggering actions like backups, clearing/preloading caches of optimisation plugins, updating copies of remote data.
Your code can respond with anything you need, from a simple OK
to a full tabulated response using Markdown:
|Order stat|Count|
|:---|---:|
|New orders today|27|
|Orders to fulfil|8|
|Unpaid orders|2|
A simple example is probably best:
add_action(
'slashpress_help'
, function(SlashPress\Command $slash, string $help_terms) {
$slash->addHelp('flubbers', 'flubbers
Gets the latest map of nearby flubbers.')
->addHelp('gronks', 'gronks
Updates the list of the top 100 gronks and their values.')
->addHelp('uncache', 'Site content not looking quite right? Use uncache
to clear the out the generated pages.');
}
, 100
, 2
);
add_filter(
'slashpress_command'
, function($initial_response, SlashPress\Command $slash) {
if (!$slash->known) {
$text = trim($slash->data['text']);
switch ($text) {
case 'flubbers':
case 'gronks':
$slash->handled = true;
wp_schedule_single_event(time(), 'big_data_fetch_cron_event_hook', [$text, $slash]);
return 'Big data fetch queued.';
case 'uncache':
$slash->handled = true;
if (function_exists('w3tc_flush_posts')) {
w3tc_flush_posts();
return 'Cleared the post cache.';
}
return 'No cache found to clear.';
}
}
return $initial_response;
}
, 10
, 2
);
add_action(
'big_data_fetch_cron_event_hook'
, function(string $what = null, SlashPress\Command $slash = null) {
$results_bad = $results = [];
if (null == $what || 'flubbers' == $what) {
if (fetch_flubbers()) {
$results[] = 'Flubbers fetched.';
}
else {
$results_bad[] = $results[] = 'Could not fetch the flubbers.';
}
}
if (null == $what || 'gronks' == $what) {
if (fetch_gronks()) {
$results[] = 'Gronks fetched.';
}
else {
$results_bad[] = $results[] = 'Could not fetch the gronks.';
}
}
if ($slash) {
if ($slash->canRespondDelayed()) {
$slash->respondDelayed(implode(" \n", $results));
}
}
elseif ($results_bad) {
echo implode(" \n", $results_bad);
}
}
);