Server IP : 85.214.239.14 / Your IP : 18.221.217.100 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/wordpress/wp-content/plugins/duplicate-post/src/ui/ |
Upload File : |
<?php namespace Yoast\WP\Duplicate_Post\UI; /** * Newsletter class. */ class Newsletter { /** * Renders the newsletter signup form. * * @return string The HTML of the newsletter signup form (escaped). */ public static function newsletter_signup_form() { $newsletter_form_response = self::newsletter_handle_form(); $copy = \sprintf( /* translators: 1: Yoast */ \esc_html__( 'If you want to stay up to date about all the exciting developments around Duplicate Post, subscribe to the %1$s newsletter!', 'duplicate-post' ), 'Yoast' ); $email_label = \esc_html__( 'Email address', 'duplicate-post' ); $copy_privacy_policy = \sprintf( /* translators: %1$s and %2$s are replaced by opening and closing anchor tags. */ \esc_html__( 'Yoast respects your privacy. Read %1$sour privacy policy%2$s on how we handle your personal information.', 'duplicate-post' ), '<a href="https://yoa.st/4jf" target="_blank">', '</a>' ); $response_html = ''; if ( \is_array( $newsletter_form_response ) ) { $response_status = $newsletter_form_response['status']; $response_message = $newsletter_form_response['message']; $response_html = '<div class="newsletter-response-' . $response_status . ' clear" id="newsletter-response" style="margin-top: 6px;">' . $response_message . '</div>'; } $html = ' <!-- Begin Newsletter Signup Form --> <form method="post" id="newsletter-subscribe-form" name="newsletter-subscribe-form" novalidate> ' . \wp_nonce_field( 'newsletter', 'newsletter_nonce' ) . ' <p>' . $copy . '</p> <div class="newsletter-field-group" style="display: flex; flex-direction: column"> <label for="newsletter-email" style="margin: 0 0 4px 0;"><strong>' . $email_label . '</strong></label> <div> <input type="email" value="" name="EMAIL" class="required email" id="newsletter-email" style="margin-right: 4px;"> <input type="submit" value="' . \esc_attr__( 'Subscribe', 'duplicate-post' ) . '" name="subscribe" id="newsletter-subscribe" class="button"> </div> <p style="font-size: 10px;">' . $copy_privacy_policy . '</p> </div> ' . $response_html . ' </form> <!--End Newsletter Signup Form--> '; return $html; } /** * Handles and validates Newsletter form. * * @return array|null */ private static function newsletter_handle_form() { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Already sanitized. if ( isset( $_POST['newsletter_nonce'] ) && ! \wp_verify_nonce( \wp_unslash( $_POST['newsletter_nonce'] ), 'newsletter' ) ) { return [ 'status' => 'error', 'message' => \esc_html__( 'Something went wrong. Please try again later.', 'duplicate-post' ), ]; } $email = null; if ( isset( $_POST['EMAIL'] ) ) { $email = \sanitize_email( \wp_unslash( $_POST['EMAIL'] ) ); } if ( $email === null ) { return null; } if ( ! \is_email( $email ) ) { return [ 'status' => 'error', 'message' => \esc_html__( 'Please enter valid e-mail address.', 'duplicate-post' ), ]; } return self::newsletter_subscribe_to_mailblue( $email ); } /** * Handles subscription request and provides feedback response. * * @param string $email Subscriber email. * * @return array Feedback response. */ private static function newsletter_subscribe_to_mailblue( $email ) { $response = \wp_remote_post( 'https://my.yoast.com/api/Mailing-list/subscribe', [ 'method' => 'POST', 'body' => [ 'customerDetails' => [ 'email' => $email, 'firstName' => '', ], 'list' => 'Yoast newsletter', ], ] ); $wp_remote_retrieve_response_code = \wp_remote_retrieve_response_code( $response ); if ( $wp_remote_retrieve_response_code <= 200 || $wp_remote_retrieve_response_code >= 300 ) { return [ 'status' => 'error', 'message' => \esc_html__( 'Something went wrong. Please try again later.', 'duplicate-post' ), ]; } return [ 'status' => 'success', 'message' => \esc_html__( 'You have successfully subscribed to the newsletter. Please check your inbox.', 'duplicate-post' ), ]; } }