connection = $connection; } public function register(): void { add_action( 'admin_notices', array( $this, 'render' ) ); add_action( 'admin_post_mowl_dismiss_notice', array( $this, 'dismiss' ) ); } public static function flash( string $type, string $text ): void { set_transient( self::flash_key(), array( 'type' => $type, 'text' => $text, ), MINUTE_IN_SECONDS ); } public function render(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $flash = get_transient( self::flash_key() ); if ( is_array( $flash ) ) { delete_transient( self::flash_key() ); $this->box( $flash['type'], $flash['text'] ); } if ( ! $this->connection->is_connected() ) { $this->box( 'info', sprintf( /* translators: %s: settings page URL */ __( 'Mowl is installed but not connected yet. Connect your site to start collecting subscribers.', 'mowl-email' ), esc_url( ConnectController::settings_url() ) ), 'not_connected' ); return; } if ( $this->connection->is_broken() ) { $this->box( 'error', sprintf( /* translators: %s: settings page URL */ __( 'Mowl no longer accepts this site’s connection. Reconnect to keep forms working.', 'mowl-email' ), esc_url( ConnectController::settings_url() ) ) ); } // Az admin saját kérése a jel: ha a Cloudflare-en át jön, de a kapcsoló // ki van kapcsolva, minden látogató a CF címén osztozik. if ( empty( FormSettings::load()['behind_cloudflare'] ) && null !== CloudflareRanges::visitor_ip() ) { $this->box( 'warning', sprintf( /* translators: %s: settings page URL (Form tab, Spam protection) */ __( 'It looks like your site is behind Cloudflare. Turn on “My site is behind Cloudflare”, otherwise every visitor shares Cloudflare’s address and some sign-ups may be rate-limited.', 'mowl-email' ), esc_url( ConnectController::settings_url( array( 'tab' => 'form' ) ) . '#mowl-spam-protection' ) ), 'cloudflare_detected' ); } $flags = Options::flags(); if ( ! empty( $flags[ Turnstile::FAILING_FLAG ] ) ) { $this->box( 'error', sprintf( /* translators: 1: number of failed checks, 2: settings page URL (Form tab, Spam protection) */ __( 'The last %1$d Turnstile checks on your forms all failed and none passed, so real visitors may not be able to subscribe. Check that the site key and the secret key belong to the same Turnstile widget, and purge your page cache. Check the Turnstile keys.', 'mowl-email' ), Turnstile::FAILING_STREAK, esc_url( ConnectController::settings_url( array( 'tab' => 'form' ) ) . '#mowl-spam-protection' ) ) ); } if ( ! empty( $flags[ Turnstile::MISCONFIGURED_FLAG ] ) ) { $this->box( 'error', sprintf( /* translators: %s: settings page URL (Form tab, Spam protection) */ __( 'Cloudflare Turnstile rejected your secret key, so the captcha is not protecting your forms right now. Check the Turnstile keys.', 'mowl-email' ), esc_url( ConnectController::settings_url( array( 'tab' => 'form' ) ) . '#mowl-spam-protection' ) ) ); } if ( ! empty( $flags['quota_exceeded'] ) ) { $this->box( 'warning', __( 'Your Mowl subscriber quota is full: recent sign-ups could not be added. Upgrade your Mowl plan or clean up your list.', 'mowl-email' ), 'quota_' . $flags['quota_exceeded'] ); } if ( ! empty( $flags['wc_dead_events'] ) ) { $this->box( 'warning', sprintf( /* translators: %s: settings page URL (WooCommerce tab) */ __( 'Some WooCommerce events could not be sent to Mowl after repeated attempts. Check the WooCommerce tab and retry them.', 'mowl-email' ), esc_url( ConnectController::settings_url( array( 'tab' => 'woocommerce' ) ) ) ), 'wc_dead_' . $flags['wc_dead_events'] ); } } public function dismiss(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( '', 403 ); } check_admin_referer( 'mowl_dismiss_notice' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a referer ellenőrizve. $notice = isset( $_GET['notice'] ) ? sanitize_key( wp_unslash( $_GET['notice'] ) ) : ''; if ( '' !== $notice ) { update_user_meta( get_current_user_id(), 'mowl_dismissed_' . $notice, 1 ); } $referer = wp_get_referer(); Redirect::to( false !== $referer ? $referer : admin_url() ); } private static function flash_key(): string { return 'mowl_admin_notice_' . get_current_user_id(); } private function dismissed( string $key ): bool { return (bool) get_user_meta( get_current_user_id(), 'mowl_dismissed_' . $key, true ); } /** * Eltüntethető notice-nál a kulcs egyszer megy át sanitize_key()-en, és * ugyanaz kerül a meta-lekérdezésbe és a linkbe, mint amit a dismiss() * a kérésből visszakap — így a kettő szükségképp egyezik. */ private function box( string $type, string $html, ?string $dismiss_key = null ): void { $dismiss = ''; if ( null !== $dismiss_key ) { $dismiss_key = sanitize_key( $dismiss_key ); if ( $this->dismissed( $dismiss_key ) ) { return; } $url = wp_nonce_url( admin_url( 'admin-post.php?action=mowl_dismiss_notice¬ice=' . rawurlencode( $dismiss_key ) ), 'mowl_dismiss_notice' ); $dismiss = ' ' . esc_html__( 'Dismiss', 'mowl-email' ) . ''; } printf( '
%2$s%3$s