ABSpath = $this->getABSPATH();
$this->get_options();
$this->get_admin_options();
$this->get_plugin_upgraded(); //call always, otherwise db version will not match anymore.
if (isset($_GET['rsssl_dismiss_review_notice'])){
$this->get_dismiss_review_notice();
}
register_deactivation_hook(dirname(__FILE__) . "/" . $this->plugin_filename, array($this, 'deactivate'));
add_action('admin_init', array($this, 'add_privacy_info'));
}
static function this()
{
return self::$_this;
}
public function add_privacy_info()
{
if (!function_exists('wp_add_privacy_policy_content')) {
return;
}
$content = sprintf(
__('Really Simple SSL and Really Simple SSL add-ons do not process any personal identifiable information, so the GDPR does not apply to these plugins or usage of these plugins on your website. You can find our privacy policy here.', 'really-simple-ssl'),
'https://really-simple-ssl.com/privacy-statement/'
);
wp_add_privacy_policy_content(
'Really Simple SSL',
wp_kses_post(wpautop($content, false))
);
}
public function get_dismiss_review_notice() {
$this->review_notice_shown = true;
$this->dismiss_review_notice = true;
$this->save_options();
}
/**
* Initializes the admin class
*
* @since 2.2
*
* @access public
*
*/
public function init()
{
if (!current_user_can($this->capability)) return;
$is_on_settings_page = $this->is_settings_page();
if (defined("RSSSL_FORCE_ACTIVATE") && RSSSL_FORCE_ACTIVATE) {
$options = get_option('rlrsssl_options');
$options['ssl_enabled'] = true;
update_option('rlrsssl_options', $options);
}
/*
* check if we're one minute past the activation. Then flush rewrite rules
* this way we lower the memory impact on activation
* Flush should happen on shutdown, not on init, as often happens in other plugins
* https://codex.wordpress.org/Function_Reference/flush_rewrite_rules
* */
$activation_time = get_option('rsssl_flush_rewrite_rules');
$more_than_one_minute_ago = $activation_time < strtotime("-1 minute");
$less_than_5_minutes_ago = $activation_time > strtotime("-5 minute");
if (get_option('rsssl_flush_rewrite_rules') && $more_than_one_minute_ago && $less_than_5_minutes_ago){
delete_option('rsssl_flush_rewrite_rules');
add_action('shutdown', 'flush_rewrite_rules');
}
/*
Detect configuration when:
- SSL activation just confirmed.
- on settings page
- No SSL detected
*/
//when configuration should run again
if ($this->clicked_activate_ssl() || !$this->ssl_enabled || !$this->site_has_ssl || $is_on_settings_page || is_network_admin()) {
if (is_multisite()) $this->build_domain_list();//has to come after clicked_activate_ssl, otherwise this domain won't get counted.
$this->detect_configuration();
//flush caches when just activated ssl
//flush the permalinks
if ($this->clicked_activate_ssl()) {
if (!defined('RSSSL_NO_FLUSH') || !RSSSL_NO_FLUSH) {
update_option('rsssl_flush_rewrite_rules', time());
}
add_action('admin_init', array(RSSSL()->rsssl_cache, 'flush'), 40);
}
if (!$this->wpconfig_ok()) {
//if we were to activate ssl, this could result in a redirect loop. So warn first.
add_action("admin_notices", array($this, 'show_notice_wpconfig_needs_fixes'));
if (is_multisite()) add_action('network_admin_notices', array($this, 'show_notice_wpconfig_needs_fixes'), 10);
$this->ssl_enabled = false;
$this->save_options();
} elseif ($this->ssl_enabled) {
add_action('init', array($this, 'configure_ssl'), 20);
}
}
//when SSL is enabled, and not enabled by user, ask for activation.
add_action("admin_notices", array($this, 'show_notice_activate_ssl'), 10);
add_action('rsssl_activation_notice', array($this, 'no_ssl_detected'), 10);
add_action('rsssl_activation_notice', array($this, 'ssl_detected'), 10);
add_action('rsssl_activation_notice_inner', array($this, 'almost_ready_to_migrate'), 30);
add_action('rsssl_activation_notice_inner', array($this, 'show_pro'), 40);
add_action('rsssl_activation_notice_inner', array($this, 'show_enable_ssl_button'), 50);
add_action('plugins_loaded', array($this, 'check_plugin_conflicts'), 30);
//add the settings page for the plugin
add_action('admin_enqueue_scripts', array($this, 'enqueue_assets'));
add_action('admin_init', array($this, 'load_translation'), 20);
//settings page, form and settings link in the plugins page
add_action('admin_menu', array($this, 'add_settings_page'), 40);
add_action('admin_init', array($this, 'create_form'), 40);
add_action('admin_init', array($this, 'listen_for_deactivation'), 40);
//Only redirect while on own settings page, otherwise deactivate link in plugins overview will break.
//if ($this->is_settings_page()) {
add_action( 'update_option_rlrsssl_options', array( $this, 'maybe_remove_highlight_from_url' ) );
//}
$plugin = rsssl_plugin;
add_filter("plugin_action_links_$plugin", array($this, 'plugin_settings_link'));
//Add update notification to Settings admin menu
add_action('admin_menu', array($this, 'rsssl_edit_admin_menu') );
//check if the uninstallfile is safely renamed to php.
$this->check_for_uninstall_file();
//callbacks for the ajax dismiss buttons
add_action('wp_ajax_dismiss_htaccess_warning', array($this, 'dismiss_htaccess_warning_callback'));
add_action('wp_ajax_dismiss_success_message', array($this, 'dismiss_success_message_callback'));
add_action('wp_ajax_rsssl_dismiss_review_notice', array($this, 'dismiss_review_notice_callback'));
add_action('wp_ajax_rsssl_dismiss_settings_notice', array($this, 'dismiss_settings_notice_callback'));
//handle notices
add_action('admin_notices', array($this, 'show_notices'));
//show review notice, only to free users
if (!defined("rsssl_pro_version") && (!defined("rsssl_pp_version")) && (!defined("rsssl_soc_version")) && (!class_exists('RSSSL_PRO')) && (!is_multisite())) {
add_action('admin_notices', array($this, 'show_leave_review_notice'));
}
add_action("update_option_rlrsssl_options", array($this, "update_htaccess_after_settings_save"), 20, 3);
}
/*
* Deactivate the plugin while keeping SSL
* Activated when the 'uninstall_keep_ssl' button is clicked in the settings tab
*
*/
public function listen_for_deactivation()
{
//check if we are on ssl settings page
if (!$this->is_settings_page()) return;
//check user role
if (!current_user_can($this->capability)) return;
//check nonce
if (!isset($_GET['token']) || (!wp_verify_nonce($_GET['token'], 'rsssl_deactivate_plugin'))) return;
//check for action
if (isset($_GET["action"]) && $_GET["action"] == 'uninstall_keep_ssl') {
//deactivate plugin, but don't revert to http.
$plugin = $this->plugin_dir . "/" . $this->plugin_filename;
$plugin = plugin_basename(trim($plugin));
if (is_multisite()) {
$network_current = get_site_option('active_sitewide_plugins', array());
if (is_plugin_active_for_network($plugin)) {
unset($network_current[$plugin]);
}
update_site_option('active_sitewide_plugins', $network_current);
//remove plugin one by one on each site
$sites = get_sites();
foreach ($sites as $site) {
RSSSL()->rsssl_multisite->switch_to_blog_bw_compatible($site);
$current = get_option('active_plugins', array());
$current = $this->remove_plugin_from_array($plugin, $current);
update_option('active_plugins', $current);
restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
}
} else {
$current = get_option('active_plugins', array());
$current = $this->remove_plugin_from_array($plugin, $current);
update_option('active_plugins', $current);
}
wp_redirect(admin_url('plugins.php'));
exit;
}
}
/*
* Remove the plugin from the active plugins array when called from listen_for_deactivation
*
* */
public function remove_plugin_from_array($plugin, $current)
{
$key = array_search($plugin, $current);
if (false !== $key) {
unset($current[$key]);
}
return $current;
}
/*
* @Since 3.1
*
* Check if site uses an htaccess.conf file, used in bitnami installations
*
*/
public function uses_htaccess_conf() {
$htaccess_conf_file = dirname(ABSPATH) . "/conf/htaccess.conf";
//conf/htaccess.conf can be outside of open basedir, return false if so
$open_basedir = ini_get("open_basedir");
if (!empty($open_basedir)) return false;
if (is_file($htaccess_conf_file) ) {
return true;
} else {
return false;
}
}
public function get_sites_bw_compatible()
{
global $wp_version;
$sites = ($wp_version >= 4.6) ? get_sites() : wp_get_sites();
return $sites;
}
/*
The new get_sites function returns an object.
*/
public function switch_to_blog_bw_compatible($site)
{
global $wp_version;
if ($wp_version >= 4.6) {
switch_to_blog($site->blog_id);
} else {
switch_to_blog($site['blog_id']);
}
}
/*
checks if the user just clicked the "activate SSL" button.
*/
private function clicked_activate_ssl()
{
if (!current_user_can($this->capability)) return;
//if (!isset( $_POST['rsssl_nonce'] ) || !wp_verify_nonce( $_POST['rsssl_nonce'], 'rsssl_nonce' )) return false;
if (isset($_POST['rsssl_do_activate_ssl'])) {
$this->activate_ssl();
//if (empty(get_option('rsssl_activation_timestamp'))) {
update_option('rsssl_activation_timestamp', time());
//}
return true;
}
return false;
}
/*
Activate the SSL for this site
*/
public function activate_ssl()
{
$this->ssl_enabled = true;
$this->wp_redirect = true;
$this->set_siteurl_to_ssl();
$this->save_options();
}
public function deactivate_ssl()
{
$this->ssl_enabled = false;
$this->wp_redirect = false;
$this->htaccess_redirect = false;
$this->remove_ssl_from_siteurl();
$this->save_options();
}
public function redirect_to_settings_page_after_activation() {
if (isset($_GET['page']) && $_GET['page'] == 'rlrsssl_really_simple_ssl') return;
$url = add_query_arg( array(
"page" => "rlrsssl_really_simple_ssl",
), admin_url( "options-general.php" ) );
wp_redirect( $url );
exit;
}
public function wpconfig_ok()
{
if (($this->do_wpconfig_loadbalancer_fix || $this->no_server_variable || $this->wpconfig_siteurl_not_fixed) && !$this->wpconfig_is_writable()) {
$result = false;
} else {
$result = true;
}
return apply_filters('rsssl_wpconfig_ok_check', $result);
}
/*
This message is shown when no SSL is not enabled by the user yet
*/
public function show_notice_activate_ssl()
{
//prevent showing the review on edit screen, as gutenberg removes the class which makes it editable.
$screen = get_current_screen();
if ( $screen->parent_base === 'edit' ) return;
if ($this->ssl_enabled) return;
if (defined("RSSSL_DISMISS_ACTIVATE_SSL_NOTICE") && RSSSL_DISMISS_ACTIVATE_SSL_NOTICE) return;
//for multisite, show only activate when a choice has been made to activate networkwide or per site.
if (is_multisite() && !RSSSL()->rsssl_multisite->selected_networkwide_or_per_site) return;
//on multisite, only show this message on the network admin. Per site activated sites have to go to the settings page.
//otherwise sites that do not need SSL possibly get to see this message.
if (is_multisite() && !is_network_admin()) return;
if (!$this->wpconfig_ok()) return;
if (!current_user_can($this->capability)) return;
do_action('rsssl_activation_notice');
}
public function ssl_detected()
{
if ($this->site_has_ssl) {
?>
';
printf(__("Really Simple SSL failed to detect a valid SSL certificate. If you do have an SSL certificate, try to reload this page over https by clicking this button: %sReload over https%s The built-in certificate check will run once daily, to force a new certificate check visit the SSL settings page. ", "really-simple-ssl"), $link_open, $link_close);
$ssl_test_url = "https://www.ssllabs.com/ssltest/";
$link_open = '';
$link_close = '';
printf(__("Really Simple SSL requires a valid SSL certificate. You can check your certificate on %sQualys SSL Labs%s.", "really-simple-ssl"), $link_open, $link_close);
echo "
";
printf(__("If your site has cPanel, you can %sget a free SSL certificate%s. ", "really-simple-ssl"), '', '');
?>
ABSpath.well-known/acme-challenge")) {
return true;
}
return false;
}
/**
*
* @return bool
* since 3.1
* Check if there are already .well-known rules in .htaccess file
* @access public
*
*/
public function has_well_known_needle()
{
$htaccess = file_get_contents($this->htaccess_file());
$well_known_needle = ".well-known";
if (strpos($htaccess, $well_known_needle) !== false) {
return true;
}
return false;
}
public function show_leave_review_notice()
{
//prevent showing the review on edit screen, as gutenberg removes the class which makes it editable.
$screen = get_current_screen();
if ( $screen->parent_base === 'edit' ) return;
//this user has never had the review notice yet.
if ($this->ssl_enabled && !get_option('rsssl_activation_timestamp')){
$month = rand ( 0, 11);
$trigger_notice_date = time() + $month * MONTH_IN_SECONDS;
update_option('rsssl_activation_timestamp', $trigger_notice_date);
update_option('rsssl_before_review_notice_user', true);
}
if (!$this->review_notice_shown && get_option('rsssl_activation_timestamp') && get_option('rsssl_activation_timestamp') < strtotime("-1 month")) {
if ($this->dismiss_review_notice) return;
add_action('admin_print_footer_scripts', array($this, 'insert_dismiss_review'));
?>
site_has_ssl) {
if (sizeof($this->plugin_conflict) > 0) {
//pre WooCommerce 2.5
if (isset($this->plugin_conflict["WOOCOMMERCE_FORCEHTTP"]) && $this->plugin_conflict["WOOCOMMERCE_FORCEHTTP"] && isset($this->plugin_conflict["WOOCOMMERCE_FORCESSL"]) && $this->plugin_conflict["WOOCOMMERCE_FORCESSL"]) {
?>
capability) ) return;
//nonce check fails if url is changed to SSL.
//check_ajax_referer( 'really-simple-ssl-dismiss', 'security' );
$this->ssl_success_message_shown = TRUE;
$this->save_options();
wp_die();
}
/**
* Process the ajax dismissal of the htaccess message.
*
* @since 2.1
*
* @access public
*
*/
public function dismiss_htaccess_warning_callback()
{
if (!current_user_can($this->capability) ) return;
check_ajax_referer('really-simple-ssl', 'security');
$this->htaccess_warning_shown = TRUE;
$this->save_options();
wp_die(); // this is required to terminate immediately and return a proper response
}
/**
* Process the ajax dismissal of settings notice
*
* Since 3.1
*
* @access public
*
*/
public function dismiss_settings_notice_callback()
{
if (!current_user_can($this->capability) ) return;
check_ajax_referer('really-simple-ssl', 'security');
if (isset($_POST['type'])) {
$dismiss_type = sanitize_title( $_POST['type'] );
update_option( "rsssl_".$dismiss_type."_dismissed", true );
delete_transient( 'rsssl_plusone_count' );
}
wp_die(); // this is required to terminate immediately and return a proper response
}
/**
* Process the ajax dismissal of the htaccess message.
*
* @since 2.1
*
* @access public
*
*/
public function dismiss_review_notice_callback()
{
$type = isset($_POST['type']) ? $_POST['type'] : false;
if ($type === 'dismiss'){
$this->review_notice_shown = TRUE;
}
if ($type === 'later') {
//Reset activation timestamp, notice will show again in one month.
update_option('rsssl_activation_timestamp', time());
}
$this->save_options();
wp_die(); // this is required to terminate immediately and return a proper response
}
/**
* Adds the admin options page
*
* @since 2.0
*
* @access public
*
*/
public function add_settings_page()
{
if (!current_user_can($this->capability)) return;
//hides the settings page if the hide menu for subsites setting is enabled
if (is_multisite() && rsssl_multisite::this()->hide_menu_for_subsites && !is_super_admin()) return;
global $rsssl_admin_page;
$count = $this->count_plusones();
if ($count > 0 ) {
$update_count = "$count";
} else {
$update_count = "";
}
$rsssl_admin_page = add_options_page(
__("SSL settings", "really-simple-ssl"), //link title
__("SSL", "really-simple-ssl") . $update_count, //page title
$this->capability, //capability
'rlrsssl_really_simple_ssl', //url
array($this, 'settings_page')); //function
// Adds my_help_tab when my_admin_page loads
add_action('load-' . $rsssl_admin_page, array($this, 'admin_add_help_tab'));
}
/**
*
* @since 3.1.6
*
* Add an update count to the WordPress admin Settings menu item
* Doesn't work when the Admin Menu Editor plugin is active
*
*/
public function rsssl_edit_admin_menu()
{
if (!current_user_can($this->capability)) return;
global $menu;
$count = $this->count_plusones();
$menu_slug = 'options-general.php';
$menu_title = __('Settings');
foreach($menu as $index => $menu_item){
if (!isset($menu_item[2]) || !isset($menu_item[0])) continue;
if ($menu_item[2]===$menu_slug){
$pattern = '/([1-9])<\/span><\/span>/i';
if (preg_match($pattern, $menu_item[0], $matches)){
if (isset($matches[1])) $count = intval($count) + intval($matches[1]);
}
$update_count = $count > 0 ? "$count":'';
$menu[$index][0] = $menu_title . $update_count;
}
}
}
/**
* Admin help tab
*
* @since 2.0
*
* @access public
*
*/
public function admin_add_help_tab()
{
$screen = get_current_screen();
// Add my_help_tab if current screen is My Admin Page
$screen->add_help_tab(array(
'id' => "really-simple-ssl-documentation",
'title' => __("Documentation", "really-simple-ssl"),
'content' => '
' . __("On really-simple-ssl.com you can find a lot of articles and documentation about installing this plugin, and installing SSL in general.", "really-simple-ssl") . '
',
));
}
/**
* Create tabs on the settings page
*
* @since 2.1
*
* @access public
*
*/
public function admin_tabs($current = 'homepage')
{
$tabs = array(
'configuration' => __("Configuration", "really-simple-ssl"),
'settings' => __("Settings", "really-simple-ssl"),
'debug' => __("Debug", "really-simple-ssl")
);
$tabs = apply_filters("rsssl_tabs", $tabs);
echo '
";
echo "Options ";
if ($this->autoreplace_insecure_links) echo "* Mixed content fixer ";
if ($this->wp_redirect) echo "* WordPress redirect ";
if ($this->htaccess_redirect) echo "* htaccess redirect ";
if ($this->do_not_edit_htaccess) echo "* Stop editing the .htaccess file ";
if ($this->switch_mixed_content_fixer_hook) echo "* Use alternative method to fix mixed content ";
if ($this->dismiss_all_notices) echo "* Dismiss all Really Simple SSL notices ";
echo " ";
echo "Server information ";
echo "Server: " . RSSSL()->rsssl_server->get_server() . " ";
echo "SSL Type: $this->ssl_type ";
if (is_multisite()) {
echo "MULTISITE ";
echo (!RSSSL()->rsssl_multisite->ssl_enabled_networkwide) ? "SSL is being activated per site " : "SSL is activated network wide ";
}
echo $this->debug_log;
echo "
Constants ";
if (defined('RSSSL_FORCE_ACTIVATE')) echo "RSSSL_FORCE_ACTIVATE defined";
if (defined('RSSSL_NO_FLUSH')) echo "RSSSL_NO_FLUSH defined";
if (defined('RSSSL_DISMISS_ACTIVATE_SSL_NOTICE')) echo "RSSSL_DISMISS_ACTIVATE_SSL_NOTICE defined";
if (defined('RLRSSSL_DO_NOT_EDIT_HTACCESS')) echo "RLRSSSL_DO_NOT_EDIT_HTACCESS defined";
if (defined('RSSSL_SAFE_MODE')) echo "RSSSL_SAFE_MODE defined";
if (defined("RSSSL_SERVER_OVERRIDE")) echo "RSSSL_SERVER_OVERRIDE defined";
if( !defined('RSSSL_FORCE_ACTIVATE')
&& !defined('RSSSL_NO_FLUSH')
&& !defined('RSSSL_DISMISS_ACTIVATE_SSL_NOTICE')
&& !defined('RLRSSSL_DO_NOT_EDIT_HTACCESS')
&& !defined('RSSSL_SAFE_MODE')
&& !defined("RSSSL_SERVER_OVERRIDE")
) echo "No constants defined";
echo "
";
$this->debug_log = "";
$this->save_options();
} else {
echo " ";
_e("To view results here, enable the debug option in the settings tab.", "really-simple-ssl");
}
?>
"; ?>
';
?>
") ?>
get_banner_html(array(
'img' => 'rsssl-pro.jpg',
'title' => 'Really Simple SSL Pro',
'description' => __("Really Simple SSL Pro optimizes your SSL configuration: extensive scan for mixed content issues, access to premium support, HSTS and more!", "really-simple-ssl"),
'url' => $url,
'pro' => true,
)
);
if (!class_exists('COMPLIANZ')) {
$this->get_banner_html( array(
'img' => 'complianz.jpg',
'title' => 'Complianz',
'description' => __( "The Complianz Privacy Suite (GDPR/CaCPA) for WordPress. Simple, Quick and Complete. Up-to-date customized legal documents by a prominent IT Law firm.", "really-simple-ssl" ),
'url' => "$admin_url" . "plugin-install.php?s=complianz+RogierLankhorst&tab=search&type=term",
'pro' => true,
)
);
}
if (!defined("ZRDN_PLUGIN_DIRECTORY")) {
$this->get_banner_html(array(
'img' => 'ziprecipes.png',
'title' => 'Zip Recipes',
'description' => __("Create beautiful SEO friendly recipe cards for your recipes with Zip Recipes.", "really-simple-ssl"),
'url' => "$admin_url" . "plugin-install.php?s=zip+recipes+RogierLankhorst&tab=search&type=term",
)
);
}
if (!defined("wp_search_insights_plugin")) {
$this->get_banner_html(array(
'img' => 'wpsearchinsights.jpg',
'title' => 'WP Search Insights',
'description' => __("Records all searches made on your site. See valuable insights in a clean dashboard", "really-simple-ssl"),
'url' => "$admin_url" . "plugin-install.php?s=wp+search+insights+Rogier+Lankhorst&tab=search&type=term",
)
);
}
if (defined("ultimatemember_version")) {
if (!defined("um_tagging_version")) {
$this->get_banner_html(array(
'img' => 'tagging.jpg',
'title' => 'UM Tagging',
'description' => __("UM Tagging allows you to @tag or @mention all users on your platform.", "really-simple-ssl"),
'url' => 'https://really-simple-plugins.com/download/um-tagging/',
)
);
}
}
if (defined("EDD_SL_PLUGIN_DIR") && (get_locale() === 'nl_NL')) {
$this->get_banner_html(array(
'img' => 'edd-moneybird.jpg',
'title' => 'EDD Moneybird',
'description' => __("Export your Easy Digital Downloads sales directly to Moneybird.", "really-simple-ssl"),
'url' => 'https://really-simple-plugins.com/download/edd-moneybird/',
)
);
}
if (defined('WC_PLUGIN_FILE') && (get_locale() === 'nl_NL')) {
$this->get_banner_html(array(
'img' => 'woocommerce-moneybird.jpg',
'title' => 'WooCommerce Moneybird',
'description' => __("Export your WooCommerce sales directly to Moneybird.", "really-simple-ssl"),
'url' => 'https://really-simple-plugins.com/download/woocommerce-moneybird/',
)
);
}
?>
";
} elseif ($type == "error") {
return "";
} else {
return "";
}
}
/**
*
* Add a dismiss button which will dismiss the nearest
. Used on 'Configuration' dashboard page
*
* @since 3.1.6
*
*/
public function rsssl_dismiss_button()
{
return '';
}
/**
* @param $args
*
* @since 3.0
*
* Generate the HTML for the settings page sidebar
*
*/
private function get_banner_html($args)
{
$default = array(
'pro' => false,
);
$args = wp_parse_args($args, $default);
$pro = $args['pro'] ? '-pro' : '';
?>
is_settings_page()) {
add_action( 'admin_head', array( $this, 'highlight_js' ) );
}
register_setting('rlrsssl_options', 'rlrsssl_options', array($this, 'options_validate'));
// Show a dismiss review
if (!$this->dismiss_review_notice && !$this->review_notice_shown && get_option('rsssl_activation_timestamp') && get_option('rsssl_activation_timestamp') < strtotime("-1 month")) {
add_settings_field('id_dismiss_review_notice', __("Dismiss review notice", "really-simple-ssl"), array($this, 'get_option_dismiss_review_notice'), 'rlrsssl', 'rlrsssl_settings');
}
add_settings_section('rlrsssl_settings', __("Settings", "really-simple-ssl"), array($this, 'section_text'), 'rlrsssl');
add_settings_field('id_autoreplace_insecure_links', __("Mixed content fixer", "really-simple-ssl"), array($this, 'get_option_autoreplace_insecure_links'), 'rlrsssl', 'rlrsssl_settings');
//only show option to enable or disable mixed content and redirect when SSL is detected
if ($this->ssl_enabled) {
add_settings_field('id_wp_redirect', __("Enable WordPress 301 redirection to SSL", "really-simple-ssl"), array($this, 'get_option_wp_redirect'), 'rlrsssl', 'rlrsssl_settings');
//when enabled networkwide, it's handled on the network settings page
if (RSSSL()->rsssl_server->uses_htaccess() && (!is_multisite() || !RSSSL()->rsssl_multisite->ssl_enabled_networkwide)) {
add_settings_field('id_htaccess_redirect', __("Enable 301 .htaccess redirect", "really-simple-ssl"), array($this, 'get_option_htaccess_redirect'), 'rlrsssl', 'rlrsssl_settings');
}
add_settings_field('id_javascript_redirect', __("Enable Javascript redirection to SSL", "really-simple-ssl"), array($this, 'get_option_javascript_redirect'), 'rlrsssl', 'rlrsssl_settings');
}
add_settings_field('id_debug', __("Debug", "really-simple-ssl"), array($this, 'get_option_debug'), 'rlrsssl', 'rlrsssl_settings');
//on multisite this setting can only be set networkwide
if (RSSSL()->rsssl_server->uses_htaccess() && !is_multisite()) {
add_settings_field('id_do_not_edit_htaccess', __("Stop editing the .htaccess file", "really-simple-ssl"), array($this, 'get_option_do_not_edit_htaccess'), 'rlrsssl', 'rlrsssl_settings');
}
add_settings_field('id_switch_mixed_content_fixer_hook', __("Use alternative method to fix mixed content", "really-simple-ssl"), array($this, 'get_option_switch_mixed_content_fixer_hook'), 'rlrsssl', 'rlrsssl_settings');
add_settings_field('id_dismiss_all_notices', __("Dismiss all Really Simple SSL notices", "really-simple-ssl"), array($this, 'get_option_dismiss_all_notices'), 'rlrsssl', 'rlrsssl_settings');
add_settings_field('id_deactivate_keep_ssl', __("Deactivate plugin and keep SSL", "really-simple-ssl"), array($this, 'get_option_deactivate_keep_ssl'), 'rlrsssl', 'rlrsssl_settings');
}
/**
* Insert some explanation above the form
*
* @since 2.0
*
* @access public
*
*/
public function section_text()
{
?>
site_has_ssl;
$newinput['ssl_success_message_shown'] = $this->ssl_success_message_shown;
$newinput['htaccess_warning_shown'] = $this->htaccess_warning_shown;
$newinput['review_notice_shown'] = $this->review_notice_shown;
$newinput['plugin_db_version'] = $this->plugin_db_version;
$newinput['ssl_enabled'] = $this->ssl_enabled;
$newinput['debug_log'] = $this->debug_log;
$newinput['dismiss_review_notice'] = $this->dismiss_review_notice;
if (!empty($input['hsts']) && $input['hsts'] == '1') {
$newinput['hsts'] = TRUE;
} else {
$newinput['hsts'] = FALSE;
}
if (!empty($input['javascript_redirect']) && $input['javascript_redirect'] == '1') {
$newinput['javascript_redirect'] = TRUE;
} else {
$newinput['javascript_redirect'] = FALSE;
}
if (!empty($input['wp_redirect']) && $input['wp_redirect'] == '1') {
$newinput['wp_redirect'] = TRUE;
} else {
$newinput['wp_redirect'] = FALSE;
}
if (!empty($input['autoreplace_insecure_links']) && $input['autoreplace_insecure_links'] == '1') {
$newinput['autoreplace_insecure_links'] = TRUE;
} else {
$newinput['autoreplace_insecure_links'] = FALSE;
}
if (!empty($input['debug']) && $input['debug'] == '1') {
$newinput['debug'] = TRUE;
} else {
$newinput['debug'] = FALSE;
$this->debug_log = "";
}
if (!empty($input['do_not_edit_htaccess']) && $input['do_not_edit_htaccess'] == '1') {
$newinput['do_not_edit_htaccess'] = TRUE;
} else {
$newinput['do_not_edit_htaccess'] = FALSE;
}
if (!empty($input['switch_mixed_content_fixer_hook']) && $input['switch_mixed_content_fixer_hook'] == '1') {
$newinput['switch_mixed_content_fixer_hook'] = TRUE;
} else {
$newinput['switch_mixed_content_fixer_hook'] = FALSE;
}
if (!empty($input['dismiss_all_notices']) && $input['dismiss_all_notices'] == '1') {
$newinput['dismiss_all_notices'] = TRUE;
} else {
$newinput['dismiss_all_notices'] = FALSE;
}
if (!empty($input['dismiss_review_notice']) && $input['dismiss_review_notice'] == '1') {
$newinput['dismiss_review_notice'] = TRUE;
} else {
$newinput['dismiss_review_notice'] = FALSE;
}
if (!empty($input['htaccess_redirect']) && $input['htaccess_redirect'] == '1') {
$newinput['htaccess_redirect'] = TRUE;
} else {
$newinput['htaccess_redirect'] = FALSE;
}
return $newinput;
}
/**
* Insert option into settings form
* deprecated
* @since 2.0
*
* @access public
*
*/
public function get_option_debug()
{
?>
rsssl_help->get_help_tip(__("Enable this option to get debug info in the debug tab.", "really-simple-ssl"));
}
/**
* Insert option into settings form
* @since 2.2
*
* @access public
*
*/
public function get_option_javascript_redirect()
{
$javascript_redirect = $this->javascript_redirect;
$disabled = "";
$comment = "";
if (is_multisite() && rsssl_multisite::this()->javascript_redirect) {
$disabled = "disabled";
$javascript_redirect = TRUE;
$comment = __("This option is enabled on the network menu.", "really-simple-ssl");
}
?>
rsssl_help->get_help_tip(__("This is a fallback you should only use if other redirection methods do not work.", "really-simple-ssl"));
echo $comment;
}
/**
* Insert option into settings form
* @since 2.5.0
*
* @access public
*
*/
public function get_option_wp_redirect()
{
$wp_redirect = $this->wp_redirect;
$disabled = "";
$comment = "";
if (is_multisite() && rsssl_multisite::this()->wp_redirect) {
$disabled = "disabled";
$wp_redirect = TRUE;
$comment = __("This option is enabled on the network menu.", "really-simple-ssl");
}
?>
rsssl_help->get_help_tip(__("Enable this if you want to use the internal WordPress 301 redirect. Needed on NGINX servers, or if the .htaccess redirect cannot be used.", "really-simple-ssl"));
echo $comment;
}
/**
* Insert option into settings form
* The .htaccess redirect is not shown for multisite sites that are enabled network wide.
*
* @since 2.5.8
*
* @access public
*
*/
public function get_option_htaccess_redirect()
{
$options = get_option('rlrsssl_options');
$htaccess_redirect = $this->htaccess_redirect;
$disabled = "";
$comment = "";
//networkwide is not shown, so this only applies to per site activated sites.
if (is_multisite() && RSSSL()->rsssl_multisite->htaccess_redirect) {
$disabled = "disabled";
$htaccess_redirect = TRUE;
$comment = __("This option is enabled on the network menu.", "really-simple-ssl");
} else {
$disabled = ($this->do_not_edit_htaccess) ? "disabled" : "";
}
?>
rsssl_help->get_help_tip(__("A .htaccess redirect is faster. Really Simple SSL detects the redirect code that is most likely to work (99% of websites), but this is not 100%. Make sure you know how to regain access to your site if anything goes wrong!", "really-simple-ssl"));
echo $comment;
if ($this->uses_htaccess_conf()) {
$htaccess_file = "htaccess.conf (/conf/htaccess.conf/)";
} else {
$htaccess_file = ".htaccess";
}
if ($this->htaccess_redirect && (!is_writable($this->htaccess_file()) || !$this->htaccess_test_success)) {
echo "
";
if (!is_writable($this->htaccess_file())) _e("The $htaccess_file file is not writable. Add these lines to your htaccess manually, or set 644 writing permissions.", "really-simple-ssl");
if (!$this->htaccess_test_success) _e("The .htaccess redirect rules that were selected by this plugin failed in the test. The following redirect rules were tested:", "really-simple-ssl");
echo "
";
if ($this->ssl_type != "NA") {
$manual = true;
$rules = $this->get_redirect_rules($manual);
$arr_search = array("<", ">", "\n");
$arr_replace = array("<", ">", " ");
$rules = str_replace($arr_search, $arr_replace, $rules);
?>
do_not_edit_htaccess) {
_e("If the setting 'do not edit htaccess' is enabled, you can't change this setting.", "really-simple-ssl");
} elseif (!$this->htaccess_redirect) {
$link_start = '';
$link_end = '';
printf(
__('Before you enable this, make sure you know how to %1$sregain access%2$s to your site in case of a redirect loop.', 'really-simple-ssl'),
$link_start,
$link_end
);
}
}
}
/**
* Insert option into settings form
*
* @since 2.0
*
* @access public
*
*/
public function get_option_do_not_edit_htaccess()
{
?>
rsssl_help->get_help_tip(__("If you want to customize the Really Simple SSL .htaccess, you need to prevent Really Simple SSL from rewriting it. Enabling this option will do that.", "really-simple-ssl"));
if (!$this->do_not_edit_htaccess && !is_writable($this->htaccess_file())) _e(".htaccess is currently not writable.", "really-simple-ssl");
}
/**
* Insert option into settings form
*
* @since 2.1
*
* @access public
*
*/
public function get_option_switch_mixed_content_fixer_hook()
{
?>
rsssl_help->get_help_tip(__("If this option is set to true, the mixed content fixer will fire on the init hook instead of the template_redirect hook. Only use this option when you experience problems with the mixed content fixer.", "really-simple-ssl"));
}
/**
*
* Get the option to dismiss all Really Simple SSL notices
*
* @since 3.2
*
* @access public
*
*/
public function get_option_dismiss_all_notices()
{
?>
rsssl_help->get_help_tip(__("Enable this option to dismiss all +1 notices in the Configuration tab", "really-simple-ssl"));
}
/**
*
* Add a button and thickbox to deactivate the plugin while keeping SSL
*
* @since 3.0
*
* @access public
*
*/
public function get_option_deactivate_keep_ssl()
{
?>
rsssl_help->get_help_tip(__("Clicking this button will deactivate the plugin while keeping your site on SSL. The WordPress 301 redirect, Javascript redirect and mixed content fixer will stop working. The site address will remain https:// and the .htaccess redirect will remain active. Deactivating the plugin via the plugins overview will revert the site back to http://.", "really-simple-ssl"));
}
/**
* Since 3.3.2
*/
public function get_option_dismiss_review_notice() {
?>
rsssl_help->get_help_tip(__("Enable this option to dismiss the review notice.", "really-simple-ssl"));
}
/**
*
* Mixed content fixer option
*
*/
public function get_option_autoreplace_insecure_links()
{
//$options = get_option('rlrsssl_options');
$autoreplace_mixed_content = $this->autoreplace_insecure_links;
$disabled = "";
$comment = "";
if (is_multisite() && rsssl_multisite::this()->autoreplace_mixed_content) {
$disabled = "disabled";
$autoreplace_mixed_content = TRUE;
$comment = __("This option is enabled on the network menu.", "really-simple-ssl");
}
?>
rsssl_help->get_help_tip(__("In most cases you need to leave this enabled, to prevent mixed content issues on your site.", "really-simple-ssl"));
echo $comment;
}
/**
* Add settings link on plugins overview page
*
* @since 2.0
*
* @access public
*
*/
public function plugin_settings_link($links)
{
//add 'revert to http' after the Deactivate link on the plugins overview page
if (isset($links['deactivate'])) {
$deactivate_link = $links['deactivate'];
$links['deactivate'] = str_replace('', " " . __("(revert to http)", "really-simple-ssl") . '', $deactivate_link);
}
$settings_link = '' . __("Settings", "really-simple-ssl") . '';
array_unshift($links, $settings_link);
$faq_link = '' . __('Docs', 'really-simple-ssl') . '';
array_unshift($links, $faq_link);
if (defined("rsssl_pro_version")) {
if (class_exists('RSSSL_PRO')) {
if (RSSSL_PRO()->rsssl_licensing->license_is_valid()) return $links;
}
}
if (!defined("rsssl_pro_version")) {
if (!class_exists('RSSSL_PRO')) {
$premium_link = '' . __('Premium Support', 'really-simple-ssl') . '';
array_unshift($links, $premium_link);
}
}
return $links;
}
/**
* Check for possible plugin conflicts
*
* @since 2.0
*
* @access public
* @return none
*
*/
public function check_plugin_conflicts()
{
// $this->plugin_conflict["WOOCOMMERCE_FORCESSL"] = TRUE;
}
/**
* Check if wpconfig contains httponly cooky settings
*
* @since 2.5
*
* @access public
* @return boolean
*
*/
public function contains_secure_cookie_settings()
{
$wpconfig_path = $this->find_wp_config_path();
if (!$wpconfig_path) return false;
$wpconfig = file_get_contents($wpconfig_path);
if ((strpos($wpconfig, "//Begin Really Simple SSL session cookie settings") === FALSE) && (strpos($wpconfig, "cookie_httponly") === FALSE)) {
return false;
}
return true;
}
/**
* Get the absolute path the the www directory of this site, where .htaccess lives.
*
* @since 2.0
*
* @access public
*
*/
public function getABSPATH()
{
$path = ABSPATH;
if ($this->is_subdirectory_install()) {
$siteUrl = site_url();
$homeUrl = home_url();
$diff = str_replace($homeUrl, "", $siteUrl);
$diff = trim($diff, "/");
$pos = strrpos($path, $diff);
if ($pos !== false) {
$path = substr_replace($path, "", $pos, strlen($diff));
$path = trim($path, "/");
$path = "/" . $path . "/";
}
}
return $path;
}
/**
* Find if this WordPress installation is installed in a subdirectory
*
* @since 2.0
*
* @access protected
*
*/
protected function is_subdirectory_install()
{
if (strlen(site_url()) > strlen(home_url())) {
return true;
}
return false;
}
/**
* @return mixed|string
*
* Retrieve the contents of the test page
*
*/
protected function get_test_page_contents()
{
$filecontents = get_transient('rsssl_testpage');
if (!$filecontents) {
$filecontents = "";
$testpage_url = trailingslashit($this->test_url()) . "ssl-test-page.php";
$this->trace_log("Opening testpage to check server configuration: " . $testpage_url);
$response = wp_remote_get($testpage_url);
if (is_array($response)) {
$status = wp_remote_retrieve_response_code($response);
$filecontents = wp_remote_retrieve_body($response);
}
$this->trace_log("test page url, enter in browser to check manually: " . $testpage_url);
if (!is_wp_error($response) && (strpos($filecontents, "#SSL TEST PAGE#") !== false)) {
$this->trace_log("SSL test page loaded successfully");
} else {
$error = "";
if (is_wp_error($response)) $error = $response->get_error_message();
$this->trace_log("Could not open testpage " . $error);
}
if (empty($filecontents)) {
$filecontents = 'not-valid';
}
set_transient('rsssl_testpage', $filecontents, 600);
}
return $filecontents;
}
/**
*
* @return string
*
* since 3.1
*
* Determine dirname to show in admin_notices() in really-simple-ssl-pro.php to show a warning when free folder has been renamed
*/
public function get_current_rsssl_free_dirname() {
return basename( __DIR__ );
}
/**
* @return string
*
* since 3.1
*
* Determine the htaccess file. This can be either the regular .htaccess file, or an htaccess.conf file on bitnami installations.
*
*/
public function htaccess_file() {
if ($this->uses_htaccess_conf()) {
$htaccess_file = realpath(dirname(ABSPATH) . "/conf/htaccess.conf");
} else {
$htaccess_file = $this->ABSpath . ".htaccess";
}
return $htaccess_file;
}
/**
*
* Insert script to highlight option after dashboard click
*
* @since 3.2
*
* @access public
*
*/
public function highlight_js(){
?>
"rlrsssl_really_simple_ssl",
"tab" => "settings"
), admin_url( "options-general.php" ) );
wp_safe_redirect( $url );
exit;
}
}
} //class closure
/**
* Wrapper functions for dashboard notices()
* @return string
*/
if (!function_exists('rsssl_mixed_content_fixer_detected')) {
function rsssl_mixed_content_fixer_detected() {
return RSSSL()->really_simple_ssl->mixed_content_fixer_detected();
}
}
if (!function_exists('rsssl_site_has_ssl')) {
function rsssl_site_has_ssl() {
return RSSSL()->really_simple_ssl->site_has_ssl;
}
}
if (!function_exists('rsssl_autoreplace_insecure_links')) {
function rsssl_autoreplace_insecure_links() {
return RSSSL()->really_simple_ssl->autoreplace_insecure_links;
}
}
if (!function_exists('rsssl_ssl_enabled')) {
function rsssl_ssl_enabled() {
if ( RSSSL()->really_simple_ssl->ssl_enabled ) {
return 'ssl-enabled';
} else {
return 'ssl-not-enabled';
}
}
}
if (!function_exists('rsssl_ssl_detected')) {
function rsssl_ssl_detected() {
if ( ! RSSSL()->really_simple_ssl->wpconfig_ok() ) {
return 'fail';
}
if ( ! RSSSL()->really_simple_ssl->site_has_ssl ) {
return 'no-ssl-detected';
}
if ( RSSSL()->rsssl_certificate->is_valid() ) {
return 'ssl-detected';
}
return false;
}
}
if (!function_exists('rsssl_check_redirect')) {
function rsssl_check_redirect() {
if ( ! RSSSL()->really_simple_ssl->has_301_redirect() ) {
return 'no-redirect-set';
}
if ( RSSSL()->really_simple_ssl->has_301_redirect() && RSSSL()->rsssl_server->uses_htaccess() && RSSSL()->really_simple_ssl->htaccess_contains_redirect_rules() ) {
return 'htaccess-redirect-set';
}
if ( RSSSL()->really_simple_ssl->has_301_redirect() && RSSSL()->really_simple_ssl->wp_redirect && RSSSL()->rsssl_server->uses_htaccess() && ! RSSSL()->really_simple_ssl->htaccess_redirect ) {
return 'wp-redirect-to-htaccess';
}
if ( RSSSL()->rsssl_server->uses_htaccess() && ( ! is_multisite() || ! RSSSL()->rsssl_multisite->is_per_site_activated_multisite_subfolder_install() ) ) {
if ( ! is_writable( RSSSL()->really_simple_ssl->htaccess_file() ) ) {
return 'htaccess-not-writeable';
} else {
return 'htaccess-cannot-be-set';
}
} else {
return 'default';
}
}
}
if (!function_exists('rsssl_hsts_enabled')) {
function rsssl_hsts_enabled() {
if ( RSSSL()->really_simple_ssl->contains_hsts() ) {
return 'contains-hsts';
} else {
return 'no-hsts';
}
}
}
if (!function_exists('rsssl_secure_cookies_set')) {
function rsssl_secure_cookies_set() {
if ( RSSSL()->really_simple_ssl->contains_secure_cookie_settings() ) {
return 'set';
} else {
return 'not-set';
}
}
}
if (!function_exists('rsssl_scan_upsell')) {
function rsssl_scan_upsell() {
return 'upsell';
}
}
if (!function_exists('rsssl_htaccess_redirect_allowed')) {
function rsssl_htaccess_redirect_allowed() {
return RSSSL()->really_simple_ssl->htaccess_redirect_allowed();
}
}
// Non-prefixed for backwards compatibility
if (!function_exists('uses_elementor')) {
function uses_elementor() {
if ( defined( 'ELEMENTOR_VERSION' ) || defined( 'ELEMENTOR_PRO_VERSION' ) ) {
return true;
} else {
return false;
}
}
}
if (!function_exists('rsssl_uses_elementor')) {
function rsssl_uses_elementor() {
if ( defined( 'ELEMENTOR_VERSION' ) || defined( 'ELEMENTOR_PRO_VERSION' ) ) {
return true;
} else {
return false;
}
}
}
if (!function_exists('rsssl_uses_divi')) {
function rsssl_uses_divi() {
if ( defined( 'ET_CORE_PATH' ) ) {
return true;
} else {
return false;
}
}
}
if (!function_exists('rsssl_ssl_activation_time_no_longer_then_3_days_ago')) {
function rsssl_ssl_activation_time_no_longer_then_3_days_ago() {
$activation_time = get_option( 'rsssl_activation_timestamp' );
$three_days_after_activation = $activation_time + 3 * DAY_IN_SECONDS;
if ( time() < $three_days_after_activation ) {
return true;
} else {
return false;
}
}
}
if (!function_exists('rsssl_elementor_notice')) {
function rsssl_elementor_notice() {
return 'elementor-notice';
}
}
if (!function_exists('rsssl_wp_redirect_condition')) {
function rsssl_wp_redirect_condition() {
if ( RSSSL()->really_simple_ssl->has_301_redirect() && RSSSL()->really_simple_ssl->wp_redirect && ! RSSSL()->really_simple_ssl->htaccess_redirect ) {
return true;
} else {
return false;
}
}
}
if (!function_exists('rsssl_wordpress_redirect')) {
function rsssl_wordpress_redirect() {
if ( RSSSL()->really_simple_ssl->has_301_redirect() && RSSSL()->really_simple_ssl->wp_redirect ) {
return '301-wp-redirect';
} else {
return 'no-redirect';
}
}
}
if (!function_exists('rsssl_no_multisite')) {
function rsssl_no_multisite() {
if ( ! is_multisite() ) {
return true;
} else {
return false;
}
}
}
if (!function_exists('rsssl_does_not_use_pro')) {
function rsssl_does_not_use_pro() {
if ( ! defined("rsssl_pro_version") ) {
// Does not use RSSSL pro
return true;
} else {
return false;
}
}
}