' . esc_html__( 'Each feed fires its hook with four arguments: $data (key → value, or your custom keys), $entry, $values and $feed. Example:', 'fieldwren' ) . '
' . esc_html( "add_action( 'fwren/integration/hook', function ( \$data, \$entry, \$values, \$feed ) {\n // …\n}, 10, 4 );" ) . '' . esc_html__( 'Throw an exception to mark the feed as failed.', 'fieldwren' ) . '
'; } public function feed_fields( $form_id ) { return array( array( 'key' => 'hook', 'type' => 'text', 'label' => __( 'Hook name', 'fieldwren' ), 'default' => 'fwren/integration/hook', 'required' => true, 'smartcodes' => false, 'desc' => __( 'Letters, numbers, _ - / . only.', 'fieldwren' ) ), array( 'key' => 'body', 'type' => 'select', 'label' => __( '$data', 'fieldwren' ), 'default' => 'all', 'no_empty' => true, 'options' => array( 'all' => __( 'All fields (key → text value)', 'fieldwren' ), 'custom' => __( 'Custom keys', 'fieldwren' ) ) ), array( 'key' => 'custom', 'type' => 'kv', 'label' => __( 'Custom keys', 'fieldwren' ), 'show_if' => array( 'body' => 'custom' ) ), ); } public function process( array $feed, array $entry, array $values ) { $hook = preg_replace( '#[^A-Za-z0-9_\-/.]#', '', (string) ( $feed['settings']['hook'] ?? '' ) ); if ( '' === $hook ) { return new \WP_Error( 'fwren_no_hook', __( 'No hook name.', 'fieldwren' ) ); } $data = array(); if ( 'custom' === ( $feed['settings']['body'] ?? 'all' ) ) { $data = $this->kv( 'custom' ); } else { foreach ( $this->data_rows() as $k => $r ) { $data[ $k ] = $r[1]; } } $data['_meta'] = $this->entry_meta(); do_action( $hook, $data, $entry, $values, $feed ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Hook name is chosen by the site admin in the integration settings. /* translators: %s hook */ return sprintf( __( 'Fired %s.', 'fieldwren' ), $hook ); } }