languages = get_available_languages(); // default language is en_US but get_available_languages // contains translations in .mo files $this->languages[] = 'en_US'; $this->translation = get_user_locale(); if ( isset( $_GET['translation'] ) ) { $this->translation = $_GET['translation']; } elseif ( isset( $_POST['translation'] ) ) { $this->translation = $_POST['translation']; } if ( $this->translation !== 'en_US' ) { $this->mo = new Mo; try { $mofile = __DIR__ . '/languages/akismet-privacy-policies-' . $this->translation . '.mo'; if ( ! file_exists( $mofile ) ) { throw new RuntimeException( 'File not found.' ); } $fp = fopen( $mofile, 'rb' ); if ( ! $fp ) { throw new \RuntimeException( 'File open failed.' ); } $this->mo->import_from_file( $mofile ); fclose( $fp ); } catch ( Exception $error ) { if ( defined('WP_DEBUG_DISPLAY') && WP_DEBUG_DISPLAY) { $this->adminNotice( sprintf( /* translators: %1$s is the min PHP-version, %2$s the current PHP-version */ esc_html__( 'Akismet privacy policies plugin has the error: %1$1s.', 'akismet-privacy-policies' ), $error ) ); } } } $this->options = get_option( 'akismet_privacy_notice_settings_' . $this->translation ); if ( empty( $this->options['checkbox'] ) ) { $this->options['checkbox'] = $this->checkbox; } if ( $this->options['checkbox'] ) { add_action( 'pre_comment_on_post', [ $this, 'print_error_message' ] ); } if ( ! isset( $this->options['style'] ) ) { $this->options['style'] = $this->style; } if ( $this->options['style'] ) { add_action( 'wp_head', [ $this, 'add_style' ] ); } // for settings add_action( 'init', [ $this, 'translate_strings' ] ); add_action( 'init', [ $this, 'akismet_privacy_policies_textdomain' ] ); add_action( 'admin_menu', [ $this, 'add_settings_page' ] ); add_filter( 'plugin_action_links', [ $this, 'plugin_action_links' ], 10, 2 ); add_action( 'admin_init', [ $this, 'register_settings' ] ); } /** * Print admin notices. * * @param string $message */ public function adminNotice( $message ) { add_action( 'admin_notices', static function () use ( $message ) { printf( '

%1$s

', esc_html( $message ) ); } ); } /** * Handler for the action 'init'. Instantiates this class. * * @return Akismet_Privacy_Policies $classobj * @since 0.0.2 * @access public */ public static function get_object() { if ( self::$classobj === null ) { self::$classobj = new self; } return self::$classobj; } /** * Initialize and translate $this->notice, $this->error_message * * @return void * @since 2.0.0 * @access public */ public function translate_strings() { // dummy translation, only there to let poedit recognize the text... esc_html__( 'I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.
More information on Akismet and GDPR.', 'akismet-privacy-policies' ); esc_html__( '

Attention: You have not accepted our privacy disclaimer.

', 'akismet-privacy-policies' ); if ( $this->translation !== 'en_US' ) { $this->notice = $this->mo->translate( 'I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.
More information on Akismet and GDPR.', 'akismet-privacy-policies' ); } else { $this->notice = 'I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.
More information on Akismet and GDPR.'; } if ( $this->translation !== 'en_US' ) { $this->error_message = $this->mo->translate( '

Attention: You have not accepted our privacy disclaimer.

', 'akismet-privacy-policies' ); } else { $this->error_message = '

Attention: You have not accepted our privacy disclaimer.

