'unread' ) ); $bubble = $unread ? ' ' . number_format_i18n( $unread ) . '' : ''; self::$entries_hook = add_menu_page( __( 'ALPEG Forms', 'alpeg-forms' ), __( 'ALPEG Forms', 'alpeg-forms' ) . $bubble, 'manage_options', 'alpeg-forms', array( __CLASS__, 'render_entries' ), 'dashicons-feedback', 26 ); add_submenu_page( 'alpeg-forms', __( 'Submissions', 'alpeg-forms' ), __( 'Submissions', 'alpeg-forms' ), 'manage_options', 'alpeg-forms', array( __CLASS__, 'render_entries' ) ); add_submenu_page( 'alpeg-forms', __( 'Settings', 'alpeg-forms' ), __( 'Settings', 'alpeg-forms' ), 'manage_options', 'alpeg-forms-settings', array( Settings::class, 'render' ) ); // Import & export: forms from other plugins, old submissions, template files. add_submenu_page( 'alpeg-forms', __( 'Import & export', 'alpeg-forms' ), __( 'Import & export', 'alpeg-forms' ), 'manage_options', 'alpeg-forms-import', array( Importer::class, 'render' ) ); // The license page only appears once a license module (Pro add-on) is installed. if ( License::has_module() ) { add_submenu_page( 'alpeg-forms', __( 'License', 'alpeg-forms' ), __( 'License', 'alpeg-forms' ), 'manage_options', 'alpeg-forms-license', array( License::class, 'render_page' ) ); } add_action( 'load-' . self::$entries_hook, array( __CLASS__, 'load_entries' ) ); } /** * Load CSS only on our own pages. * * @param string $hook Hook suffix. */ public static function assets( $hook ) { if ( false === strpos( $hook, 'alpeg-forms' ) ) { return; } wp_enqueue_style( 'alpeg-forms-admin', ALPEG_FORMS_URL . 'assets/css/admin.css', array(), ALPEG_FORMS_VERSION ); } /** * Before output: handle bulk actions and screen options. */ public static function load_entries() { if ( ! current_user_can( 'manage_options' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read only. if ( ! empty( $_GET['view'] ) ) { // A bookmarked detail URL remains read-only unless its action nonce is supplied. if ( isset( $_GET['_wpnonce'] ) ) { $id = absint( $_GET['view'] ); check_admin_referer( 'alpeg_forms_read_' . $id ); Entries::set_status( array( $id ), 'read' ); } return; } add_screen_option( 'per_page', array( 'label' => __( 'Submissions per page', 'alpeg-forms' ), 'default' => 20, 'option' => 'alpeg_forms_per_page', ) ); add_filter( 'set_screen_option_alpeg_forms_per_page', static function ( $status, $option, $value ) { return max( 1, min( 200, (int) $value ) ); }, 10, 3 ); Entries_Table::process_bulk_action(); } /** * Submissions: list or detail view. */ public static function render_entries() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read only. $view = isset( $_GET['view'] ) ? absint( $_GET['view'] ) : 0; if ( $view ) { self::render_entry( $view ); return; } $table = new Entries_Table(); $table->prepare_items(); $total = Entries::count(); $failures = Mail_Diagnostics::recent_failures(); ?>


search_box( __( 'Search submissions', 'alpeg-forms' ), 'alpeg-forms-search' ); $table->display(); ?>
'; if ( ! $entry ) { echo '

' . esc_html__( 'Submission not found', 'alpeg-forms' ) . '

'; echo '

← ' . esc_html__( 'Back to overview', 'alpeg-forms' ) . '

'; return; } $reply = $entry->email ? 'mailto:' . rawurlencode( $entry->email ) . '?subject=' . rawurlencode( 'Re: ' . $entry->form_title ) : ''; $del = wp_nonce_url( admin_url( 'admin-post.php?action=alpeg_forms_entry&do=delete&id=' . $entry->id ), 'alpeg_forms_entry_' . $entry->id ); $unr = wp_nonce_url( admin_url( 'admin-post.php?action=alpeg_forms_entry&do=unread&id=' . $entry->id ), 'alpeg_forms_entry_' . $entry->id ); ?>

←

form_title ); ?> #id; ?>

