I'm trying to call action from 'wpcf7_mail_sent' hook (form submitted from frontend from not logged in user). It's not working. If I call same method from hook, that attached to 'save_post' hook - it works. I update post from admin panel.
Code samples:
plugin #1 (This part works)
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 );
plugin #1 (this part throws 500 error)
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;
}
}
plugin #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
}
}