'; } } /** * find translations * * @access public * @return void * @since 2.0.0 * * @uses load_plugin_textdomain */ public function akismet_privacy_policies_textdomain() { load_plugin_textdomain( 'akismet-privacy-policies', false, basename( __DIR__ ) . '/languages' ); } /** * Print content for policies include markup. * Use filter hook akismet_privacy_notice_options for change markup or notice. * * @access public * * @param array string $arr_comment_defaults * * @since 0.0.1 * * @uses apply_filters */ public function add_comment_notice( $arr_comment_defaults ) { if ( is_user_logged_in() ) { return $arr_comment_defaults; } if ( ! isset( $this->options['checkbox'] ) || ( empty( $this->options['checkbox'] ) && $this->options['checkbox'] !== 0 ) ) { $this->options['checkbox'] = $this->checkbox; } if ( empty( $this->options['notice'] ) ) { $this->options['notice'] = wp_kses( $this->notice, wp_kses_allowed_html($this->notice) ); } $defaults = [ 'css_class' => 'privacy-notice', 'html_element' => 'p', 'text' => $this->options['notice'], 'checkbox' => $this->options['checkbox'], 'position' => 'comment_notes_after', ]; // Make it filterable $params = apply_filters( 'akismet_privacy_notice_options', $defaults ); // Create the output $html = "\n" . '<' . $params['html_element']; if ( ! empty( $params['css_class'] ) ) { $html .= ' class="' . $params['css_class'] . '"'; } $html .= '>' . "\n"; if ( (bool) $params['checkbox'] ) { $html .= '' . "\n"; $html .= ''; } $html .= '' . "\n"; // Add the text to array if ( isset( $arr_comment_defaults['comment_notes_after'] ) ) { $arr_comment_defaults['comment_notes_after'] .= $html; return $arr_comment_defaults; } // for custom hook in theme $arr_comment_defaults = $html; echo $arr_comment_defaults; } /** * Return Message on inactive checkbox * Use filter akismet_privacy_error_message for change text or markup * * @since 0.0.2 * @uses wp_die * @access public */ public function print_error_message() { if ( is_user_logged_in() ) { return; } if ( empty( $this->options['error_message'] ) ) { $this->options['error_message'] = $this->error_message; } // check for checkbox active if ( isset( $_POST['comment'] ) && ! isset( $_POST['akismet_privacy_check'] ) ) { $message = apply_filters( 'akismet_privacy_error_message', wp_kses( $this->options['error_message'], wp_kses_allowed_html( $this->options['error_message'] ) ) ); wp_die( $message ); } } /** * Print style in wp_head. * * @since 0.0.2 * @uses get_option, plugin_action_links, plugin_basename * @access public */ public function add_style() { if ( is_user_logged_in() ) { return; } if ( empty( $this->options['style'] ) ) { $this->options['style'] = $this->style; } echo ''; } /** * Add settings link on plugins.php in backend * * @param array $links , string $file * * @param $file * * @return array * @uses plugin_basename, esc_html__ * @access public * * @since 0.0.2 */ public function plugin_action_links( $links, $file ) { if ( plugin_basename( __DIR__ . '/akismet-privacy-policies.php' ) === $file ) { $links[] = '' . esc_html__( 'Settings', 'akismet-privacy-policies' ) . ''; } return $links; } /** * Add settings page in WP backend * * @return void * @since 0.0.2 * @uses add_options_page, add_action * @access public */ public function add_settings_page() { $options_page = add_options_page( esc_html__( 'Akismet Privacy Policies Settings', 'akismet-privacy-policies' ), esc_html__( 'Akismet Privacy Policies', 'akismet-privacy-policies' ), 'manage_options', 'akismet_privacy_notice_settings_group', [ $this, 'get_settings_page' ] ); add_action( 'load-' . $options_page, [ $this, 'contextual_help' ] ); } /** * Return form and markup on settings page * * @since 0.0.2 * @uses settings_fields, normalize_whitespace * @access public */ public function get_settings_page() { ?>

get_plugin_data( 'Name' ); ?>

options['checkbox'] ) || ( empty( $this->options['checkbox'] ) && $this->options['checkbox'] !== 0 ) ) { $this->options['checkbox'] = $this->checkbox; } if ( empty( $this->options['notice'] ) ) { $this->options['notice'] = normalize_whitespace( $this->notice ); } if ( empty( $this->options['error_message'] ) ) { $this->options['error_message'] = normalize_whitespace( $this->error_message ); } if ( empty( $this->options['style'] ) ) { $this->options['style'] = normalize_whitespace( $this->style ); } ?>
options['checkbox'] ) ) { checked( 1, $this->options['checkbox'] ); } ?> />

Note: HTML is possible', 'akismet-privacy-policies' ) ?>
Attention: You will have to add the link to your privacy statement manually. Since WordPress version 5 you can find a link to a guide for creating your own privacy statement under \'Settings\' → \'Privacy\'.', 'akismet-privacy-policies' ) ?>
notice; if ( $this->translation !== 'en_US' ) { $example_notice = $this->mo->translate( $this->notice ); } echo '' . esc_html( $example_notice ) . ''; ?>

Note: HTML is possible', 'akismet-privacy-policies' ) ?>
error_message; if ( $this->translation !== 'en_US' ) { $example_error = $this->mo->translate( $this->error_message ); } echo '' . esc_html( $example_error ) . ''; ?>

Note: CSS is possible', 'akismet-privacy-policies' ) ?>
' . esc_html( $this->style ) . ''; ?>

You can find more information about the topic here: akismet.com/gdpr/. This plugin has been developed by Inpsyde GmbH, Germany, with legal support by the law firm SCHWENKE & DRAMBURG.

', 'akismet-privacy-policies' ) ?>
translation, [ 'sanitize_callback' => [ $this, 'validate_settings' ] ] ); } /** * Unregister and delete settings; clean database * * @return void * @since 0.0.2 * @uses unregister_setting, delete_option * @access public */ public function unregister_settings() { $all_options = wp_load_alloptions(); $to_be_deleted = preg_grep( '/^akismet_privacy_notice_settings(_)*[a-z]*(_)*[A-Z]*$/', array_keys( $all_options ) ); foreach ( $to_be_deleted as $option ) { unregister_setting( 'akismet_privacy_notice_settings_group', $option ); delete_option( $option ); } } /** * Add help text * * @internal param string $screen * * @since 0.0.2 * @uses normalize_whitespace * */ public function contextual_help() { $contextual_help = '

' . __( 'The plugin amends the comment form by a privacy notice which is necessary in some countries due to EU legislation', 'akismet-privacy-policies' ) . '

' . ''; $screen = get_current_screen(); if ( $screen !== null ) { $screen->add_help_tab( [ 'id' => 'settings_page_akismet_privacy_notice_settings_group', 'title' => __( 'Akismet Privacy Policies', 'akismet-privacy-policies' ), 'content' => normalize_whitespace( $contextual_help ), ] ); } } } // end class if ( function_exists( 'add_action' ) && class_exists( 'Akismet_Privacy_Policies' ) ) { add_action( 'plugins_loaded', [ 'Akismet_Privacy_Policies', 'get_object' ] ); } else { header( 'Status: 403 Forbidden' ); header( 'HTTP/1.1 403 Forbidden' ); exit(); }