説明

について wpforms_post_submissions_process アクションは、最初のフィールドバリデーションが通過した後、フォーム入力処理中に発生します。

パラメータ

ポストID
int (必須)投稿ID。
フィールド
配列エントリーフィールドの値/プロパティをサニタイズ。
フォームデータ
配列フォームの設定/データ。
$entry_id
int (必須)エントリーID。

ソース

wpforms-post-submissions/src/Plugin.php

詳細情報

について wpforms_post_submissions_process アクションは、フィールドが検証された後、エントリーの保存処理中に実行されます。

このアクションはエントリーを保存し、投稿から記事の作成を開始します。

以下に示す例では、WordPressカスタムフィールドの作成を使って、投稿に割り当てるカスタム・メタ・フィールドをいくつか作成します。

この例では、フォームID1159に投稿された各著者のソーシャルフォローリンクを構築します。

/**
 * Action fires after form submission and validation.
 *
 * @link   https://wpforms.com/developers/wpforms_post_submissions_process/
 *
 * @param  int      $post_id     Post ID.
 * @param  array    $fields      Sanitized entry field values/properties.
 * @param  array    $form_data   Form settings/data.
 * @param  int      $entry_id    Entry ID.
 *
 * @return array
 */

function wpf_dev_post_submissions_process( $post_id, $fields, $form_data, $entry_id ) {

    // Only do this for form #1159.
    if ( absint( $form_data[ 'id' ] ) !== 1159 ) {
        return;
    }

    /*
     * Field IDs, for reference.
     * 21 - Twitter URL
     * 22 - Facebook URL
     * 23 - Dribble URL
     * 24 - Instagram URL
     */

    // Below we're going to create our new custom content template,
    // using the field IDs listed above
    ob_start();
    ?>
    <h2><em>Author Social Follow Links</em></h2>
    <div class="social_links">
    <a href="<?php echo esc_url( $fields[21][ 'value' ] ); ?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/twitter.png" class="author_social_follow" width="80" height="80" alt="Follow me on Twitter!" /></a>
    <a href="<?php echo esc_url( $fields[22][ 'value' ] ); ?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/facebook.png" class="author_social_follow" width="80" height="80" alt="Follow me on Facebook!" /></a>
    <a href="<?php echo esc_url( $fields[23][ 'value' ] ); ?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/dribbble.png" class="author_social_follow" width="80" height="80" alt="Follow me on Dribbble!" /></a>
    <a href="<?php echo esc_url( $fields[24][ 'value' ] ); ?>" target="_blank"><img src="<?php echo get_template_directory_uri(); ?>/images/instagram.png" class="author_social_follow" width="80" height="80" alt="Follow me on Instagram!" /></a>
    </div>
    <?php
    $content = ob_get_clean();

    remove_filter( 'content_save_pre', 'wp_filter_post_kses' );
    remove_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );

    $post = array(
        'ID'           => $post_id,
        'post_content' => $content,
    );
    wp_update_post( $post );

    add_filter( 'content_save_pre', 'wp_filter_post_kses' );
    add_filter( 'content_filtered_save_pre', 'wp_filter_post_kses' );
}
add_action( 'wpforms_post_submissions_process', 'wpf_dev_post_submissions_process', 10, 4 );

参考記事