*/ public function discover_forms() { return Registry::published_forms( 'wpcf7_contact_form' ); } /** * @return void */ public function register_hooks() { add_filter( 'wpcf7_form_elements', array( $this, 'inject' ) ); add_action( 'wpcf7_before_send_mail', array( $this, 'capture' ), 10, 3 ); } /** * @param string $html Form elements HTML. * @return string */ public function inject( $html ) { $form = \WPCF7_ContactForm::get_current(); if ( ! $form || ! ServerConsent::form_enabled( $this->id(), $form->id() ) ) { return $html; } $field = ServerConsent::checkbox_html( $this->id(), (int) $form->id() ); $submit = strpos( $html, 'wpcf7-submit' ); if ( false === $submit ) { return $html . $field; } // Put the opt-in on its own line above the element that contains the submit button. $start = strrpos( substr( $html, 0, $submit ), 'id(), $form->id() ) ) { return; } if ( '1' !== (string) $submission->get_posted_data( ServerConsent::FIELD ) ) { return; // Box left unticked: no consent, nothing recorded. } ServerConsent::record( 'form', $this->id(), 'cf7:' . $form->id() . ' ' . $form->title(), ServerConsent::form_options( $this->id(), (int) $form->id() )['label'], null, (int) $form->id() ); } }