' . (int) $unread . '' : ''; $hooks = array(); $hooks[] = add_menu_page( __( 'StackMime Forms', 'stackmime-forms' ), __( 'Forms', 'stackmime-forms' ) . $bubble, stackmime_forms_cap(), 'stackmime-forms', 'stackmime_forms_render_entries', 'dashicons-feedback', 26 ); $hooks[] = add_submenu_page( 'stackmime-forms', __( 'Entries', 'stackmime-forms' ), __( 'Entries', 'stackmime-forms' ), stackmime_forms_cap(), 'stackmime-forms', 'stackmime_forms_render_entries' ); $hooks[] = add_submenu_page( 'stackmime-forms', __( 'Forms', 'stackmime-forms' ), __( 'All forms', 'stackmime-forms' ), 'manage_options', 'stackmime-forms-builder', 'stackmime_forms_render_builder' ); $hooks[] = add_submenu_page( 'stackmime-forms', __( 'StackMime Forms settings', 'stackmime-forms' ), __( 'Settings', 'stackmime-forms' ), 'manage_options', 'stackmime-forms-settings', 'stackmime_forms_render_settings' ); $hooks[] = add_submenu_page( 'stackmime-forms', __( 'Getting started', 'stackmime-forms' ), __( 'Getting started', 'stackmime-forms' ), 'manage_options', 'stackmime-forms-guide', 'stackmime_forms_render_guide' ); foreach ( $hooks as $hook ) { add_action( 'admin_print_styles-' . $hook, function () { stackmime_forms_ui_enqueue( STACKMIME_FORMS_URL ); wp_enqueue_style( 'stackmime-forms-screens', STACKMIME_FORMS_URL . 'assets/admin/forms-admin.css', array( 'stackmime-forms-admin' ), STACKMIME_FORMS_VERSION ); wp_enqueue_script( 'stackmime-forms-screens', STACKMIME_FORMS_URL . 'assets/admin/admin.js', array(), STACKMIME_FORMS_VERSION, array( 'in_footer' => true ) ); } ); } } ); add_filter( 'plugin_action_links_' . plugin_basename( STACKMIME_FORMS_FILE ), function ( $links ) { array_unshift( $links, '' . esc_html__( 'Forms', 'stackmime-forms' ) . '', '' . esc_html__( 'Getting started', 'stackmime-forms' ) . '' ); return $links; } ); add_filter( 'plugin_row_meta', function ( $links, $file ) { if ( plugin_basename( STACKMIME_FORMS_FILE ) === $file ) { $links[] = '' . esc_html__( 'Docs', 'stackmime-forms' ) . ''; $links[] = '' . esc_html__( 'Pro add-on', 'stackmime-forms' ) . ''; } return $links; }, 10, 2 ); /** * Header icon. */ function stackmime_forms_ui_icon() { return ''; } /** * Header and tabs shared by the plugin's screens. * * @param string $current Current tab. */ function stackmime_forms_admin_header( $current ) { $tabs = array( 'entries' => array( __( 'Entries', 'stackmime-forms' ), admin_url( 'admin.php?page=stackmime-forms' ), stackmime_forms_unread_count() ? stackmime_forms_unread_count() : '' ), ); if ( current_user_can( 'manage_options' ) ) { $tabs['forms'] = array( __( 'Forms', 'stackmime-forms' ), admin_url( 'admin.php?page=stackmime-forms-builder' ) ); $tabs['settings'] = array( __( 'Settings', 'stackmime-forms' ), admin_url( 'admin.php?page=stackmime-forms-settings' ) ); $tabs['guide'] = array( __( 'Getting started', 'stackmime-forms' ), admin_url( 'admin.php?page=stackmime-forms-guide' ) ); } /** * Tabs in the plugin's header: key => array( label, URL[, count] ). * * @param array $tabs Tabs. * @param string $current Current tab. */ $tabs = (array) apply_filters( 'stackmime_forms_admin_tabs', $tabs, $current ); stackmime_forms_ui_header( array( 'title' => __( 'StackMime Forms', 'stackmime-forms' ), 'sub' => __( 'Lightweight forms that never lose a lead', 'stackmime-forms' ), 'current' => $current, 'tabs' => $tabs, ) ); } /** * Entries screen (list or single entry). */ function stackmime_forms_render_entries() { if ( ! current_user_can( stackmime_forms_cap() ) ) { return; } echo '
'; stackmime_forms_admin_header( 'entries' ); // phpcs:disable WordPress.Security.NonceVerification.Recommended -- display only. if ( isset( $_GET['entry'] ) ) { stackmime_forms_ui_open( false ); stackmime_forms_render_entry( absint( $_GET['entry'] ) ); stackmime_forms_ui_close( false ); echo '
'; return; } $table = new StackMime_Forms_List_Table(); $table->prepare_items(); stackmime_forms_ui_open( false ); if ( isset( $_GET['done'] ) ) { stackmime_forms_ui_alert( 'ok', sanitize_text_field( wp_unslash( $_GET['done'] ) ) ); } if ( ! defined( 'STACKMIME_MAIL_VERSION' ) && ! get_option( 'stackmime_forms_mail_hint_off' ) && current_user_can( 'manage_options' ) ) { stackmime_forms_ui_alert( 'info', __( 'Tip: entries are always saved here, but email alerts sent with your server\'s default mail often land in spam. An SMTP plugin such as StackMime Mail fixes that.', 'stackmime-forms' ) ); } ?>
views(); ?>
search_box( __( 'Search entries', 'stackmime-forms' ), 'smf-search' ); ?>
display(); ?>
'; } /** * Address of one entry. The link carries a nonce tied to the entry, so opening it from the entries list * marks it as read; without a valid nonce (for example a link in an email alert) the entry opens read-only. * * @param int $id Entry ID. */ function stackmime_forms_entry_url( $id ) { return wp_nonce_url( admin_url( 'admin.php?page=stackmime-forms&entry=' . (int) $id ), 'stackmime_forms_read_' . (int) $id, '_smfnonce' ); } /** * Single entry screen. Opening an entry from the entries list (a nonce-protected link) marks it as read. * * @param int $id Entry ID. */ function stackmime_forms_render_entry( $id ) { $entry = stackmime_forms_entry( $id ); if ( ! $entry ) { echo '
' . esc_html__( 'Entry not found', 'stackmime-forms' ) . '' . esc_html__( 'Back to entries', 'stackmime-forms' ) . '
'; return; } $nonce = isset( $_GET['_smfnonce'] ) ? sanitize_key( wp_unslash( $_GET['_smfnonce'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- this is the nonce, verified next. if ( 'new' === $entry->status && '' !== $nonce && wp_verify_nonce( $nonce, 'stackmime_forms_read_' . (int) $id ) ) { stackmime_forms_update( $id, array( 'status' => 'read' ) ); $entry->status = 'read'; } $form = stackmime_forms_get( $entry->form_id ); $link = function ( $op ) use ( $id ) { return wp_nonce_url( admin_url( 'admin-post.php?action=stackmime_forms_entry_action&do=' . $op . '&id=' . (int) $id ), 'stackmime_forms_entry_' . (int) $id ); }; $fields = $form ? $form['fields'] : array(); foreach ( $entry->fields as $key => $value ) { if ( ! isset( $fields[ $key ] ) ) { $fields[ $key ] = array( 'label' => $key, 'type' => 'text', 'options' => array(), ); } } $statuses = array( 'new' => __( 'Unread', 'stackmime-forms' ), 'read' => __( 'Read', 'stackmime-forms' ), 'spam' => __( 'Spam', 'stackmime-forms' ), 'trash' => __( 'Trash', 'stackmime-forms' ), ); // phpcs:disable WordPress.Security.NonceVerification.Recommended -- display only. if ( isset( $_GET['done'] ) ) { stackmime_forms_ui_alert( 'ok', sanitize_text_field( wp_unslash( $_GET['done'] ) ) ); } // phpcs:enable ?>

