plugin_name . ' ' . __('settings'), $apbct->plugin_name, 'manage_options', 'cleantalk', $callback ); // Add CleanTalk Moderation option to the Discussion page add_settings_field( 'cleantalk_allowed_moderation', esc_html__('CleanTalk allowed comments moderation', 'cleantalk-spam-protect'), 'apbct_discussion_settings__field__moderation', 'discussion' ); add_filter('allowed_options', function ($options) { $options['discussion'][] = 'cleantalk_allowed_moderation'; return $options; }); // End modification Discussion page if ( ! in_array($pagenow, array('options.php', 'options-general.php', 'settings.php', 'admin.php')) ) { return; } $callback_format = version_compare($wp_version, '4.7') >= 0 ? array('type' => 'string', 'sanitize_callback' => 'apbct_settings__validate', 'default' => null) : 'apbct_settings__validate'; register_setting( 'cleantalk_settings', 'cleantalk_settings', $callback_format ); $fields = apbct_settings__set_fileds(); $fields = APBCT_WPMS && is_main_site() ? apbct_settings__set_fileds__network($fields) : $fields; apbct_settings__add_groups_and_fields($fields); } function apbct_settings__set_fileds() { global $apbct; $additional_ac_title = ''; if ( $apbct->api_key && is_null($apbct->fw_stats['firewall_updating_id']) ) { if ( $apbct->settings['sfw__enabled'] && ! $apbct->stats['sfw']['entries'] ) { $additional_ac_title = ' ' . esc_html__( 'The functionality was disabled because SpamFireWall database is empty. Please, do the synchronization or', 'cleantalk-spam-protect' ) . ' ' . '' . esc_html__( 'contact to our support.', 'cleantalk-spam-protect' ) . ''; } } $additional_sfw_description = ''; if ( ! empty($apbct->data['notice_incompatibility']) ) { $additional_sfw_description .= '
'; foreach ( $apbct->data['notice_incompatibility'] as $notice ) { $additional_sfw_description .= '' . $notice . '
'; } } $fields = array( 'main' => array( 'title' => '', 'default_params' => array(), 'description' => '', 'html_before' => '', 'html_after' => '', 'fields' => array( 'action_buttons' => array( 'callback' => 'apbct_settings__field__action_buttons', ), 'connection_reports' => array( 'callback' => 'apbct_settings__field__statistics', ), 'debug_tab' => array( 'callback' => 'apbct_settings__field__debug_tab', 'display' => Server::getDomain(), array( 'lc', 'loc', 'lh', 'test' ), ), 'api_key' => array( 'callback' => 'apbct_settings__field__apikey', ), ), ), 'state' => array( 'title' => '', 'default_params' => array(), 'description' => '', 'html_before' => '
', 'html_after' => '', 'fields' => array( 'state' => array( 'callback' => 'apbct_settings__field__state', ), ), ), 'debug' => array( 'title' => '', 'default_params' => array(), 'description' => '', 'html_before' => '', 'html_after' => '', 'fields' => array( 'state' => array( 'callback' => 'apbct_settings__field__debug', ), ), ), // Different 'different' => array( 'title' => '', 'default_params' => array(), 'description' => '', 'html_before' => '
', 'html_after' => '', 'fields' => array( 'sfw__enabled' => array( 'type' => 'checkbox', 'title' => 'SpamFireWall', // Do not to localize this phrase 'description' => __( "This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk-spam-protect' ) . '
' . esc_html__( 'If the setting is turned on, plugin will automatically add IP address for each session with administration rights to Personal list in the cloud.', 'cleantalk-spam-protect' ) . $additional_sfw_description, 'childrens' => array('sfw__anti_flood', 'sfw__anti_crawler', 'sfw__use_delete_to_clear_table'), 'long_description' => true, ), 'comments__hide_website_field' => array( 'type' => 'checkbox', 'title' => __('Hide the "Website" field', 'cleantalk-spam-protect'), 'description' => __( 'This option hides the "Website" field on the comment form.', 'cleantalk-spam-protect' ), 'long_description' => true, 'display' => ! $apbct->white_label, ), ), ), // Forms protection 'forms_protection' => array( 'title' => __('Forms to protect', 'cleantalk-spam-protect'), 'default_params' => array(), 'description' => '', 'html_before' => '

