芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/popup-maker/classes/Newsletters.php
get_error_code() ) { self::send_errors( self::$errors ); } $response = []; // Process the submission and pass the $response array as a reference variable so data can be added.. do_action_ref_array( 'pum_sub_form_submission', [ $values, &$response, &self::$errors ] ); $error_code = self::$errors->get_error_code(); $already_subscribed = 'already_subscribed' === $error_code; $success = empty( $error_code ) || $already_subscribed ? true : false; if ( ! $success && ! $already_subscribed ) { do_action( 'pum_sub_form_errors', $values, self::$errors ); switch ( $error_code ) { case 'api_errors': $response['message'] = pum_get_newsletter_provider_message( $values['provider'], 'error', $values ); break; } self::send_errors( self::$errors, $response ); } else { do_action( 'pum_sub_form_success', $values ); if ( $already_subscribed ) { $response['already_subscribed'] = true; } $response['message'] = pum_get_newsletter_provider_message( $values['provider'], $already_subscribed ? 'already_subscribed' : 'success', $values ); self::send_success( $response ); } // Don't let it keep going. die(); } /** * Process and send error messages. * * Optionally pass extra data to send back to front end. * * @param $errors WP_Error * @param array $extra_response_args */ public static function send_errors( WP_Error $errors, $extra_response_args = [] ) { if ( ! $errors || ! is_wp_error( $errors ) ) { $errors = self::$errors; } $response = array_merge( $extra_response_args, [ 'errors' => self::prepare_errors( $errors ), ] ); wp_send_json_error( $response ); die(); } /** * Send a success response with passed data. * * @param array|mixed $response */ public static function send_success( $response = [] ) { wp_send_json_success( array_filter( $response ) ); die; } /** * Prepare errors for response. * * @param WP_Error $_errors * * @return array */ public static function prepare_errors( WP_Error $_errors ) { if ( ! $_errors || ! is_wp_error( $_errors ) ) { $_errors = self::$errors; } $errors = []; foreach ( $_errors->get_error_codes() as $code ) { $errors[] = [ 'code' => $code, 'field' => $_errors->get_error_data( $code ), 'message' => $_errors->get_error_message( $code ), ]; } return $errors; } /** * Records the submission into a database table. * * @param array $values */ public static function record_submission( $values = [] ) { $data = wp_parse_args( $values, [ 'uuid' => self::uuid(), 'user_id' => get_current_user_id(), 'popup_id' => 0, 'email_hash' => '', 'email' => '', 'name' => '', 'fname' => '', 'lname' => '', 'consent' => 'no', 'consent_args' => '', ] ); $subscriber_id = PUM_DB_Subscribers::instance()->insert( $data ); if ( is_user_logged_in() && $subscriber_id ) { update_user_meta( get_current_user_id(), 'pum_subscribed', true ); } } /** * Return the current or new uuid. * * @return mixed|string */ public static function uuid() { static $uuid; if ( ! isset( $uuid ) ) { $uuid = PUM_GA::get_uuid(); } return $uuid; } /** * Provides basic field sanitization. * * @param array $values * * @return array */ public static function sanitization( $values = [] ) { $values = wp_parse_args( $values, [ 'provider' => pum_get_option( 'newsletter_default_provider', 'none' ), 'consent' => 'no', 'consent_args' => [], ] ); $values['provider'] = sanitize_text_field( $values['provider'] ); $values['provider'] = sanitize_text_field( $values['provider'] ); if ( ! empty( $values['consent_args'] ) && is_string( $values['consent_args'] ) ) { if ( strpos( $values['consent_args'], '\"' ) >= 0 ) { $values['consent_args'] = stripslashes( $values['consent_args'] ); } $values['consent_args'] = (array) json_decode( $values['consent_args'] ); } $values['consent_args'] = wp_parse_args( $values['consent_args'], [ 'enabled' => 'no', 'required' => false, 'text' => '', ] ); // Anonymize the data if they didn't consent and privacy is enabled. if ( 'yes' === $values['consent_args']['enabled'] && ! $values['consent_args']['required'] && 'no' === $values['consent'] ) { $values['uuid'] = ''; $values['user_id'] = 0; $values['name'] = ''; $values['fname'] = ''; $values['lname'] = ''; $values['email'] = function_exists( 'wp_privacy_anonymize_data' ) ? wp_privacy_anonymize_data( 'email', $values['email'] ) : 'deleted@site.invalid'; } // Split name into fname & lname or vice versa. if ( isset( $values['name'] ) ) { $values['name'] = trim( sanitize_text_field( $values['name'] ) ); // Creates last name $name = explode( ' ', $values['name'] ); if ( ! isset( $name[1] ) ) { $name[1] = ''; } $values['fname'] = trim( $name[0] ); $values['lname'] = trim( $name[1] ); } else { $values['fname'] = isset( $values['fname'] ) ? sanitize_text_field( $values['fname'] ) : ''; $values['lname'] = isset( $values['lname'] ) ? sanitize_text_field( $values['lname'] ) : ''; $values['name'] = trim( $values['fname'] . ' ' . $values['lname'] ); } $values['email'] = sanitize_email( $values['email'] ); $values['email_hash'] = md5( $values['email'] ); return $values; } /** * Provides basic field validation. * * @param WP_Error $errors * @param array $values * * @return WP_Error */ public static function validation( $errors, $values = [] ) { if ( ! isset( $values['email'] ) || empty( $values['email'] ) ) { $errors->add( 'empty_email', pum_get_newsletter_provider_message( $values['provider'], 'empty_email', $values ), 'email' ); } elseif ( ! is_email( $values['email'] ) ) { $errors->add( 'invalid_email', pum_get_newsletter_provider_message( $values['provider'], 'invalid_email', $values ), 'email' ); } if ( 'yes' === $values['consent_args']['enabled'] && $values['consent_args']['required'] && 'no' === $values['consent'] ) { $errors->add( 'consent_required', pum_get_newsletter_provider_message( $values['provider'], 'consent_required', $values ), 'consent' ); } return $errors; } }