Description

Le wpforms_post_submissions_process se déclenche pendant le traitement de la saisie du formulaire, après la validation initiale du champ.

Paramètres

$post_id
int (Requis) Post ID.
$fields
tableau Valeurs/propriétés des champs d'entrée assainis.
$form_data
tableau Paramètres/données du formulaire.
$entry_id
int (Requis) ID de l'entrée.

Source

wpforms-post-submissions/src/Plugin.php

Plus d'informations

Le wpforms_post_submissions_process se déclenche après la validation des champs, au cours du processus d'enregistrement de l'entrée.

Cette action permet d'enregistrer l'entrée et de commencer à créer le message à partir de la soumission.

Exemples

L'exemple ci-dessous permet de créer des champs méta personnalisés à affecter à l'article en utilisant la création de champs personnalisés de WordPress.

Cet exemple va construire les liens sociaux pour chaque article soumis par l'auteur sur le formulaire ID 1159.

/**
 * 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 );

Articles de référence