Descrizione
Il wpforms_post_submissions_process
si attiva durante l'elaborazione del modulo, dopo che la convalida iniziale del campo è stata superata.
Parametri
- $post_id
- int (Richiesto) ID post.
- $campi
- array Valori/proprietà del campo di immissione sanificati.
- $form_data
- array Impostazioni/dati del modulo.
- $entry_id
- int (obbligatorio) ID voce.
Fonte
wpforms-post-submissions/src/Plugin.php
Ulteriori informazioni
Il wpforms_post_submissions_process
si attiva dopo la convalida dei campi, durante il processo di salvataggio della voce.
Questa azione salverà la voce e inizierà a creare il post a partire dall'invio.
Esempi
L'esempio mostrato di seguito creerà alcuni meta-campi personalizzati da assegnare al post utilizzando la creazione di campi personalizzati di WordPress.
Questo esempio costruirà i link social follow per ogni post inviato dall'autore sul modulo 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 );Articoli di riferimento