/wp-json/contact-form-7/v1/contact-forms/{postId}/feedback
フォームの送信先はAjaxでここにアクセスしてた。
ここで作成されたカスタムエンドポイント
plugins/contact-form-7/includes/rest-api.php
register_rest_route( $namespace,
'/contact-forms/(?P<id>\d+)/feedback',
array(
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'wpcf7_rest_create_feedback',
'permission_callback' => '__return_true',
),
)
);
function wpcf7_rest_create_feedback( WP_REST_Request $request ) {
$url_params = $request->get_url_params();
$item = null;
if ( ! empty( $url_params['id'] ) ) {
$item = wpcf7_contact_form( $url_params['id'] );
}
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7' ),
array( 'status' => 404 )
);
}
$result = $item->submit();
$unit_tag = $request->get_param( '_wpcf7_unit_tag' );
$response = array(
'into' => '#' . wpcf7_sanitize_unit_tag( $unit_tag ),
'status' => $result['status'],
'message' => $result['message'],
'posted_data_hash' => $result['posted_data_hash'],
);
wpcf7_contact_formで取得したインスタンスのsubmitを実行してるので中身をみる
contact-form.php
public function submit( $args = '' ) {
$args = wp_parse_args( $args, array(
'skip_mail' =>
( $this->in_demo_mode()
|| $this->is_true( 'skip_mail' )
|| ! empty( $this->skip_mail ) ),
) );
if ( $this->is_true( 'subscribers_only' )
and ! current_user_can( 'wpcf7_submit', $this->id() ) ) {
$result = array(
'contact_form_id' => $this->id(),
'status' => 'error',
'message' => __(
"This contact form is available only for logged in users.",
'contact-form-7'
),
);
return $result;
}
$submission = WPCF7_Submission::get_instance( $this, array(
'skip_mail' => $args['skip_mail'],
) );
$result = array(
'contact_form_id' => $this->id(),
'status' => $submission->get_status(),
'message' => $submission->get_response(),
'demo_mode' => $this->in_demo_mode(),
);
if ( $submission->is( 'validation_failed' ) ) {
$result['invalid_fields'] = $submission->get_invalid_fields();
}
switch ( $submission->get_status() ) {
case 'init':
case 'validation_failed':
case 'acceptance_missing':
case 'spam':
$result['posted_data_hash'] = '';
break;
default:
$result['posted_data_hash'] = $submission->get_posted_data_hash();
break;
}
do_action( 'wpcf7_submit', $this, $result );
return $result;
}