我正在尝试从“wpcf7\\u mail\\u sent”挂钩(未登录用户从前端提交的表单)调用操作。它不起作用了。如果我从钩子调用相同的方法,即连接到“save\\u post”钩子的方法,它会工作。我从管理面板更新帖子。
代码示例:
插件#1(此部分有效)
function event_updated( $post_ID, $post, $update ) {
/*
$post_ID(int) - Post ID.
$post(WP_Post) - Post object.
$update(bool) - Whether this is an existing post being updated or not.
*/
$post_type = get_post_type($post_id);
if ( "event_post_type" != $post_type ) return;
do_action(\'update_event_hook\', $post_ID, $post);
}
add_action( \'save_post\', \'event_updated\', 10, 3 );
插件#1(此部分引发500错误)
add_action( \'wpcf7_mail_sent\', \'set_event_booked\' );
function set_event_booked($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$id = $posted_data[\'post-id\'];
$new_id = $posted_data[\'event-id\'];
$post = new \\stdClass;
$post->ID = intval($posted_data[\'post-id\']);
$post->post_type = \'event_post_type\';
update_post_meta($new_id, \'event_booked\', \'on\');
try {
do_action(\'update_event_hook\', $id, $post);
} catch (Exception $e) {
$error_message = $e->getMessage();
$log_message = \'Add reservaion ERROR: \'. $error_message;
}
}
插件#2
class API_sync_class
{
private static $options;
public static function Init()
{
self::$options = get_option("api_sync");
if (self::$options[\'use\']) {
add_action(\'update_event_hook\', array(\'API_sync_class\', \'AddEditReservation\'), 10, 2);
}
}
public static function AddEditReservation($post_id, $post)
{
API_sync_class::DebugToFile(\'AddEditReservation method:\');
$type = get_post_type($post_id);
if ($type && ($type != \'event_post_type\')) {
return;
}
$appdata = self::AppData($post);
API_sync_class::DebugToFile(\'Data to be sent to API (prepared)\');
API_sync_class::DebugToFile($appdata);
....... Some other code of meethod
}
}