id = 'ppl_afw_new_application'; $this->title = __( 'New affiliate application', 'affireo-affiliates-for-woocommerce' ); $this->description = __( 'Sent to the store admin when a new affiliate application is submitted for review.', 'affireo-affiliates-for-woocommerce' ); $this->heading = __( 'New affiliate application', 'affireo-affiliates-for-woocommerce' ); $this->subject = __( 'A new affiliate application needs review', 'affireo-affiliates-for-woocommerce' ); $this->recipient = get_option( 'admin_email' ); add_action( 'ppl_afw_affiliate_registered', array( $this, 'trigger' ), 20, 2 ); parent::__construct(); } /** * Triggers the email. * * @since 1.0.0 * @param int $affiliate_id Affiliate id. * @param array $fields Submitted fields. */ public function trigger( $affiliate_id, $fields ) { $this->setup_locale(); $this->affiliate = $this->affiliates()->find( $affiliate_id ); $this->fields = is_array( $fields ) ? $fields : array(); if ( ! $this->get_recipient() ) { $this->recipient = get_option( 'admin_email' ); } $this->dispatch(); $this->restore_locale(); } /** * Body content. * * @since 1.0.0 * @return string */ protected function get_body() { $user = $this->affiliate ? get_userdata( (int) $this->affiliate->user_id ) : null; $body = '

' . esc_html__( 'A new affiliate application is waiting for review.', 'affireo-affiliates-for-woocommerce' ) . '

'; if ( $user ) { $body .= '

' . esc_html__( 'Applicant:', 'affireo-affiliates-for-woocommerce' ) . ' ' . esc_html( $user->display_name . ' (' . $user->user_email . ')' ) . '

'; } foreach ( $this->fields as $key => $value ) { if ( 'terms_version' === $key || ! is_scalar( $value ) || '' === (string) $value ) { continue; } $body .= '

' . esc_html( ucwords( str_replace( '_', ' ', $key ) ) ) . ': ' . esc_html( (string) $value ) . '

'; } if ( $this->affiliate ) { $body .= '

' . esc_html__( 'Review application', 'affireo-affiliates-for-woocommerce' ) . '

'; } return $body; } }