←

form_id ) . ' #' . $id ); ?>

$field ) : ?> fields[ $key ] ?? '' ); if ( '' === $value ) { continue; } ?>
' . esc_html( $value ) . ''; } elseif ( 'tel' === $field['type'] ) { echo '' . esc_html( $value ) . ''; } elseif ( 'url' === $field['type'] ) { echo '' . esc_html( $value ) . ''; } else { echo nl2br( esc_html( $value ) ); } ?>
created_at . ' UTC' ) ) ); ?>
page_url ) : ?>
page_url, PHP_URL_PATH ) . ( wp_parse_url( $entry->page_url, PHP_URL_QUERY ) ? '?' . wp_parse_url( $entry->page_url, PHP_URL_QUERY ) : '' ) ); ?>
status ] ?? $entry->status ); ?>spam_reason ? ' (' . esc_html( $entry->spam_reason ) . ')' : ''; ?>
email_status ) { echo '' . esc_html__( 'Sent', 'stackmime-forms' ) . ''; } elseif ( 'failed' === $entry->email_status ) { echo '' . esc_html__( 'Failed', 'stackmime-forms' ) . '
' . esc_html( (string) $entry->email_error ) . ''; } else { echo '' . esc_html__( 'Not sent', 'stackmime-forms' ) . ''; } ?>
status ) : ?> status ) : ?> status ) : ?> status ) : ?>
$op ) ); return __( 'Updated.', 'stackmime-forms' ); case 'restore': case 'notspam': stackmime_forms_update( $id, array( 'status' => 'read' ) ); return __( 'Restored.', 'stackmime-forms' ); case 'delete': stackmime_forms_delete( $id ); return __( 'Deleted.', 'stackmime-forms' ); case 'resend': return stackmime_forms_send_notification( $id ) ? __( 'Email alert sent again.', 'stackmime-forms' ) : __( 'The email alert failed again. Check your site\'s email settings.', 'stackmime-forms' ); } return ''; } add_action( 'admin_post_stackmime_forms_entry_action', function () { $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- the nonce is checked next, and is tied to this ID. if ( ! current_user_can( stackmime_forms_cap() ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'stackmime-forms' ), 403 ); } check_admin_referer( 'stackmime_forms_entry_' . $id ); $op = isset( $_GET['do'] ) ? sanitize_key( $_GET['do'] ) : ''; $msg = stackmime_forms_apply_action( $id, $op ); $url = in_array( $op, array( 'resend', 'notspam', 'read' ), true ) ? admin_url( 'admin.php?page=stackmime-forms&entry=' . $id ) : admin_url( 'admin.php?page=stackmime-forms' ); wp_safe_redirect( add_query_arg( 'done', rawurlencode( $msg ), $url ) ); exit; } ); /** * Bulk actions are posted back to the entries screen and handled before any output. */ add_action( 'load-toplevel_page_stackmime-forms', function () { if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'POST' !== sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) || empty( $_POST['ids'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- the nonce is checked below before anything changes. return; } if ( ! current_user_can( stackmime_forms_cap() ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'stackmime-forms' ), 403 ); } check_admin_referer( 'bulk-entries' ); $op = sanitize_key( wp_unslash( $_POST['action'] ?? '-1' ) ); if ( '' === $op || '-1' === $op ) { $op = sanitize_key( wp_unslash( $_POST['action2'] ?? '' ) ); } $ids = array_map( 'absint', (array) wp_unslash( $_POST['ids'] ) ); $n = 0; foreach ( $ids as $id ) { if ( $id && in_array( $op, array( 'read', 'new', 'spam', 'trash', 'restore', 'notspam', 'delete' ), true ) ) { stackmime_forms_apply_action( $id, $op ); ++$n; } } wp_safe_redirect( add_query_arg( 'done', rawurlencode( sprintf( /* translators: %d: number of entries. */ _n( '%d entry updated.', '%d entries updated.', $n, 'stackmime-forms' ), $n ) ), wp_get_referer() ? wp_get_referer() : admin_url( 'admin.php?page=stackmime-forms' ) ) ); exit; } ); /** * CSV export (opens cleanly in Excel; cells can't run formulas). */ add_action( 'admin_post_stackmime_forms_export', function () { if ( ! current_user_can( stackmime_forms_cap() ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'stackmime-forms' ), 403 ); } check_admin_referer( 'stackmime_forms_export' ); $form_id = isset( $_GET['form'] ) ? sanitize_key( $_GET['form'] ) : ''; $status = isset( $_GET['status'] ) ? sanitize_key( $_GET['status'] ) : 'all'; $result = stackmime_forms_query( array( 'form' => $form_id, 'status' => $status, 'per_page' => 100000, 'page' => 1, ) ); nocache_headers(); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename=entries-' . ( $form_id ? $form_id . '-' : '' ) . gmdate( 'Y-m-d' ) . '.csv' ); $out = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen stackmime_forms_write_csv( $out, $result['rows'] ); fclose( $out ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose exit; } ); /** * Save settings. */ add_action( 'admin_post_stackmime_forms_save', function () { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'stackmime-forms' ), 403 ); } check_admin_referer( 'stackmime_forms_save' ); $in = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitised per field. $to = array_filter( array_map( 'sanitize_email', array_map( 'trim', explode( ',', (string) ( $in['notify_to'] ?? '' ) ) ) ), 'is_email' ); update_option( 'stackmime_forms_settings', array( 'notify_to' => implode( ', ', $to ), 'autoreply' => empty( $in['autoreply'] ) ? 0 : 1, 'autoreply_subject' => sanitize_text_field( $in['autoreply_subject'] ?? '' ), 'autoreply_body' => sanitize_textarea_field( $in['autoreply_body'] ?? '' ), 'help_phone' => sanitize_text_field( $in['help_phone'] ?? '' ), 'style' => in_array( $in['style'] ?? '', array( 'clean', 'none' ), true ) ? $in['style'] : 'clean', 'accent' => (string) sanitize_hex_color( (string) ( $in['accent'] ?? '' ) ), 'min_seconds' => min( 20, max( 1, absint( $in['min_seconds'] ?? 3 ) ) ), 'rate_limit' => min( 50, max( 1, absint( $in['rate_limit'] ?? 5 ) ) ), 'max_links' => min( 20, absint( $in['max_links'] ?? 2 ) ), 'retention_days' => min( 3650, absint( $in['retention_days'] ?? 0 ) ), 'delete_on_uninstall' => empty( $in['delete_on_uninstall'] ) ? 0 : 1, ), false ); wp_safe_redirect( admin_url( 'admin.php?page=stackmime-forms-settings&saved=1' ) ); exit; } ); /** * Settings screen. */ function stackmime_forms_render_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $s = stackmime_forms_settings(); echo '
'; stackmime_forms_admin_header( 'settings' ); stackmime_forms_ui_open( true ); if ( isset( $_GET['saved'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- display only. stackmime_forms_ui_alert( 'ok', __( 'Settings saved.', 'stackmime-forms' ) ); } ?>

'; }