最终进入带有Wordpress网站的项目。我试图将数据从WPforms制成的表单发布到外部API。这不是一个wordpress的家伙,但我读到我可以通过编写自己的插件与其他插件互动。这是我的插件
<?php
/**
* Plugin Name: name
* Plugin URI: http://www.mywebsite.com/my-first-plugin
* Description: plugin to post user data from wp form
* Version: 1.0
* Author: John
* Author URI: http://www.mywebsite.com
*/
function register_lsf_mobile_user( $fields, $entry, $form_data, $entry_id ) {
$api_url = "https://lsf-development.firebaseapp.com";
$body = array(
'email' => $fields[1]['value'],
'password' => $fields[1]['value']
);
$request = wp_remote_post( $api_url, array('body' => $body) );
if (is_wp_error($request)) {
$msg = "There was an error trying to register a lsfMobile user.\n";
$msg .= 'Error returned: ' . $error = $request->get_error_message() . "\n\n";
$msg .= "The user below may need to be added to the CRM manually.\n";
$msg .= $body['name'] . ' ' . $body['email'];
wp_mail( get_bloginfo( 'admin_email' ), 'lsfMobile user registration error', $msg );
}
}
add_action( 'wpforms_process_complete_16522', 'register_lsf_mobile_user', 10, 4 );
在压缩,上传/安装并激活上述自定义插件之后,我尝试通过将wp_form嵌入到私有页面中并输入和提交数据来对其进行测试。但是,我的动作钩子似乎没有被调用。我尝试做回声“ alert(“ ...”)