slug() . '_submission'; } /** * Register the submission event. */ public function register_events() { PingPush_Events::register( $this->event_id(), array( /* translators: %s: form plugin name. */ 'label' => sprintf( __( '%s submission', 'pingpush' ), static::name() ), 'group' => 'forms', 'source' => static::name(), /* translators: {form_name} is a placeholder, keep it as is. */ 'title' => __( 'New submission: {form_name}', 'pingpush' ), 'message' => '{fields}', 'priority' => 0, 'enabled' => true, 'placeholders' => array( 'form_name', 'form_id', 'entry_id', 'fields', 'field:name' ), 'options' => array( 'form_ids' => array( 'type' => 'text', 'label' => __( 'Only these form IDs (comma-separated, empty = all forms)', 'pingpush' ), 'default' => '', ), ), ) ); } /** * Whether a form id passes the "only these forms" filter. * * @param int|string $form_id Form id. * @return bool */ protected function form_allowed( $form_id ) { $settings = PingPush_Events::settings_for( $this->event_id() ); $ids = array_filter( array_map( 'trim', explode( ',', (string) ( $settings['form_ids'] ?? '' ) ) ), 'strlen' ); return empty( $ids ) || in_array( (string) $form_id, $ids, true ); } /** * Send the notification. * * @param int|string $form_id Form id. * @param string $form_name Form name. * @param array $fields key => ['label' => string, 'value' => mixed]. * @param int|string $entry_id Entry id, if stored. * @param string $url Admin URL for the entry. * @param string $url_title Link title; defaults to "View entry". */ protected function notify( $form_id, $form_name, array $fields, $entry_id = '', $url = '', $url_title = '' ) { if ( ! PingPush_Events::is_enabled( $this->event_id() ) || ! $this->form_allowed( $form_id ) ) { return; } $dedupe = $entry_id ? 'entry:' . $form_id . ':' . $entry_id : 'hash:' . md5( (string) $form_id . wp_json_encode( $fields ) ); PingPush_Events::trigger( $this->event_id(), array( 'form_name' => '' !== (string) $form_name ? (string) $form_name : '#' . $form_id, 'form_id' => (string) $form_id, 'entry_id' => (string) $entry_id, 'fields' => $fields, ), array( 'url' => $url ? $url : admin_url(), 'url_title' => $url ? ( $url_title ? $url_title : __( 'View entry', 'pingpush' ) ) : __( 'Open dashboard', 'pingpush' ), 'dedupe' => $dedupe, 'dedupe_ttl' => 60, ) ); } /** * Field types that never carry user input. * * @param string $type Type. * @return bool */ protected function is_display_only( $type ) { return in_array( strtolower( (string) $type ), array( 'html', 'section', 'page', 'pagebreak', 'page_break', 'divider', 'hr', 'captcha', 'recaptcha', 'hcaptcha', 'turnstile', 'submit', 'button', 'step', 'honeypot', 'password', 'gdpr', 'consent_text', 'spam' ), true ); } }