Reputation: 41
is this possible?
To get the JSON
(plugin url) of the form
(fields
, input
types, etc.) how would I have to hook this up in a plugin
?
Then to use the send mechanism of the plugin
how would I transfer my rest POST
to the plugins
send function?
Any ideas would be appreciated
Upvotes: 2
Views: 5671
Reputation: 1617
I know this is two years old, but I needed the same exact thing so I made a plugin and happened to run across this post.
https://github.com/CodeBradley/contact-form-7-rest-api
Upvotes: 0
Reputation: 4156
You can hook in the wpcf7_before_send_mail
action to get POST data right before the mail il sent by CF7.
add_action('wpcf7_before_send_mail', 'my_wpcf7_choose_recipient');
function my_wpcf7_choose_recipient($WPCF7_ContactForm)
{
// use $submission to access POST data
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$subject = $data['subject']
// use WPCF7_ContactForm->prop() to access form settings
$mail = $WPCF7_ContactForm->prop('mail');
$recipient = $mail['recipient'];
// update a form property
$WPCF7_ContactForm->set_properties(array('mail' => $mail));
}
Then in this function you can call your plugin and transfer him $submission
.
And if you want to alter the POST data, you can use the wpcf7_posted_data filter:
add_filter('wpcf7_posted_data', 'my_wpcf7_posted_data');
function my_wpcf7_posted_data($data)
{
$data['subject'] = 'Test ' . $data['subject'];
return $data;
}
Upvotes: 2