2

最终完成了一个带有 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 嵌入到私人页面并输入和提交数据来对其进行测试。但是,我的动作钩子似乎没有被调用。我试着做 echo " alert("...")

4

0 回答 0