data as $row ) : ?>
'; foreach ( $row['files'] as $i => $file ) { $exists = (bool) Files::absolute_path( $file['path'] ); echo '
  • '; if ( $exists ) { echo '' . esc_html( $file['name'] ) . ''; } else { echo esc_html( $file['name'] ) . ' (' . esc_html__( 'file deleted', 'alpeg-forms' ) . ')'; } echo ' ' . esc_html( size_format( (int) $file['size'] ) ) . '
  • '; } echo ''; } elseif ( '' === $val ) { echo '–'; } elseif ( 'email' === $row['type'] ) { echo '' . esc_html( $val ) . ''; } elseif ( 'tel' === $row['type'] ) { echo '' . esc_html( $val ) . ''; } elseif ( 'url' === $row['type'] ) { echo '' . esc_html( $val ) . ''; } else { echo nl2br( esc_html( $val ) ); } ?>
    page_url ? $entry->page_url : ( $entry->post_id ? get_permalink( $entry->post_id ) : '' ); $title = $entry->post_id ? get_the_title( $entry->post_id ) : ''; if ( '' === $title ) { $path = (string) wp_parse_url( $url, PHP_URL_PATH ); $query = (string) wp_parse_url( $url, PHP_URL_QUERY ); $title = ( '' !== $path ? $path : '/' ) . ( '' !== $query ? '?' . $query : '' ); } return $url ? '' . esc_html( $title ) . '' : esc_html( $title ); } /** * Delivery status of the notification. * * @param object $entry Entry. * @return string HTML. */ private static function mail_status( $entry ) { switch ( $entry->mail_status ) { case 'sent': return '' . esc_html__( 'handed over to the mail server', 'alpeg-forms' ) . ''; case 'failed': return '' . esc_html__( 'failed', 'alpeg-forms' ) . '' . ( $entry->mail_error ? '
    ' . esc_html( $entry->mail_error ) . '' : '' ) . '
    ' . esc_html__( 'Mail diagnostics', 'alpeg-forms' ) . ''; case 'none': return esc_html__( 'no recipient configured', 'alpeg-forms' ); } return ''; } /** * Single actions from the detail view. */ public static function handle_entry_action() { $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'alpeg-forms' ), 403 ); } check_admin_referer( 'alpeg_forms_entry_' . $id ); $do = isset( $_GET['do'] ) ? sanitize_key( wp_unslash( $_GET['do'] ) ) : ''; if ( 'delete' === $do ) { Entries::delete( array( $id ) ); wp_safe_redirect( admin_url( 'admin.php?page=alpeg-forms&af_done=deleted&af_n=1' ) ); exit; } if ( 'unread' === $do ) { Entries::set_status( array( $id ), 'unread' ); } wp_safe_redirect( admin_url( 'admin.php?page=alpeg-forms' ) ); exit; } /** * Notice after bulk actions. */ private static function bulk_notice() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- display only. if ( empty( $_GET['af_done'] ) ) { return; } $n = isset( $_GET['af_n'] ) ? absint( $_GET['af_n'] ) : 0; $done = sanitize_key( wp_unslash( $_GET['af_done'] ) ); // phpcs:enable $messages = array( /* translators: %d: number */ 'deleted' => _n( '%d submission deleted.', '%d submissions deleted.', $n, 'alpeg-forms' ), /* translators: %d: number */ 'read' => _n( '%d submission marked as read.', '%d submissions marked as read.', $n, 'alpeg-forms' ), /* translators: %d: number */ 'unread' => _n( '%d submission marked as unread.', '%d submissions marked as unread.', $n, 'alpeg-forms' ), ); if ( isset( $messages[ $done ] ) ) { echo '

    ' . esc_html( sprintf( $messages[ $done ], $n ) ) . '

    '; } } /** * "New page with form": the editor starts with the block. * * @param string $content Content. * @param \WP_Post $post Post. * @return string */ public static function starter_content( $content, $post ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- prefill only. if ( ! empty( $_GET['alpeg_forms_starter'] ) && 'page' === $post->post_type ) { return '

    ' . esc_html__( 'Do you have a question or a request? Just write to us – we will get back to you as soon as possible.', 'alpeg-forms' ) . '

    ' . "\n\n" . ''; } return $content; } /** * Title of the starter page. * * @param string $title Title. * @param \WP_Post $post Post. * @return string */ public static function starter_title( $title, $post ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_GET['alpeg_forms_starter'] ) && 'page' === $post->post_type ) { return __( 'Contact', 'alpeg-forms' ); } return $title; } /** * Links in the plugin list. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Submissions', 'alpeg-forms' ) . '', '' . esc_html__( 'Settings', 'alpeg-forms' ) . '' ); return $links; } }