我正在使用WPCasa儀表板插件來允許用戶提交房地產對象。我必須使用外部服務來驗證對象。我想阻止WP更新數據庫,如果來自服務的響應有錯誤。停止wordpress提交如果無效。 (WPCasa)
我爲我的功能使用wpcasa自己的鉤子。
這是我的孩子主題functions.php
部分:
function newListingAdded($ID, $post) {
...
if ($post->post_date === $post->post_modified) {
// new post
$response = wp_remote_post($targetUrl.'listings/new', $options);
} else {
$response = wp_remote_post($targetUrl.'listings/update', $options);
}
$output = json_decode($response['body']);
if (is_array($output)) {
$_SESSION['messages'] = [];
foreach ($output as $error) {
if (isset($error->msg)) {
array_push($_SESSION['messages'], ['danger', $error->msg]);
}
}
}
}
add_action('publish_listing', 'newListingAdded', 10, 2);
到目前爲止一切正常像預期。我只是無法弄清楚如何停止實際提交數據的WordPress。