/wp-content/plugins/really-simple-ssl/class-multisite.php

https://bitbucket.org/carloskikea/helpet · PHP · 786 lines · 523 code · 140 blank · 123 comment · 63 complexity · 54409f830f6ae3639e669eccdef5818f MD5 · raw file

  1. <?php
  2. defined('ABSPATH') or die("you do not have access to this page!");
  3. if ( ! class_exists( 'rsssl_multisite' ) ) {
  4. class rsssl_multisite {
  5. private static $_this;
  6. public $option_group = "rsssl_network_options";
  7. public $page_slug = "really-simple-ssl";
  8. public $section = "rsssl_network_options_section";
  9. public $ssl_enabled_networkwide;
  10. public $selected_networkwide_or_per_site;
  11. public $wp_redirect;
  12. public $htaccess_redirect;
  13. public $do_not_edit_htaccess;
  14. public $autoreplace_mixed_content;
  15. public $javascript_redirect;
  16. public $hsts;
  17. public $mixed_content_admin;
  18. public $cert_expiration_warning;
  19. public $hide_menu_for_subsites;
  20. private $pro_url = "https://www.really-simple-ssl.com/pro-multisite";
  21. function __construct() {
  22. if ( isset( self::$_this ) )
  23. wp_die( sprintf( __( '%s is a singleton class and you cannot create a second instance.','really-simple-ssl' ), get_class( $this ) ) );
  24. self::$_this = $this;
  25. $this->load_options();
  26. register_activation_hook( dirname( __FILE__ )."/".rsssl_plugin, array($this,'activate') );
  27. /*filters to make sure WordPress returns the correct protocol */
  28. add_filter("admin_url", array($this, "check_admin_protocol"), 20, 3 );
  29. add_filter('home_url', array($this, 'check_site_protocol') , 20,4);
  30. add_filter('site_url', array($this, 'check_site_protocol') , 20,4);
  31. add_action("plugins_loaded", array($this, "process_networkwide_choice"), 10, 0);
  32. add_action("plugins_loaded", array($this, "networkwide_choice_notice"), 20, 0);
  33. add_action('network_admin_menu', array( &$this, 'add_multisite_menu' ) );
  34. add_action('network_admin_edit_rsssl_update_network_settings', array($this,'update_network_options'));
  35. if (is_network_admin()) {
  36. add_action('network_admin_notices', array($this, 'show_notices'), 10);
  37. add_action('admin_print_footer_scripts', array($this, 'insert_dismiss_success'));
  38. }
  39. add_action('wp_ajax_dismiss_success_message_multisite', array($this,'dismiss_success_message_callback') );
  40. add_action('wp_ajax_rsssl_pro_dismiss_pro_option_notice', array($this,'dismiss_pro_option_notice') );
  41. add_action("network_admin_notices", array($this, 'show_pro_option_notice'));
  42. add_action("rsssl_show_network_tab_settings", array($this, 'settings_tab'));
  43. add_action( 'wpmu_new_blog', array($this, 'maybe_activate_ssl_in_new_blog'), 10, 6 );
  44. }
  45. static function this() {
  46. return self::$_this;
  47. }
  48. /*
  49. When a new site is added, maybe activate SSL as well.
  50. */
  51. public function maybe_activate_ssl_in_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
  52. if ($this->ssl_enabled_networkwide) {
  53. $site = get_blog_details($blog_id);
  54. $this->switch_to_blog_bw_compatible($site);
  55. RSSSL()->really_simple_ssl->activate_ssl();
  56. restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
  57. }
  58. }
  59. public function networkwide_choice_notice(){
  60. if ($this->plugin_network_wide_active() && !$this->selected_networkwide_or_per_site) {
  61. add_action('network_admin_notices', array($this, 'show_notice_activate_networkwide'), 10);
  62. }
  63. }
  64. public function load_options(){
  65. $options = get_site_option('rlrsssl_network_options');
  66. $this->selected_networkwide_or_per_site = isset($options["selected_networkwide_or_per_site"]) ? $options["selected_networkwide_or_per_site"] : false;
  67. $this->ssl_enabled_networkwide = isset($options["ssl_enabled_networkwide"]) ? $options["ssl_enabled_networkwide"] : false;
  68. $this->wp_redirect = isset($options["wp_redirect"]) ? $options["wp_redirect"] : false;
  69. $this->htaccess_redirect = isset($options["htaccess_redirect"]) ? $options["htaccess_redirect"] : false;
  70. $this->do_not_edit_htaccess = isset($options["do_not_edit_htaccess"]) ? $options["do_not_edit_htaccess"] : false;
  71. $this->autoreplace_mixed_content = isset($options["autoreplace_mixed_content"]) ? $options["autoreplace_mixed_content"] : false;
  72. $this->javascript_redirect = isset($options["javascript_redirect"]) ? $options["javascript_redirect"] : false;
  73. $this->hsts = isset($options["hsts"]) ? $options["hsts"] : false;
  74. $this->mixed_content_admin = isset($options["mixed_content_admin"]) ? $options["mixed_content_admin"] : false;
  75. $this->cert_expiration_warning = isset($options["cert_expiration_warning"]) ? $options["cert_expiration_warning"] : false;
  76. $this->hide_menu_for_subsites = isset($options["hide_menu_for_subsites"]) ? $options["hide_menu_for_subsites"] : false;
  77. }
  78. /**
  79. * On plugin activation, we can check if it is networkwide or not.
  80. *
  81. * @since 2.1
  82. *
  83. * @access public
  84. *
  85. */
  86. public function activate($networkwide) {
  87. //if networkwide, we ask, if not, we set it as selected.
  88. if (!$networkwide) {
  89. $this->selected_networkwide_or_per_site = true;
  90. $this->ssl_enabled_networkwide = false;
  91. $this->save_options();
  92. }
  93. }
  94. /*
  95. Add network menu for SSL
  96. Only when plugin is network activated.
  97. */
  98. public function add_multisite_menu(){
  99. if (!$this->plugin_network_wide_active()) return;
  100. register_setting( $this->option_group, 'rsssl_options');
  101. add_settings_section('rsssl_network_settings', __("Settings","really-simple-ssl"), array($this,'section_text'), $this->page_slug);
  102. //if (RSSSL()->really_simple_ssl->site_has_ssl) {
  103. add_settings_field('id_ssl_enabled_networkwide', __("Enable SSL", "really-simple-ssl"), array($this,'get_option_enable_multisite'), $this->page_slug, 'rsssl_network_settings');
  104. //if ($this->selected_networkwide_or_per_site) {
  105. RSSSL()->rsssl_network_admin_page = add_submenu_page('settings.php', "SSL", "SSL", 'manage_options', $this->page_slug, array( &$this, 'multisite_menu_page' ) );
  106. //}
  107. // }
  108. }
  109. /*
  110. Shows the content of the multisite menu page
  111. */
  112. public function section_text(){
  113. if (!RSSSL()->really_simple_ssl->site_has_ssl) {
  114. ?>
  115. <p>
  116. <?php _e("No SSL was detected. If you do have an SSL certificate, try to reload this page over https by clicking this link:","really-simple-ssl");?>&nbsp;<a href="<?php echo $current_url?>"><?php _e("reload over https.","really-simple-ssl");?></a>
  117. <?php _e("You can check your certificate on","really-simple-ssl");?>&nbsp;<a target="_blank" href="https://www.ssllabs.com/ssltest/">Qualys SSL Labs</a>
  118. </p>
  119. <?php
  120. } else {
  121. _e("Below you can set the multisite options for Really Simple SSL","really-simple-ssl");
  122. }
  123. }
  124. public function get_option_enable_multisite(){
  125. ?>
  126. <select name="rlrsssl_network_options[ssl_enabled_networkwide]">
  127. <?php if (!$this->selected_networkwide_or_per_site) {?>
  128. <option value="-1" <?php if (!$this->selected_networkwide_or_per_site) echo "selected";?>><?php _e("No selection was made", "really-simple-ssl")?>
  129. <?php }?>
  130. <option value="1" <?php if ($this->ssl_enabled_networkwide) echo "selected";?>><?php _e("networkwide", "really-simple-ssl")?>
  131. <option value="0" <?php if (!$this->ssl_enabled_networkwide) echo "selected";?>><?php _e("per site", "really-simple-ssl")?>
  132. </select>
  133. <?php
  134. //echo '<input id="rlrsssl_options" name="rlrsssl_network_options[ssl_enabled_networkwide]" size="40" type="checkbox" value="1"' . checked( 1, $this->ssl_enabled_networkwide, false ) ." />";
  135. rsssl_help::this()->get_help_tip(__("Select to enable SSL networkwide or per site.", "really-simple-ssl"));
  136. }
  137. /**
  138. * Displays the options page. The big difference here is where you post the data
  139. * because, unlike for normal option pages, there is nowhere to process it by
  140. * default so we have to create our own hook to process the saving of our options.
  141. */
  142. public function multisite_menu_page() {
  143. $tab = "settings";
  144. if ( isset ( $_GET['tab'] ) ) $tab = $_GET['tab'];
  145. $this->admin_tabs($tab);
  146. do_action("rsssl_show_network_tab_{$tab}");
  147. }
  148. public function settings_tab(){
  149. if (isset($_GET['updated'])): ?>
  150. <div id="message" class="updated notice is-dismissible"><p><?php _e('Options saved.', 'really-simple-ssl') ?></p></div>
  151. <?php endif; ?>
  152. <div class="wrap">
  153. <h1><?php _e('Really Simple SSL multisite options', 'really-simple-ssl'); ?></h1>
  154. <form method="POST" action="edit.php?action=rsssl_update_network_settings">
  155. <?php
  156. settings_fields($this->option_group);
  157. do_settings_sections($this->page_slug);
  158. submit_button();
  159. ?>
  160. </form>
  161. </div>
  162. <?php
  163. }
  164. /**
  165. * Save network settings
  166. */
  167. public function update_network_options() {
  168. check_admin_referer($this->option_group.'-options');
  169. if (isset($_POST["rlrsssl_network_options"])) {
  170. $prev_ssl_enabled_networkwide = $this->ssl_enabled_networkwide;
  171. $options = array_map(array($this, "sanitize_boolean"), $_POST["rlrsssl_network_options"]);
  172. $options["selected_networkwide_or_per_site"] = true;
  173. $this->ssl_enabled_networkwide = isset($options["ssl_enabled_networkwide"]) ? $options["ssl_enabled_networkwide"] : false;
  174. $this->wp_redirect = isset($options["wp_redirect"]) ? $options["wp_redirect"] : false;
  175. $this->htaccess_redirect = isset($options["htaccess_redirect"]) ? $options["htaccess_redirect"] : false;
  176. $this->do_not_edit_htaccess = isset($options["do_not_edit_htaccess"]) ? $options["do_not_edit_htaccess"] : false;
  177. $this->autoreplace_mixed_content = isset($options["autoreplace_mixed_content"]) ? $options["autoreplace_mixed_content"] : false;
  178. $this->javascript_redirect = isset($options["javascript_redirect"]) ? $options["javascript_redirect"] : false;
  179. $this->hsts = isset($options["hsts"]) ? $options["hsts"] : false;
  180. $this->mixed_content_admin = isset($options["mixed_content_admin"]) ? $options["mixed_content_admin"] : false;
  181. $this->cert_expiration_warning = isset($options["cert_expiration_warning"]) ? $options["cert_expiration_warning"] : false;
  182. $this->hide_menu_for_subsites = isset($options["hide_menu_for_subsites"]) ? $options["hide_menu_for_subsites"] : false;
  183. $this->selected_networkwide_or_per_site = isset($options["selected_networkwide_or_per_site"]) ? $options["selected_networkwide_or_per_site"] : false;
  184. }
  185. $this->save_options();
  186. if ($this->ssl_enabled_networkwide) {
  187. //enable SSL on all sites on the network
  188. $this->activate_ssl_networkwide();
  189. } elseif ($prev_ssl_enabled_networkwide!=$this->ssl_enabled_networkwide) {
  190. //if we switch to per page, we deactivate SSL on all pages first, but only if the setting was changed.
  191. $sites = $this->get_sites_bw_compatible();
  192. foreach ( $sites as $site ) {
  193. $this->switch_to_blog_bw_compatible($site);
  194. RSSSL()->really_simple_ssl->deactivate_ssl();
  195. restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
  196. }
  197. }
  198. // At last we redirect back to our options page.
  199. wp_redirect(add_query_arg(array('page' => $this->page_slug, 'updated' => 'true'), network_admin_url('settings.php')));
  200. exit;
  201. }
  202. public function sanitize_boolean($value)
  203. {
  204. if ($value == true) {
  205. return true;
  206. } else {
  207. return false;
  208. }
  209. }
  210. /**
  211. * Give the user an option to activate network wide or not.
  212. * Needs to be called after detect_configuration function
  213. *
  214. * @since 2.3
  215. *
  216. * @access public
  217. *
  218. */
  219. public function show_notice_activate_networkwide(){
  220. //if no SSL was detected, don't activate it yet.
  221. if (!RSSSL()->really_simple_ssl->site_has_ssl) {
  222. global $wp;
  223. $current_url = "https://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]
  224. ?>
  225. <div id="message" class="error fade notice activate-ssl">
  226. <p><?php _e("No SSL was detected. If you do have an SSL certificate, try to reload this page over https by clicking this link:","really-simple-ssl");?>&nbsp;<a href="<?php echo $current_url?>"><?php _e("reload over https.","really-simple-ssl");?></a>
  227. <?php _e("You can check your certificate on","really-simple-ssl");?>&nbsp;<a target="_blank" href="https://www.ssllabs.com/ssltest/">Qualys SSL Labs</a>
  228. </p>
  229. </div>
  230. <?php } ?>
  231. <?php if (RSSSL()->really_simple_ssl->site_has_ssl) {
  232. if (is_main_site(get_current_blog_id()) && RSSSL()->really_simple_ssl->wpconfig_ok()) {
  233. ?>
  234. <div id="message" class="updated fade notice activate-ssl">
  235. <h1><?php _e("Choose your preferred setup","really-simple-ssl");?></h1>
  236. <?php _e("Some things can't be done automatically. Before you migrate, please check for: ",'really-simple-ssl');?>
  237. <p>
  238. <ul>
  239. <li><?php _e('Http references in your .css and .js files: change any http:// into //','really-simple-ssl');?></li>
  240. <li><?php _e('Images, stylesheets or scripts from a domain without an SSL certificate: remove them or move to your own server.','really-simple-ssl');?></li>
  241. </ul>
  242. </p>
  243. <?php $this->show_pro(); ?>
  244. <p>
  245. <form action="" method="post">
  246. <?php wp_nonce_field( 'rsssl_nonce', 'rsssl_nonce' );?>
  247. <input type="submit" class='button button-primary' value="<?php _e("Activate SSL networkwide","really-simple-ssl");?>" id="rsssl_do_activate_ssl_networkwide" name="rsssl_do_activate_ssl_networkwide">
  248. <input type="submit" class='button button-primary' value="<?php _e("Activate SSL per site","really-simple-ssl");?>" id="rsssl_do_activate_ssl_per_site" name="rsssl_do_activate_ssl_per_site">
  249. </form>
  250. </p>
  251. <p>
  252. <?php _e("Networkwide activation does not check if a site has an SSL certificate. It just migrates all sites to SSL.","really-simple-ssl");?>
  253. </p>
  254. </div>
  255. <?php
  256. }
  257. }
  258. }
  259. /**
  260. * @since 2.3
  261. * Shows option to buy pro
  262. */
  263. public function show_pro(){
  264. ?>
  265. <p><?php _e('You can also let the automatic scan of the pro version handle this for you, and get premium support and increased security with HSTS included.','really-simple-ssl');?>&nbsp;<a target="_blank" href="<?php echo $this->pro_url;?>"><?php _e("Check out Really Simple SSL Premium","really-simple-ssl");?></a></p>
  266. <?php
  267. }
  268. /*
  269. Check if the plugin is network activated.
  270. */
  271. public function plugin_network_wide_active(){
  272. if ( ! function_exists( 'is_plugin_active_for_network' ) )
  273. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  274. if ( is_plugin_active_for_network(rsssl_plugin) ){
  275. return true;
  276. } else {
  277. return false;
  278. }
  279. }
  280. public function process_networkwide_choice(){
  281. if (!$this->plugin_network_wide_active()) return;
  282. if ( isset($_POST['rsssl_do_activate_ssl_networkwide'])) {
  283. $this->selected_networkwide_or_per_site = true;
  284. $this->ssl_enabled_networkwide = true;
  285. $this->wp_redirect = true;
  286. $this->save_options();
  287. //enable SSL on all sites on the network
  288. $this->activate_ssl_networkwide();
  289. }
  290. if (isset($_POST['rsssl_do_activate_ssl_per_site'])) {
  291. $this->selected_networkwide_or_per_site = true;
  292. $this->ssl_enabled_networkwide = false;
  293. $this->save_options();
  294. }
  295. }
  296. public function save_options(){
  297. $options = get_site_option("rlrsssl_network_options");
  298. if (!is_array($options)) $options = array();
  299. $options["selected_networkwide_or_per_site"] = $this->selected_networkwide_or_per_site;
  300. $options["ssl_enabled_networkwide"] = $this->ssl_enabled_networkwide;
  301. $options["wp_redirect"] = $this->wp_redirect;
  302. $options["htaccess_redirect"] = $this->htaccess_redirect;
  303. $options["do_not_edit_htaccess"] = $this->do_not_edit_htaccess;
  304. $options["autoreplace_mixed_content"] = $this->autoreplace_mixed_content;
  305. $options["javascript_redirect"] = $this->javascript_redirect;
  306. $options["hsts"] = $this->hsts;
  307. $options["mixed_content_admin"] = $this->mixed_content_admin;
  308. $options["cert_expiration_warning"] = $this->cert_expiration_warning;
  309. $options["hide_menu_for_subsites"] = $this->hide_menu_for_subsites;
  310. update_site_option("rlrsssl_network_options", $options);
  311. }
  312. public function activate_ssl_networkwide(){
  313. //set all sites as enabled
  314. $sites = $this->get_sites_bw_compatible();
  315. foreach ( $sites as $site ) {
  316. $this->switch_to_blog_bw_compatible($site);
  317. RSSSL()->really_simple_ssl->activate_ssl();
  318. restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
  319. }
  320. }
  321. //change deprecated function depending on version.
  322. public function get_sites_bw_compatible(){
  323. global $wp_version;
  324. $sites = ($wp_version >= 4.6 ) ? get_sites() : wp_get_sites();
  325. return $sites;
  326. }
  327. /*
  328. The new get_sites function returns an object.
  329. */
  330. public function switch_to_blog_bw_compatible($site){
  331. global $wp_version;
  332. if ($wp_version >= 4.6 ) {
  333. switch_to_blog( $site->blog_id );
  334. } else {
  335. switch_to_blog( $site[ 'blog_id' ] );
  336. }
  337. }
  338. public function deactivate(){
  339. $options = get_site_option("rlrsssl_network_options");
  340. $options["selected_networkwide_or_per_site"] = false;
  341. $options["wp_redirect"] = false;
  342. $options["htaccess_redirect"] = false;
  343. $options["do_not_edit_htaccess"] = false;
  344. $options["autoreplace_mixed_content"] = false;
  345. $options["javascript_redirect"] = false;
  346. $options["hsts"] = false;
  347. $options["mixed_content_admin"] = false;
  348. $options["cert_expiration_warning"] = false;
  349. $options["hide_menu_for_subsites"] = false;
  350. unset($options["ssl_enabled_networkwide"]);
  351. update_site_option("rlrsssl_network_options", $options);
  352. $sites = $this->get_sites_bw_compatible();
  353. foreach ( $sites as $site ) {
  354. $this->switch_to_blog_bw_compatible($site);
  355. RSSSL()->really_simple_ssl->deactivate_ssl();
  356. restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
  357. }
  358. }
  359. /**
  360. * filters the get_admin_url function to correct the false https urls wordpress returns for non SSL websites.
  361. *
  362. * @since 2.3.10
  363. *
  364. */
  365. public function check_admin_protocol($url, $path, $blog_id){
  366. if (!$blog_id) $blog_id = get_current_blog_id();
  367. //if the force_ssl_admin is defined, the admin_url should not be forced back to http: all admin panels should be https.
  368. if (defined('FORCE_SSL_ADMIN')) return $url;
  369. //do not force to http if the request is made for an url of the current blog.
  370. //if a site is loaded over https, it should return https links, unless the url is requested for another blog.
  371. //In that case, we only return a https link if the site_url is https, and http otherwise.
  372. if (get_current_blog_id()==$blog_id) return $url;
  373. //now check if the blog is http or https, and change the url accordingly
  374. if (!$this->ssl_enabled_networkwide) {
  375. $home_url = get_blog_option($blog_id, 'home');
  376. if (strpos($home_url, "https://")===false) {
  377. $url = str_replace("https://","http://",$url);
  378. }
  379. }
  380. return $url;
  381. }
  382. /**
  383. * filters the home_url and/or site_url function to correct the false https urls wordpress returns for non SSL websites.
  384. *
  385. * @since 2.3.17
  386. *
  387. */
  388. public function check_site_protocol($url, $path, $orig_scheme, $blog_id){
  389. if (!$blog_id) $blog_id = get_current_blog_id();
  390. if (get_current_blog_id()==$blog_id) return $url;
  391. if (!$this->ssl_enabled_networkwide) {
  392. $home_url = get_blog_option($blog_id, 'home');
  393. if (strpos($home_url, "https://")===false) {
  394. $url = str_replace("https://","http://",$url);
  395. }
  396. }
  397. return $url;
  398. }
  399. /*
  400. * Checks if we are on a subfolder install. (domain.com/site1 )
  401. *
  402. * @since 2.2
  403. *
  404. * @access public
  405. *
  406. **/
  407. public function is_multisite_subfolder_install() {
  408. if (!is_multisite()) return FALSE;
  409. //we check this manually, as the SUBDOMAIN_INSTALL constant of wordpress might return false for domain mapping configs
  410. $is_subfolder = FALSE;
  411. $sites = $this->get_sites_bw_compatible();
  412. foreach ( $sites as $site ) {
  413. $this->switch_to_blog_bw_compatible($site);
  414. if ($this->is_subfolder(home_url())) {
  415. $is_subfolder=TRUE;
  416. }
  417. restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
  418. if ($is_subfolder) return true;
  419. }
  420. return $is_subfolder;
  421. }
  422. /**
  423. * Test if a domain has a subfolder structure
  424. *
  425. * @since 2.2
  426. *
  427. * @param string $domain
  428. *
  429. * @access private
  430. *
  431. */
  432. public function is_subfolder($domain) {
  433. //remove slashes of the http(s)
  434. $domain = preg_replace("/(http:\/\/|https:\/\/)/","",$domain);
  435. if (strpos($domain,"/")!==FALSE) {
  436. return true;
  437. }
  438. return false;
  439. }
  440. public function is_per_site_activated_multisite_subfolder_install() {
  441. if (is_multisite() && $this->is_multisite_subfolder_install() && !$this->ssl_enabled_networkwide){
  442. return true;
  443. }
  444. return false;
  445. }
  446. /**
  447. * Show notices
  448. *
  449. * @since 2.0
  450. *
  451. * @access public
  452. *
  453. */
  454. public function show_notices()
  455. {
  456. if (isset(RSSSL()->really_simple_ssl->errors["DEACTIVATE_FILE_NOT_RENAMED"])) {
  457. ?>
  458. <div id="message" class="error fade notice is-dismissible rlrsssl-fail">
  459. <h1>
  460. <?php _e("Major security issue!","really-simple-ssl");?>
  461. </h1>
  462. <p>
  463. <?php _e("The 'force-deactivate.php' file has to be renamed to .txt. Otherwise your ssl can be deactived by anyone on the internet.","really-simple-ssl");?>
  464. </p>
  465. <a href="options-general.php?page=rlrsssl_really_simple_ssl"><?php echo __("Check again","really-simple-ssl");?></a>
  466. </div>
  467. <?php
  468. }
  469. /*
  470. SSL success message
  471. */
  472. if ($this->selected_networkwide_or_per_site && !get_site_option("rsssl_success_message_shown")) {
  473. ?>
  474. <div id="message" class="updated fade notice is-dismissible rlrsssl-multisite-success">
  475. <p>
  476. <?php _e("SSL activated!","really-simple-ssl");?>&nbsp;
  477. <?php
  478. if ($this->ssl_enabled_networkwide)
  479. _e("SSL was activated on your entire network.", "really-simple-ssl");
  480. else
  481. _e("SSL was activated per site.", "really-simple-ssl");
  482. ?>
  483. <?php _e("Don't forget to change your settings in Google Analytics and Webmaster tools.","really-simple-ssl");?>&nbsp;
  484. <a target="_blank" href="https://really-simple-ssl.com/knowledge-base/how-to-setup-google-analytics-and-google-search-consolewebmaster-tools/"><?php _e("More info.","really-simple-ssl");?></a>
  485. </p>
  486. </div>
  487. <?php
  488. }
  489. if (!$this->ssl_enabled_networkwide && $this->selected_networkwide_or_per_site && $this->is_multisite_subfolder_install()) {
  490. //with no server variables, the website could get into a redirect loop.
  491. if (RSSSL()->really_simple_ssl->no_server_variable) {
  492. ?>
  493. <div id="message" class="error fade notice">
  494. <p>
  495. <?php _e('You run a Multisite installation with subfolders, which prevents this plugin from fixing your missing server variable in the wp-config.php.','really-simple-ssl');?>
  496. <?php _e('Because the $_SERVER["HTTPS"] variable is not set, your website may experience redirect loops.','really-simple-ssl');?>
  497. <?php _e('Activate networkwide to fix this.','really-simple-ssl');?>
  498. </p>
  499. </div>
  500. <?php
  501. }
  502. }
  503. }
  504. /**
  505. * Insert some ajax script to dismis the SSL success message, and stop nagging about it
  506. *
  507. * @since 2.0
  508. *
  509. * @access public
  510. *
  511. */
  512. public function insert_dismiss_success() {
  513. if ($this->selected_networkwide_or_per_site && !get_site_option("rsssl_success_message_shown")) {
  514. $ajax_nonce = wp_create_nonce( "really-simple-ssl-dismiss" );
  515. ?>
  516. <script type='text/javascript'>
  517. jQuery(document).ready(function($) {
  518. $(".rlrsssl-multisite-success.notice.is-dismissible").on("click", ".notice-dismiss", function(event){
  519. var data = {
  520. 'action': 'dismiss_success_message_multisite',
  521. 'security': '<?php echo $ajax_nonce; ?>'
  522. };
  523. $.post(ajaxurl, data, function(response) {
  524. });
  525. });
  526. });
  527. </script>
  528. <?php
  529. }
  530. }
  531. /**
  532. * Process the ajax dismissal of the success message.
  533. *
  534. * @since 2.0
  535. *
  536. * @access public
  537. *
  538. */
  539. public function dismiss_success_message_callback() {
  540. //nonce check fails if url is changed to SSL.
  541. //check_ajax_referer( 'really-simple-ssl-dismiss', 'security' );
  542. update_site_option("rsssl_success_message_shown", true);
  543. wp_die();
  544. }
  545. public function dismiss_pro_option_notice() {
  546. check_ajax_referer( 'rsssl-pro-dismiss-pro-option-notice', 'nonce' );
  547. update_option( 'rsssl_pro_pro_option_notice_dismissed', true);
  548. wp_die();
  549. }
  550. public function dismiss_pro_option_script() {
  551. $ajax_nonce = wp_create_nonce( "rsssl-pro-dismiss-pro-option-notice" );
  552. ?>
  553. <script type='text/javascript'>
  554. jQuery(document).ready(function($) {
  555. $(".rsssl-pro-dismiss-notice.notice.is-dismissible").on("click", ".notice-dismiss", function(event){
  556. var data = {
  557. 'action': 'rsssl_pro_dismiss_pro_option_notice',
  558. 'nonce': '<?php echo $ajax_nonce; ?>'
  559. };
  560. $.post(ajaxurl, data, function(response) {
  561. });
  562. });
  563. });
  564. </script>
  565. <?php
  566. }
  567. public function show_pro_option_notice(){
  568. if (!$this->is_settings_page()) return;
  569. $dismissed = get_option( 'rsssl_pro_pro_option_notice_dismissed' );
  570. if (!$dismissed) {
  571. if (defined('rsssl_pro_version')) {
  572. if (!defined('rsssl_pro_ms_version')) {
  573. add_action('admin_print_footer_scripts', array($this, 'dismiss_pro_option_script'));
  574. ?>
  575. <div id="message" class="updated fade notice is-dismissible rsssl-pro-dismiss-notice">
  576. <p>
  577. <?php echo sprintf( __( 'You are running Really Simple SSL pro. A dedicated add-on for multisite has been released. If you want more options to have full control over your multisite network, you can ask for a discount code to %supgrade%s your license to a multisite license.', 'really-simple-ssl' ), '<a href="https://really-simple-ssl.com/contact" title="Really Simple SSL">', '</a>' )?>
  578. </p>
  579. </p></div>
  580. <?php
  581. }
  582. } else {
  583. ?>
  584. <div id="message" class="updated fade notice is-dismissible rsssl-pro-dismiss-notice">
  585. <p>
  586. <?php echo sprintf( __( 'If you want more options to have full control over your multisite network, you can %supgrade%s your license to a multisite license, or dismiss this message', 'really-simple-ssl' ), '<a href="https://really-simple-ssl.com/pro-multisite" title="Really Simple SSL">', '</a>' )?>
  587. </p>
  588. </p></div>
  589. <?php
  590. }
  591. }
  592. }
  593. public function is_settings_page(){
  594. return ( isset( $_GET['page'] ) && $_GET['page'] == 'really-simple-ssl' ) ? true : false;
  595. }
  596. /**
  597. * Create tabs on the settings page
  598. *
  599. * @since 1.0.0
  600. *
  601. * @access public
  602. *
  603. */
  604. public function admin_tabs( $current = 'settings' ) {
  605. $tabs = array(
  606. 'settings'=>__("Settings","really-simple-ssl"),
  607. );
  608. $tabs = apply_filters("rsssl_network_tabs", $tabs);
  609. if (count($tabs)>1) {
  610. echo '<h2 class="nav-tab-wrapper">';
  611. foreach( $tabs as $tab => $name ){
  612. $class = ( $tab == $current ) ? ' nav-tab-active' : '';
  613. echo "<a class='nav-tab$class' href='?page=really-simple-ssl&tab=$tab'>$name</a>";
  614. }
  615. echo '</h2>';
  616. }
  617. }
  618. } //class closure
  619. }