我试图从'wpcf7_mail_sent‘钩子中调用操作(从前端提交的表单来自未登录用户)。这不管用。如果我从钩子中调用相同的方法,那么附加到'save_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
}
}
发布于 2018-04-10 04:14:46
问题解决了。在我的例子中,出现了'PHP致命错误:调用未定义函数get_home_path()‘。是啊。这很简单。
https://wordpress.stackexchange.com/questions/300269
复制相似问题