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;
$mofile = __DIR__ . '/languages/akismet-privacy-policies-' . $this->translation . '.mo';
$this->mo->import_from_file( $mofile );
}
$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' ] );
}
/**
* 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.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 .= '' . $params['html_element'] . '>' . "\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() { ?>' . __( 'The plugin amends the comment form by a privacy notice which is necessary in some countries due to EU legislation', 'akismet-privacy-policies' ) . '
' . '<strong>Akismet Anti-Spam</strong>', 'akismet-privacy-policies' ) .
__( 'This page uses the <a href="http://akismet.com/">Akismet-plugin by <a href="http://automattic.com/">Automattic</a> Inc., 60 29th Street #343, San Francisco, CA 94110-4929, USA. By means of this plugin it is possible to filter out spam comments (e.g. created by robots, containing unsolicited advertisements or links to malware). For this purpose comments are sent to a server in the USA where they get analyzed and stored for four days. If a comment gets classified as being spam, the data will be stored beyond the four-day limit. The information being stored contains the given name, the email address, the IP address, the comment content, the referrer, information about the browser being used to send the comment as well as the operating system of the computer and date and time when the comment was sent. You may use pseudonymes or ommit name and email address. You will not be able to send a comment if you do not consent by clicking the checkbox. You may object to the usage of your data by writing to <a href="mailto:support@wordpress.com" target="_blank">support@wordpress.com</a>, subject "Deletion of Data stored by Akismet" giving/describing the stored data.',
'akismet-privacy-policies'
) . '