' . '' . '' . __('Advanced settings', 'cleantalk-spam-protect') . '' . '' . '
' . '', 'fields' => array( 'misc__send_connection_reports' => array( 'type' => 'checkbox', 'title' => __('Send connection reports', 'cleantalk-spam-protect'), 'description' => __( "Checking this box you allow plugin to send the information about your connection. The option in a beta state.", 'cleantalk-spam-protect' ), ), 'misc__async_js' => array( 'type' => 'checkbox', 'title' => __('Async JavaScript loading', 'cleantalk-spam-protect'), 'description' => __( 'Use async loading for scripts. Warning: This could reduce filtration quality.', 'cleantalk-spam-protect' ), ), 'gdpr__enabled' => array( 'type' => 'checkbox', 'title' => __('Allow to add GDPR notice via shortcode', 'cleantalk-spam-protect'), 'description' => __( ' Adds small checkbox under your website form. To add it you should use the shortcode on the form\'s page: [cleantalk_gdpr_form id="FORM_ID"]', 'cleantalk-spam-protect' ), 'childrens' => array('gdpr__text'), ), 'gdpr__text' => array( 'type' => 'text', 'title' => __('GDPR text notice', 'cleantalk-spam-protect'), 'description' => __( 'This text will be added as a description to the GDPR checkbox.', 'cleantalk-spam-protect' ), 'parent' => 'gdpr__enabled', 'class' => 'apbct_settings-field_wrapper--sub', ), 'misc__store_urls' => array( 'type' => 'checkbox', 'title' => __('Store visited URLs', 'cleantalk-spam-protect'), 'description' => __( "Plugin stores last 5 visited URLs (HTTP REFERRERS) before visitor submits form on the site. You can see stored visited URLS for each visitor in your Dashboard. Turn the option on to improve Anti-Spam protection.", 'cleantalk-spam-protect' ), ), 'wp__comment_notify' => array( 'type' => 'checkbox', 'title' => __( 'Notify users with selected roles about new approved comments. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect' ), 'description' => sprintf( __( "If enabled, overrides similar WordPress %sdiscussion settings%s.", 'cleantalk-spam-protect' ), '', '' ), 'childrens' => array('wp__comment_notify__roles'), ), 'wp__comment_notify__roles' => array( 'type' => 'select', 'multiple' => true, 'parent' => 'wp__comment_notify', 'options_callback' => 'apbct_get_all_roles', 'class' => 'apbct_settings-field_wrapper--sub', ), 'wp__dashboard_widget__show' => array( 'type' => 'checkbox', 'title' => __('Show Dashboard Widget', 'cleantalk-spam-protect'), ), 'misc__complete_deactivation' => array( 'type' => 'checkbox', 'title' => __('Complete deactivation', 'cleantalk-spam-protect'), 'description' => __('Leave no trace in the system after deactivation.', 'cleantalk-spam-protect'), ), ), ), ); return $fields; } function apbct_settings__set_fileds__network($fields) { global $apbct; $additional_fields = array( 'wpms_settings' => array( 'default_params' => array(), 'description' => '', 'html_before' => '
' . '' . '' . __('WordPress Multisite (WPMS) settings', 'cleantalk-spam-protect') . '' . '' . '
', 'html_after' => '
', 'fields' => array( 'multisite__work_mode' => array( 'type' => 'select', 'options' => array( array( 'val' => 1, 'label' => __( 'Mutual Account, Individual Access Keys', 'cleantalk-spam-protect' ), 'children_enable' => 1, ), array( 'val' => 2, 'label' => __('Mutual Account, Mutual Access Key', 'cleantalk-spam-protect'), 'children_enable' => 0, ), array( 'val' => 3, 'label' => __( 'Individual accounts, individual Access keys', 'cleantalk-spam-protect' ), 'children_enable' => 0, ), ), 'title' => __('WordPress Multisite Work Mode', 'cleantalk-spam-protect'), 'description' => __( 'You can choose the work mode here for the child blogs and how they will operate with the CleanTalk Cloud. Press "?" for the detailed description.', 'cleantalk-spam-protect' ), 'long_description' => true, 'display' => APBCT_WPMS && is_main_site(), 'childrens' => array('multisite__hoster_api_key', 'multisite__white_label'), 'network' => true, ), 'multisite__hoster_api_key' => array( 'type' => 'text', 'required' => true, 'title' => __('Hoster Access key', 'cleantalk-spam-protect'), 'description' => sprintf( __('Copy the Access key from your %sCleanTalk Profile%s', 'cleantalk-spam-protect'), '', '' ), 'class' => 'apbct_settings-field_wrapper--sub', 'display' => APBCT_WPMS && is_main_site(), 'disabled' => ! isset($apbct->network_settings['multisite__work_mode']) || $apbct->network_settings['multisite__work_mode'] != 1, 'parent' => 'multisite__work_mode', 'network' => true, ), 'multisite__service_utilization' => array( 'type' => 'field', 'class' => 'apbct_settings-field_wrapper--sub', 'callback' => 'apbct_field_service_utilization', 'display' => APBCT_WPMS && is_main_site() && $apbct->network_settings['multisite__work_mode'] == 1, ), 'multisite__white_label' => array( 'type' => 'checkbox', 'title' => __('Enable White Label Mode', 'cleantalk-spam-protect'), 'description' => sprintf( __("Learn more information %shere%s.", 'cleantalk-spam-protect'), '', '' ), 'childrens' => array('multisite__white_label__plugin_name'), 'disabled' => defined('CLEANTALK_ACCESS_KEY') || ! isset($apbct->network_settings['multisite__work_mode']) || $apbct->network_settings['multisite__work_mode'] != 1, 'parent' => 'multisite__work_mode', 'class' => 'apbct_settings-field_wrapper--sub', 'network' => true, ), 'multisite__white_label__plugin_name' => array( 'title' => __('Plugin name', 'cleantalk-spam-protect'), 'description' => sprintf( __( "Specify plugin name. Leave empty for deafult %sAnti-Spam by CleanTalk%s", 'cleantalk-spam-protect' ), '', '' ), 'type' => 'text', 'parent' => 'multisite__white_label', 'class' => 'apbct_settings-field_wrapper--sub', 'network' => true, ), 'multisite__allow_custom_settings' => array( 'type' => 'checkbox', 'title' => __('Allow users to manage plugin settings', 'cleantalk-spam-protect'), 'description' => __('Allow to change settings on child sites.', 'cleantalk-spam-protect'), 'display' => APBCT_WPMS && is_main_site(), 'disabled' => $apbct->network_settings['multisite__work_mode'] == 2, 'network' => true, ), 'multisite__use_settings_template' => array( 'type' => 'checkbox', 'title' => __('Use settings template', 'cleantalk-spam-protect'), 'description' => __("Use the current settings template for child sites.", 'cleantalk-spam-protect'), 'childrens' => array( 'multisite__use_settings_template_apply_for_new', 'multisite__use_settings_template_apply_for_current' ), 'network' => true, ), 'multisite__use_settings_template_apply_for_new' => array( 'type' => 'checkbox', 'title' => __('Apply for newly added sites.', 'cleantalk-spam-protect'), 'description' => __( "The newly added site will have the same preset settings template.", 'cleantalk-spam-protect' ), 'parent' => 'multisite__use_settings_template', 'class' => 'apbct_settings-field_wrapper--sub', 'network' => true, ), 'multisite__use_settings_template_apply_for_current' => array( 'type' => 'checkbox', 'title' => __('Apply for current sites.', 'cleantalk-spam-protect'), 'description' => __( "Apply current settings template for selected sites.", 'cleantalk-spam-protect' ), 'parent' => 'multisite__use_settings_template', 'childrens' => array('multisite__use_settings_template_apply_for_current_list_sites'), 'class' => 'apbct_settings-field_wrapper--sub', 'network' => true, ), 'multisite__use_settings_template_apply_for_current_list_sites' => array( 'type' => 'select', 'multiple' => true, 'options_callback' => 'apbct_get_all_child_domains', 'options_callback_params' => array(true), 'class' => 'apbct_settings-field_wrapper--sub', 'parent' => 'multisite__use_settings_template_apply_for_current', 'description' => __( 'Sites to apply settings. Hold CTRL to select multiple sites.', 'cleantalk-spam-protect' ), 'network' => true, ), ) ) ); $fields = array_merge_recursive($fields, $additional_fields); return $fields; } function apbct_settings__add_groups_and_fields($fields) { global $apbct; $apbct->settings_fields_in_groups = $fields; $field_default_params = array( 'callback' => 'apbct_settings__field__draw', 'type' => 'radio', 'options' => array( array('val' => 1, 'label' => __('On', 'cleantalk-spam-protect'), 'childrens_enable' => 1,), array('val' => 0, 'label' => __('Off', 'cleantalk-spam-protect'), 'childrens_enable' => 0,), ), 'def_class' => 'apbct_settings-field_wrapper', 'class' => '', 'parent' => '', 'childrens' => array(), 'hide' => array(), // 'title' => 'Default title', // 'description' => 'Default description', 'display' => true, // Draw settings or not 'reverse_trigger' => false, // How to allow child settings. Childrens are opened when the parent triggered "ON". This is overrides by this option 'multiple' => false, 'description' => '', 'network' => false, 'disabled' => false, 'required' => false, ); foreach ( $apbct->settings_fields_in_groups as $group_name => $group ) { add_settings_section('apbct_section__' . $group_name, '', '', 'cleantalk-spam-protect'); foreach ( $group['fields'] as $field_name => $field ) { // Normalize $field['options'] from callback function to this type array( array( 'val' => 1, 'label' => __('On'), ), ) if ( ! empty($field['options_callback']) ) { $options = call_user_func_array( $field['options_callback'], ! empty($field['options_callback_params']) ? $field['options_callback_params'] : array() ); foreach ( $options as &$option ) { if ( is_array($option) ) { $option = array( 'val' => isset($option['val']) ? $option['val'] : current($option), 'label' => isset($option['label']) ? $option['label'] : end($option) ); } else { $option = array('val' => $option, 'label' => $option); } } unset($option); $field['options'] = $options; } $params = ! empty($group['default_params']) ? array_merge($group['default_params'], $field) : array_merge($field_default_params, $field); $params['name'] = $field_name; if ( ! $params['display'] ) { continue; } add_settings_field( 'apbct_field__' . $field_name, '', $params['callback'], 'cleantalk', 'apbct_section__' . $group_name, $params ); } } } /** * Admin callback function - Displays plugin options page */ function apbct_settings__display() { global $apbct; // Title echo '

' . __($apbct->plugin_name, 'cleantalk-spam-protect') . '

'; // Subtitle for IP license if ( $apbct->moderate_ip ) { echo '

' . __('Hosting Anti-Spam', 'cleantalk-spam-protect') . '

'; } echo '
'; apbct_settings__error__output(); // Top info if ( ! $apbct->white_label ) { echo '
'; echo __('CleanTalk\'s tech support:', 'cleantalk-spam-protect') . ' ' . 'WordPress.org.' . '
'; echo __('Plugin Homepage at', 'cleantalk-spam-protect') . ' cleantalk.org.
'; echo '' . __('GDPR compliance', 'cleantalk-spam-protect') . '
'; echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk-spam-protect') . '
'; echo __('CleanTalk is registered Trademark. All rights reserved.', 'cleantalk-spam-protect') . '
'; if ( $apbct->key_is_ok ) { echo '' . sprintf( __('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'), '', '' ) . '
'; } apbct_admin__badge__get_premium(); echo '
'; } // Output spam count if ( $apbct->key_is_ok && apbct_api_key__is_correct() ) { if ( $apbct->spam_count > 0 ) { echo '
' . '
' . '' . sprintf( __('%s has blocked %s spam.', 'cleantalk-spam-protect'), $apbct->plugin_name, number_format($apbct->spam_count, 0, ',', ' ') ) . '' . '
' . '
' . '
'; } } // Output spam count if ( $apbct->key_is_ok && apbct_api_key__is_correct() ) { if ( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ) { // CP button echo '' . __('Click here to get Anti-Spam statistics', 'cleantalk-spam-protect') . ''; echo '  '; } } if ( (apbct_api_key__is_correct() || apbct__is_hosting_license()) && ($apbct->network_settings['multisite__work_mode'] != 2 || is_main_site()) ) { // Sync button echo ''; echo '  '; } // Output spam count if ( $apbct->key_is_ok && apbct_api_key__is_correct() ) { if ( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ) { // Support button echo '' . __('Support', 'cleantalk-spam-protect') . ''; echo '  '; echo '
' . '
'; } } settings_fields('cleantalk_settings'); do_settings_fields('cleantalk', 'cleantalk_section_settings_main'); // Disabled save button if the Access key empty $disabled = ''; if (! $apbct->key_is_ok) { $disabled = 'disabled'; } $hidden_groups = ''; $hidden_groups .= '
'; foreach ( $apbct->settings_fields_in_groups as $group_name => $group ) { echo ! empty($group['html_before']) ? $group['html_before'] : ''; echo ! empty($group['title']) ? '

' . $group['title'] . '

' : ''; do_settings_fields('cleantalk', 'apbct_section__' . $group_name); if ( ! empty($group['html_after']) && strpos($group['html_after'], '{HIDDEN_SECTION_NAV}') !== false ) { $group['html_after'] = str_replace('{HIDDEN_SECTION_NAV}', $hidden_groups, $group['html_after']); } echo ! empty($group['html_after']) ? $group['html_after'] : ''; } echo '
'; echo ''; echo '
'; echo "
"; echo '
'; if ( ! $apbct->white_label ) { // Translate banner for non EN locale if ( substr(get_locale(), 0, 2) != 'en' ) { require_once(CLEANTALK_PLUGIN_DIR . 'templates/translate_banner.php'); printf($ct_translate_banner_template, substr(get_locale(), 0, 2)); } } } function apbct_settings__display__network() { // If it's network admin dashboard if ( is_network_admin() ) { $site_url = get_site_option('siteurl'); $site_url = preg_match('/\/$/', $site_url) ? $site_url : $site_url . '/'; $link = $site_url . 'wp-admin/options-general.php?page=cleantalk'; printf( "

" . __( "Please, enter the %splugin settings%s in main site dashboard.", 'cleantalk-spam-protect' ) . "

", "", "" ); return; } } function apbct_settings__error__output($return = false) { global $apbct; // If have error message output error block. $out = ''; if ( ! empty($apbct->errors) && ! defined('CLEANTALK_ACCESS_KEY') ) { $errors = $apbct->errors; $error_texts = array( // Misc 'key_invalid' => __('Error occurred while Access key validating. Error: ', 'cleantalk-spam-protect'), 'key_get' => __( 'Error occurred while automatically get Access key. Error: ', 'cleantalk-spam-protect' ), 'sfw_send_logs' => __( 'Error occurred while sending SpamFireWall logs. Error: ', 'cleantalk-spam-protect' ), 'sfw_update' => __( 'Error occurred while updating SpamFireWall local base. Error: ', 'cleantalk-spam-protect' ), 'ua_update' => __( 'Error occurred while updating User-Agents local base. Error: ', 'cleantalk-spam-protect' ), 'account_check' => __( 'Error occurred while checking account status. Error: ', 'cleantalk-spam-protect' ), 'api' => __('Error occurred while executing API call. Error: ', 'cleantalk-spam-protect'), 'cron' => __('Error occurred while executing CleanTalk Cron job. Error: ', 'cleantalk-spam-protect'), 'sfw_outdated' => __( 'Error occurred on last SpamFireWall check. Error: ', 'cleantalk-spam-protect' ), // Validating settings 'settings_validate' => 'Validate Settings', 'exclusions_urls' => 'URL Exclusions', 'exclusions_fields' => 'Field Exclusions', // Unknown 'unknown' => __('Unknown error type: ', 'cleantalk-spam-protect'), ); $errors_out = array(); $errors = apbct_settings__prepare_errors((array)$errors); foreach ( $errors as $type => $error ) { if ( ! empty($error) ) { if ( count($error) > 2 || ( ! isset($error['error'], $error['error_time']) ) ) { foreach ( $error as $sub_type => $sub_error ) { if ( $sub_type === 'error' || $sub_type === 'error_time' ) { continue; } if ( isset($sub_error['error']) && strpos($sub_error['error'], 'SFW_IS_DISABLED') !== false ) { continue; } $errors_out[$sub_type] = ''; if ( isset($sub_error['error_time']) ) { $errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': '; } $errors_out[$sub_type] .= (isset($error_texts[$type]) ? $error_texts[$type] : ucfirst($type)) . ': '; $errors_out[$sub_type] .= (isset($error_texts[$sub_type]) ? $error_texts[$sub_type] : ( $error_texts['unknown'] . $sub_type . ' ' . __('Error: ', 'cleantalk-spam-protect') ) . ' ' . $sub_error['error'] ); } } if ( ! empty($type) && $apbct->white_label && ! is_main_site() && in_array($type, array('sfw_update', 'key_invalid', 'account_check')) ) { continue; } if ( isset($error['error']) && strpos($error['error'], 'SFW_IS_DISABLED') !== false ) { continue; } $errors_out[$type] = ''; if ( isset($error['error_time']) ) { $errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': '; } $errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : ''); } } if ( ! empty($errors_out) ) { $out .= '
' . '

' . __('Errors:', 'cleantalk-spam-protect') . '

'; foreach ( $errors_out as $value ) { $out .= '

' . $value . '

'; } $out .= ! $apbct->white_label ? '

' . sprintf( __('You can get support any time here: %s.', 'cleantalk-spam-protect'), 'https://wordpress.org/support/plugin/cleantalk-spam-protect' ) . '

' : ''; $out .= '
'; } } if ( $return ) { return $out; } else { echo $out; } } /** * Get only last error from each error types from errors array * * @param array $errors * * @return array */ function apbct_settings__prepare_errors($errors) { $prepared_errors = array(); if ( is_array($errors) ) { foreach ( $errors as $type => $error ) { if ( is_array($error) ) { foreach ( $error as $key => $error_info ) { if ( is_string($key) ) { $prepared_errors[$type][$key] = end($error_info); } else { $prepared_errors[$type] = $error_info; } } } } } return $prepared_errors; } function apbct_settings__field__debug() { global $apbct; if ( $apbct->debug ) { echo '

Debug:

'; echo '

Constants:

'; echo 'CLEANTALK_AJAX_USE_BUFFER ' . (defined('CLEANTALK_AJAX_USE_BUFFER') ? var_export(CLEANTALK_AJAX_USE_BUFFER, true) : 'NOT_DEFINED') . "
"; echo 'CLEANTALK_AJAX_USE_FOOTER_HEADER ' . (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') ? var_export(CLEANTALK_AJAX_USE_FOOTER_HEADER, true) : 'NOT_DEFINED') . "
"; echo 'CLEANTALK_ACCESS_KEY ' . (defined('CLEANTALK_ACCESS_KEY') ? var_export(CLEANTALK_ACCESS_KEY, true) : 'NOT_DEFINED') . "
"; echo 'CLEANTALK_CHECK_COMMENTS_NUMBER ' . (defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? var_export(CLEANTALK_CHECK_COMMENTS_NUMBER, true) : 'NOT_DEFINED') . "
"; echo 'CLEANTALK_CHECK_MESSAGES_NUMBER ' . (defined('CLEANTALK_CHECK_MESSAGES_NUMBER') ? var_export(CLEANTALK_CHECK_MESSAGES_NUMBER, true) : 'NOT_DEFINED') . "
"; echo 'CLEANTALK_PLUGIN_DIR ' . (defined('CLEANTALK_PLUGIN_DIR') ? var_export(CLEANTALK_PLUGIN_DIR, true) : 'NOT_DEFINED') . "
"; echo 'WP_ALLOW_MULTISITE ' . (defined('WP_ALLOW_MULTISITE') ? var_export(WP_ALLOW_MULTISITE, true) : 'NOT_DEFINED') . "
"; echo '

'; echo "

Debug log:

"; echo "
"; $output = print_r($apbct->debug, true); $output = str_replace("\n", "
", $output); $output = preg_replace("/[^\S]{4}/", "    ", $output); echo "$output"; echo "
"; } } function apbct_settings__field__state() { global $apbct; $path_to_img = plugin_dir_url(__FILE__) . "images/"; $img = $path_to_img . "yes.png"; $img_no = $path_to_img . "no.png"; $img_no_gray = $path_to_img . "no_gray.png"; $color = "black"; if ( ! $apbct->key_is_ok ) { $img = $path_to_img . "no.png"; $img_no = $path_to_img . "no.png"; $color = "black"; } if ( ! apbct_api_key__is_correct($apbct->api_key) ) { $img = $path_to_img . "yes_gray.png"; $img_no = $path_to_img . "no_gray.png"; $color = "gray"; } if ( $apbct->moderate_ip ) { $img = $path_to_img . "yes.png"; $img_no = $path_to_img . "no.png"; $color = "black"; } if ( $apbct->moderate == 0 ) { $img = $path_to_img . "no.png"; $img_no = $path_to_img . "no.png"; $color = "black"; } print '
'; print '

' . __('Protection is active', 'cleantalk-spam-protect') . '

'; echo '' . __( 'Registration forms', 'cleantalk-spam-protect' ); echo '' . __( 'Comments forms', 'cleantalk-spam-protect' ); echo '' . __( 'Contact forms', 'cleantalk-spam-protect' ); echo '' . __( 'Custom contact forms', 'cleantalk-spam-protect' ); if ( ! $apbct->white_label || is_main_site() ) { echo '' . '' . __( 'Validate email for existence', 'cleantalk-spam-protect' ) . ''; } // Autoupdate status if ( $apbct->notice_auto_update && ( ! $apbct->white_label || is_main_site()) ) { echo '' . __( 'Auto update', 'cleantalk-spam-protect' ) . ' ?'; } // WooCommerce if ( class_exists('WooCommerce') ) { echo '' . __( 'WooCommerce checkout form', 'cleantalk-spam-protect' ); } if ( $apbct->moderate_ip ) { print "

The Anti-Spam service is paid by your hosting provider. License #" . $apbct->data['ip_license'] . ".
"; if ( $apbct->api_key ) { print esc_html__('The Access key is not required.', 'cleantalk-spam-protect'); } } print "
"; } /** * Admin callback function - Displays inputs of 'apikey' plugin parameter */ function apbct_settings__field__apikey() { global $apbct; echo '
'; // Using the Access key from Main site, or from CLEANTALK_ACCESS_KEY constant if ( APBCT_WPMS && ! is_main_site() && ( ! $apbct->allow_custom_key || defined('CLEANTALK_ACCESS_KEY')) ) { _e('

Access key is provided by network administrator

', 'cleantalk-spam-protect'); return; } echo ''; echo ''; // Show account name associated with the Access key if ( ! empty($apbct->data['account_name_ob']) ) { echo '
' . sprintf( __('Account at cleantalk.org is %s.', 'cleantalk-spam-protect'), '' . $apbct->data['account_name_ob'] . '' ) . '
'; }; // Show Access key button if ( (apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok) ) { echo '' . __('Show the Access key', 'cleantalk-spam-protect') . ''; } // "Auto Get Key" buttons. License agreement echo '
'; echo '

'; // Auto get key if ( ! $apbct->ip_license ) { echo ''; echo ''; echo '
'; echo '
'; } // Warnings and GDPR printf( __( 'Admin e-mail %s %s will be used for registration оr click here to %sGet Access Key Manually%s.', 'cleantalk-spam-protect' ), '' . ct_get_admin_email() . '', apbct_settings__btn_change_account_email_html(), '', '' ); // License agreement if ( ! $apbct->ip_license ) { echo '
'; echo ''; echo '"; echo '
'; } echo '
'; echo '
'; } function apbct_field_service_utilization() { global $apbct; echo '
'; if ( $apbct->services_count && $apbct->services_max && $apbct->services_utilization ) { echo sprintf( __('Hoster account utilization: %s%% ( %s of %s websites ).', 'cleantalk-spam-protect'), $apbct->services_utilization * 100, $apbct->services_count, $apbct->services_max ); // Link to the dashboard, so user could extend your subscription for more sites if ( $apbct->services_utilization * 100 >= 90 ) { echo ' '; echo sprintf( __('You could extend your subscription %shere%s.', 'cleantalk-spam-protect'), '', '' ); } } else { _e( 'Enter the Hoster Access key and synchronize with cloud to find out your hoster account utilization.', 'cleantalk-spam-protect' ); } echo '
'; } function apbct_settings__field__action_buttons() { global $apbct; $links = apply_filters( 'apbct_settings_action_buttons', array( '' . __( 'Check comments for spam', 'cleantalk-spam-protect' ) . '', '' . __( 'Check users for spam', 'cleantalk-spam-protect' ) . '', '' . __( 'Statistics & Reports', 'cleantalk-spam-protect' ) . '', ) ); echo '
'; if ( apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok ) { echo '
'; foreach ( $links as $link ) { echo $link . '    '; } echo '
'; } elseif ( apbct__is_hosting_license() ) { echo '' . __('Statistics & Reports', 'cleantalk-spam-protect') . ''; } echo '
'; } function apbct_settings__field__statistics() { global $apbct; echo ''; } function apbct_settings__field__debug_tab() { echo ''; } function apbct_discussion_settings__field__moderation() { $output = ''; echo $output; } function apbct_get_all_child_domains($except_main_site = false) { global $wpdb; $blogs = array(); $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM ' . $wpdb->blogs, OBJECT_K); if ( $except_main_site ) { foreach ( $wp_blogs as $blog ) { if ( $blog->blog_id != $blog->site_id ) { $blog_details = get_blog_details(array('blog_id' => $blog->blog_id)); $blogs[] = array( 'val' => $blog_details->id, 'label' => '#' . $blog_details->id . ' ' . $blog_details->blogname ); } } } return $blogs; } /** * Get all current WordPress roles * * @return array */ function apbct_get_all_roles() { $wp_roles = new WP_Roles(); return $wp_roles->get_names(); } function apbct_settings__field__draw($params = array()) { global $apbct; $value = $params['network'] ? $apbct->network_settings[$params['name']] : $apbct->settings[$params['name']]; $value_parent = $params['parent'] ? ($params['network'] ? $apbct->network_settings[$params['parent']] : $apbct->settings[$params['parent']]) : false; // Is element is disabled $disabled = $params['parent'] && ! $value_parent ? ' disabled="disabled"' : ''; // Strait $disabled = $params['parent'] && $params['reverse_trigger'] && ! $value_parent ? '' : $disabled; // Reverse logic $disabled = $params['disabled'] ? ' disabled="disabled"' : $disabled; // Direct disable from params $disabled = ! is_main_site() && $apbct->network_settings && ( ! $apbct->network_settings['multisite__allow_custom_settings'] || $apbct->network_settings['multisite__work_mode'] == 2 ) ? ' disabled="disabled"' : $disabled; // Disabled by super admin on sub-sites $childrens = $params['childrens'] ? 'apbct_setting---' . implode(",apbct_setting---", $params['childrens']) : ''; $hide = $params['hide'] ? implode(",", $params['hide']) : ''; echo '
'; switch ( $params['type'] ) { // Checkbox type case 'checkbox': // Popup description $popup = ''; if ( isset($params['long_description']) ) { $popup = ''; } echo '' . '' . $popup; echo '
' . $params['description'] . '
'; break; // Radio type case 'radio': // Popup description $popup = ''; if ( isset($params['long_description']) ) { $popup = ''; } // Title echo isset($params['title']) ? '

' . $params['title'] . $popup . '

' : ''; echo '
'; echo '
'; foreach ( $params['options'] as $option ) { echo ''; echo ''; echo '     '; } echo '
'; echo isset($params['description']) ? '
' . $params['description'] . '
' : ''; echo '
'; break; // Dropdown list type case 'select': // Popup description $popup = ''; if ( isset($params['long_description']) ) { $popup = ''; } echo isset($params['title']) ? '

' . $params['title'] . $popup . '

' : ''; echo ''; foreach ( $params['options'] as $option ) { echo '' . $option['label'] . ''; } echo ''; echo isset($params['description']) ? '
' . $params['description'] . '
' : ''; break; // Text type case 'text': // Popup description $popup = ''; if ( isset($params['long_description']) ) { $popup = ''; } echo '' . ' ' . ''; echo '
' . $params['description'] . '
'; break; // Textarea type case 'textarea': echo '
'; echo '' . ' '; echo '
' . $params['description'] . '
'; break; } echo '
'; } /** * Admin callback function - Plugin parameters validator * * @param array $settings Array with passed settings * * @return array Array with processed settings * @global \Cleantalk\ApbctWP\State $apbct */ function apbct_settings__validate($settings) { global $apbct; // If user is not allowed to manage settings. Get settings from the storage if ( ! $apbct->network_settings['multisite__allow_custom_settings'] && // Skip if templates applying for subsites is not set empty($settings['multisite__use_settings_template_apply_for_current_list_sites']) && ! is_main_site() && current_filter() === 'sanitize_option_cleantalk_settings' // Do in only if settings were saved ) { foreach ( $apbct->settings as $key => $setting ) { // Do not reset apikey to default is allow_custom_key is active if ( $key === 'apikey' && $apbct->allow_custom_key ) { continue; } $settings[$key] = $setting; } } // Set missing settings. foreach ( $apbct->def_settings as $setting => $value ) { if ( ! isset($settings[$setting]) ) { $settings[$setting] = null; settype($settings[$setting], gettype($value)); } } unset($setting, $value); // Set missing network settings. $stored_network_options = get_site_option($apbct->option_prefix . '_network_settings', array()); foreach ( $apbct->def_network_settings as $setting => $value ) { if ( ! isset($settings[$setting]) ) { if ( ! array_key_exists($setting, $stored_network_options) ) { $settings[$setting] = $value; } settype($settings[$setting], gettype($value)); } } unset($setting, $value); // Actions with toggle SFW settings // SFW was enabled if ( ! $apbct->settings['sfw__enabled'] && $settings['sfw__enabled'] ) { $cron = new Cron(); $cron->updateTask('sfw_update', 'apbct_sfw_update__init', 180); // SFW was disabled } elseif ( $apbct->settings['sfw__enabled'] && ! $settings['sfw__enabled'] ) { apbct_sfw__clear(); } //Sanitizing sfw__anti_flood__view_limit setting $settings['sfw__anti_flood__view_limit'] = floor(intval($settings['sfw__anti_flood__view_limit'])); $settings['sfw__anti_flood__view_limit'] = ($settings['sfw__anti_flood__view_limit'] == 0 ? 20 : $settings['sfw__anti_flood__view_limit']); // Default if 0 passed $settings['sfw__anti_flood__view_limit'] = ($settings['sfw__anti_flood__view_limit'] < 5 ? 5 : $settings['sfw__anti_flood__view_limit']); // // Validating Access key $settings['apikey'] = strpos($settings['apikey'], '*') === false ? $settings['apikey'] : $apbct->settings['apikey']; $apbct->data['key_changed'] = $settings['apikey'] !== $apbct->settings['apikey']; $settings['apikey'] = ! empty($settings['apikey']) ? trim($settings['apikey']) : ''; $settings['apikey'] = defined('CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $settings['apikey']; $settings['apikey'] = ! is_main_site() && $apbct->white_label && $apbct->settings['apikey'] ? $apbct->settings['apikey'] : $settings['apikey']; $settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $settings['apikey'] : $apbct->network_settings['apikey']; $settings['apikey'] = is_main_site() || ! $settings['multisite__white_label'] ? $settings['apikey'] : $apbct->settings['apikey']; // Show notice if the Access key is empty if ( ! apbct_api_key__is_correct() ) { $apbct->data['key_is_ok'] = false; $apbct->data['notice_show'] = 1; } else { // Key is good by default $apbct->data['key_is_ok'] = true; } // Sanitize setting values foreach ( $settings as &$setting ) { if ( is_string($setting) ) { $setting = preg_replace('/[<"\'>]/', '', trim($setting)); } // Make HTML code inactive } // Validate Exclusions // URLs if ( empty($apbct->settings['exclusions__urls']) ) { // If the field is empty, the new way checking by URL will be activated. $apbct->data['check_exclusion_as_url'] = true; } $result = apbct_settings__sanitize__exclusions( $settings['exclusions__urls'], $settings['exclusions__urls__use_regexp'], $apbct->data['check_exclusion_as_url'] ); $result === false ? $apbct->errorAdd( 'exclusions_urls', 'is not valid: "' . $settings['exclusions__urls'] . '"', 'settings_validate' ) : $apbct->errorDelete('exclusions_urls', true, 'settings_validate'); $settings['exclusions__urls'] = $result ? $result : ''; // Fields $result = apbct_settings__sanitize__exclusions( $settings['exclusions__fields'], $settings['exclusions__fields__use_regexp'] ); $result === false ? $apbct->errorAdd( 'exclusions_fields', 'is not valid: "' . $settings['exclusions__fields'] . '"', 'settings_validate' ) : $apbct->errorDelete('exclusions_fields', true, 'settings_validate'); $settings['exclusions__fields'] = $result ? $result : ''; // WPMS Logic. if ( APBCT_WPMS && is_main_site() ) { $network_settings = array( 'multisite__allow_custom_settings' => $settings['multisite__allow_custom_settings'], 'multisite__white_label' => $settings['multisite__white_label'], 'multisite__white_label__plugin_name' => $settings['multisite__white_label__plugin_name'], 'multisite__use_settings_template' => $settings['multisite__use_settings_template'], 'multisite__use_settings_template_apply_for_new' => $settings['multisite__use_settings_template_apply_for_new'], 'multisite__use_settings_template_apply_for_current' => $settings['multisite__use_settings_template_apply_for_current'], 'multisite__use_settings_template_apply_for_current_list_sites' => $settings['multisite__use_settings_template_apply_for_current_list_sites'], ); unset($settings['multisite__white_label'], $settings['multisite__white_label__plugin_name']); if ( isset($settings['multisite__hoster_api_key']) ) { $network_settings['multisite__hoster_api_key'] = $settings['multisite__hoster_api_key']; } if ( isset($settings['multisite__work_mode']) ) { $network_settings['multisite__work_mode'] = $settings['multisite__work_mode']; } } // Drop debug data if ( Post::get('submit') === 'debug_drop' ) { $apbct->debug = false; $apbct->deleteOption('debug', true); return $settings; } // Test connections to servers if ( Post::get('apbct_debug__check_connection') ) { $result = apbct_test_connection(); apbct_log($result); } // Send connection reports if ( Post::get('submit') === 'ct_send_connection_report' ) { ct_mail_send_connection_report(); return $settings; } // Ajax type $available_ajax_type = apbct_settings__get_ajax_type(); $apbct->data['ajax_type'] = $available_ajax_type ?: 'admin_ajax'; if ( $apbct->data['cookies_type'] === 'alternative' || (isset($settings['data__use_ajax']) && $settings['data__use_ajax'] == 1) ) { if ( $available_ajax_type === false ) { // There is no available alt cookies types. Cookies will be disabled. // There is no available ajax types. AJAX js will be disabled. $settings['data__set_cookies'] = 0; $settings['data__use_ajax'] = 0; } } $apbct->save('data'); // WPMS Logic. if ( APBCT_WPMS ) { if ( is_main_site() ) { // Network settings $network_settings['apikey'] = $settings['apikey']; $apbct->network_settings = $network_settings; $apbct->saveNetworkSettings(); // Network data $apbct->network_data = array( 'key_is_ok' => $apbct->data['key_is_ok'], 'moderate' => $apbct->data['moderate'], 'valid' => isset($apbct->data['valid']) ? $apbct->data['valid'] : 0, 'auto_update' => $apbct->data['auto_update'], 'user_token' => $apbct->data['user_token'], 'service_id' => $apbct->data['service_id'], ); $apbct->saveNetworkData(); if ( isset($settings['multisite__use_settings_template_apply_for_current_list_sites']) && ! empty($settings['multisite__use_settings_template_apply_for_current_list_sites']) ) { apbct_update_blogs_options($settings); } } if ( ! $apbct->white_label && ! is_main_site() && ! $apbct->allow_custom_key ) { $settings['apikey'] = ''; } } // Alt sessions table clearing if ( $apbct->data['cookies_type'] !== 'alternative' ) { \Cleantalk\ApbctWP\Variables\AltSessions::wipe(); } /** * Triggered before returning the settings */ do_action('apbct_before_returning_settings', $settings); return $settings; } function apbct_settings__sync($direct_call = false) { if ( ! $direct_call ) { check_ajax_referer('ct_secret_nonce'); } global $apbct; //Clearing all errors $apbct->errorDeleteAll('and_save_data'); // Feedback with app_agent ct_send_feedback('0:' . APBCT_AGENT); // 0 - request_id, agent version. // Key is good by default $apbct->data['key_is_ok'] = true; // Checking account status $result = ct_account_status_check($apbct->settings['apikey']); // Is key valid? if ( $result ) { // Deleting errors about invalid key $apbct->errorDelete('key_invalid key_get', 'save'); // SFW actions if ( $apbct->settings['sfw__enabled'] == 1 ) { $result = apbct_sfw_update__init(5); if ( ! empty($result['error']) ) { $apbct->errorAdd('sfw_update', $result['error']); } $result = ct_sfw_send_logs($apbct->settings['apikey']); if ( ! empty($result['error']) ) { $apbct->errorAdd('sfw_send_logs', $result['error']); } } // Updating brief data for dashboard widget cleantalk_get_brief_data($apbct->settings['apikey']); // Key is not valid } else { $apbct->data['key_is_ok'] = false; $apbct->errorAdd( 'key_invalid', __('Testing is failed. Please check the Access key.', 'cleantalk-spam-protect') ); } // WPMS Logic. if ( APBCT_WPMS ) { if ( is_main_site() ) { // Network settings $apbct->network_settings['apikey'] = $apbct->settings['apikey']; $apbct->saveNetworkSettings(); // Network data $apbct->network_data = array( 'key_is_ok' => $apbct->data['key_is_ok'], 'moderate' => $apbct->data['moderate'], 'valid' => $apbct->data['valid'], 'auto_update' => $apbct->data['auto_update'], 'user_token' => $apbct->data['user_token'], 'service_id' => $apbct->data['service_id'], ); if ( $apbct->network_settings['multisite__work_mode'] == 1 ) { $apbct->data['services_count '] = isset($result['services_count']) ? $result['services_count'] : ''; $apbct->data['services_max'] = isset($result['services_max']) ? $result['services_max'] : ''; $apbct->data['services_utilization'] = isset($result['services_utilization']) ? $result['services_utilization'] : ''; } $apbct->saveNetworkData(); if ( isset($apbct->settings['multisite__use_settings_template_apply_for_current_list_sites']) && ! empty($apbct->settings['multisite__use_settings_template_apply_for_current_list_sites']) ) { apbct_update_blogs_options($apbct->settings); } } if ( ! $apbct->white_label && ! is_main_site() && ! $apbct->allow_custom_key ) { $apbct->settings['apikey'] = ''; } } if ( $apbct->data['key_is_ok'] == false && $apbct->data['moderate_ip'] == 0 ) { // Notices $apbct->data['notice_show'] = 1; $apbct->data['notice_renew'] = 0; $apbct->data['notice_trial'] = 0; $apbct->data['notice_review'] = 0; $apbct->data['notice_auto_update'] = 0; // Other $apbct->data['service_id'] = 0; $apbct->data['valid'] = 0; $apbct->data['moderate'] = 0; $apbct->data['ip_license'] = 0; $apbct->data['moderate_ip'] = 0; $apbct->data['spam_count'] = 0; $apbct->data['auto_update'] = 0; $apbct->data['user_token'] = ''; $apbct->data['license_trial'] = 0; $apbct->data['account_name_ob'] = ''; } $out = array( 'success' => true, 'reload' => isset($apbct->data['key_changed']) ? $apbct->data['key_changed'] : 0, ); $apbct->data['key_changed'] = false; $apbct->saveData(); die(json_encode($out)); } /** * @param bool $direct_call * * @return array|bool|false[]|mixed|string|string[]|void * @psalm-suppress RedundantCondition */ function apbct_settings__get_key_auto($direct_call = false) { if ( ! $direct_call ) { check_ajax_referer('ct_secret_nonce'); } global $apbct; $website = parse_url(get_option('home'), PHP_URL_HOST) . parse_url(get_option('home'), PHP_URL_PATH); $platform = 'wordpress'; $user_ip = \Cleantalk\ApbctWP\Helper::ipGet('real', false); $timezone = filter_input(INPUT_POST, 'ct_admin_timezone'); $language = apbct_get_server_variable('HTTP_ACCEPT_LANGUAGE'); $wpms = APBCT_WPMS && defined('SUBDOMAIN_INSTALL') && ! SUBDOMAIN_INSTALL ? true : false; $white_label = $apbct->network_settings['multisite__white_label'] ? true : false; $hoster_api_key = $apbct->network_settings['multisite__hoster_api_key']; $admin_email = ct_get_admin_email(); /** * Filters the email to get Access key * * @param string email to get Access key */ $filtered_admin_email = apply_filters('apbct_get_api_key_email', $admin_email); $result = \Cleantalk\ApbctWP\API::methodGetApiKey( 'antispam', $filtered_admin_email, $website, $platform, $timezone, $language, $user_ip, $wpms, $white_label, $hoster_api_key, $filtered_admin_email !== $admin_email ); if ( empty($result['error']) ) { if ( isset($result['user_token']) ) { $apbct->data['user_token'] = $result['user_token']; } if ( ! empty($result['auth_key']) && apbct_api_key__is_correct($result['auth_key']) ) { $apbct->data['key_changed'] = trim($result['auth_key']) !== $apbct->settings['apikey']; $apbct->settings['apikey'] = trim($result['auth_key']); } $templates = ! $direct_call ? \Cleantalk\ApbctWP\CleantalkSettingsTemplates::getOptionsTemplate($result['auth_key']) : ''; if ( ! empty($templates) ) { $templatesObj = new \Cleantalk\ApbctWP\CleantalkSettingsTemplates($result['auth_key']); $out = array( 'success' => true, 'getTemplates' => $templatesObj->getHtmlContent(true), ); } else { $out = array( 'success' => true, 'reload' => true, ); } } else { $apbct->errorAdd( 'key_get', $result['error'] . ($apbct->white_label ? ' )'; } /** * Staff thing - set sfw_update cron task */ function apbct_debug__set_sfw_update_cron() { global $apbct; return '' . '' . '' . '' . '' . '' . '' . ''; } /** * Implementation of service_update_local_settings functionality */ add_action('apbct_before_returning_settings', 'apbct__send_local_settings_to_api'); function apbct__send_local_settings_to_api($settings) { // Current Access key $api_key = $settings['apikey'] ?: ''; // Settings to JSON $settings = json_encode($settings); // Hostname $hostname = preg_replace('/^(https?:)?(\/\/)?(www\.)?/', '', get_site_url()); \Cleantalk\ApbctWP\API::methodSendLocalSettings($api_key, $hostname, $settings); }