' . esc_html__( 'Start from a template', 'pubforms' ) . ' ' . esc_html__( '(optional)', 'pubforms' ) . '
'; echo '' . esc_html__( 'Pick a template and its fields and settings appear below; you can edit them before or after saving.', 'pubforms' ) . '
'; echo '| style="margin-top:.4em;"> | |
|
|
' . esc_html__( 'Save the form to get its shortcode.', 'pubforms' ) . '
'; return; } echo '' . esc_html__( 'Paste this shortcode into any page or post, or use the "PubForms Form" block:', 'pubforms' ) . '
'; echo 'ID . '"]' ) . '" onclick="this.select();" aria-label="' . esc_attr__( 'Shortcode', 'pubforms' ) . '">
'; $counts = pubforms_entry_counts( $post->ID ); /* translators: 1: total entries, 2: unread entries */ echo ''; if ( 'publish' !== $post->post_status ) { echo '' . esc_html__( 'Publish the form so visitors can see it.', 'pubforms' ) . '
'; } } add_action( 'save_post_pubforms_form', function ( $post_id ) { if ( ! isset( $_POST['pubforms_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['pubforms_nonce'] ) ), 'pubforms_save_form' ) ) { return; } if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! current_user_can( 'edit_post', $post_id ) ) { return; } // The sanitizers validate every field, so the raw arrays are passed straight in. $template_slug = sanitize_key( $_POST['pubforms_template'] ?? '' ); // phpcs:ignore WordPress.Security.NonceVerification -- nonce verified above. $template = null; if ( '' !== $template_slug && '' === get_post_meta( $post_id, '_pubforms_fields', true ) ) { $template = pubforms_template( $template_slug ); } if ( $template ) { update_post_meta( $post_id, '_pubforms_fields', pubforms_sanitize_fields( $template['fields'] ) ); if ( ! empty( $template['settings'] ) ) { update_post_meta( $post_id, '_pubforms_settings', pubforms_sanitize_settings( $template['settings'] ) ); } } else { update_post_meta( $post_id, '_pubforms_fields', pubforms_sanitize_fields( wp_unslash( $_POST['pubforms_fields'] ?? array() ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $settings = pubforms_sanitize_settings( wp_unslash( $_POST['pubforms_settings'] ?? array() ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // Webhooks make the server send requests to addresses of the editor's choosing, so only administrators set them. if ( ! current_user_can( 'manage_options' ) ) { $previous = get_post_meta( $post_id, '_pubforms_settings', true ); $settings['webhook_urls'] = is_array( $previous ) ? (string) ( $previous['webhook_urls'] ?? '' ) : ''; } update_post_meta( $post_id, '_pubforms_settings', $settings ); } } ); add_action( 'admin_enqueue_scripts', function ( $hook ) { $screen = get_current_screen(); if ( $screen && 'pubforms_form' === $screen->post_type && in_array( $hook, array( 'post.php', 'post-new.php' ), true ) ) { wp_enqueue_style( 'pubforms-builder', PUBFORMS_URL . 'assets/admin-builder.css', array(), pubforms_asset_version( 'admin-builder.css' ) ); wp_enqueue_script( 'pubforms-builder', PUBFORMS_URL . 'assets/admin-builder.js', array(), pubforms_asset_version( 'admin-builder.js' ), true ); } } ); /* ---------------------------------------------------------- Forms list */ add_filter( 'manage_pubforms_form_posts_columns', function ( $columns ) { $out = array(); foreach ( $columns as $key => $label ) { $out[ $key ] = $label; if ( 'title' === $key ) { $out['pubforms_shortcode'] = __( 'Shortcode', 'pubforms' ); $out['pubforms_entries'] = __( 'Entries', 'pubforms' ); } } return $out; } ); add_action( 'manage_pubforms_form_posts_custom_column', function ( $column, $post_id ) { if ( 'pubforms_shortcode' === $column ) { echo '' . esc_html( '[pubforms id="' . $post_id . '"]' ) . '';
} elseif ( 'pubforms_entries' === $column ) {
$c = pubforms_entry_counts( $post_id );
/* translators: 1: total entries, 2: unread entries */
echo '' . esc_html( sprintf( __( '%1$d (%2$d unread)', 'pubforms' ), $c['total'], $c['unread'] ) ) . '';
}
}, 10, 2 );