Skip to content
Browse files

Fixed ajax settings saving.

  • Loading branch information...
1 parent 6d6069a commit b195144104fb2c3acd0ac0d4f7d2fa96bbdc8b1f @mvied committed
View
8 admin/templates/metabox/network.php
@@ -87,10 +87,12 @@
</form>
<script type="text/javascript">
jQuery(document).ready(function($) {
- $('#<?php echo $this->getPlugin()->getSlug(); ?>_network_settings_form').submit(function(e) {
+ var form = $('#<?php echo $this->getPlugin()->getSlug(); ?>_network_settings_form').first();
+ $('#network-settings-save').click(function() {
+ $(form).find('input[name="action"]').val('<?php echo $this->getPlugin()->getSlug(); ?>_network_settings_save');
+ });
+ $(form).submit(function(e) {
e.preventDefault();
- var form = this;
- $(form).find('input[name="action"]').val('<?php echo $this->getPlugin()->getSlug(); ?>_network_settings');
$(form).find('.submit-waiting').show();
$.post(ajaxurl, $(form).serialize(), function(response) {
$(form).find('.submit-waiting').hide();
View
11 admin/templates/metabox/settings.php
@@ -111,10 +111,15 @@
</form>
<script type="text/javascript">
jQuery(document).ready(function($) {
- $('#<?php echo $this->getPlugin()->getSlug(); ?>_settings_form').submit(function(e) {
+ var form = $('#<?php echo $this->getPlugin()->getSlug(); ?>_settings_form').first();
+ $('#settings-save').click(function() {
+ $(form).find('input[name="action"]').val('<?php echo $this->getPlugin()->getSlug(); ?>_settings_save');
+ });
+ $('#settings-reset').click(function() {
+ $(form).find('input[name="action"]').val('<?php echo $this->getPlugin()->getSlug(); ?>_settings_reset');
+ });
+ $(form).submit(function(e) {
e.preventDefault();
- var form = this;
- $(form).find('input[name="action"]').val('<?php echo $this->getPlugin()->getSlug(); ?>_settings');
$(form).find('.submit-waiting').show();
$.post(ajaxurl, $(form).serialize(), function(response) {
$(form).find('.submit-waiting').hide();
View
59 lib/WordPressHTTPS/Module/Network.php
@@ -19,7 +19,7 @@ class WordPressHTTPS_Module_Network extends Mvied_Plugin_Module {
*/
public function init() {
if ( is_admin() ) {
- add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_network_settings', array(&$this, 'save'));
+ add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_network_settings_save', array(&$this, 'save'));
if ( isset($_GET['page']) && strpos($_GET['page'], $this->getPlugin()->getSlug()) !== false && strpos($_SERVER['REQUEST_URI'], 'wp-admin/network') !== false ) {
// Add meta boxes
add_action('admin_init', array(&$this, 'add_meta_boxes'));
@@ -122,39 +122,38 @@ public function save() {
$errors = array();
$reload = false;
$logout = false;
- if ( isset($_POST['network-settings-save']) ) {
- if ( isset($_POST['blog']) && is_array($_POST['blog']) && sizeof($_POST['blog']) > 0 ) {
- foreach( $_POST['blog'] as $blog_id => $setting ) {
- foreach( $setting as $key => $value ) {
- if ( $key == 'ssl_host' && $value != '' ) {
- $blog_url = WordPressHTTPS_Url::fromString(get_site_url($blog_id, '', 'https'));
- $value = strtolower($value);
- // Add Scheme
- if ( strpos($value, 'http://') === false && strpos($value, 'https://') === false ) {
- $value = 'https://' . $value;
- }
-
- $ssl_host = WordPressHTTPS_Url::fromString($value);
-
- // Add Port
- $port = (($blog_url->getPort() && $blog_url->getPort() != 80 && $blog_url->getPort() != 443) ? $port : null);
- $ssl_host->setPort($port);
-
- // Add Path
- if ( strpos($ssl_host->getPath(), $blog_url->getPath()) !== true ) {
- $path = '/'. ltrim(str_replace(rtrim($blog_url->getPath(), '/'), '', $ssl_host->getPath()), '/');
- $ssl_host->setPath(rtrim($path, '/') . $blog_url->getPath());
- }
- $ssl_host->setPath(rtrim($ssl_host->getPath(), '/') . '/');
- $value = $ssl_host->toString();
+
+ if ( isset($_POST['blog']) && is_array($_POST['blog']) && sizeof($_POST['blog']) > 0 ) {
+ foreach( $_POST['blog'] as $blog_id => $setting ) {
+ foreach( $setting as $key => $value ) {
+ if ( $key == 'ssl_host' && $value != '' ) {
+ $blog_url = WordPressHTTPS_Url::fromString(get_site_url($blog_id, '', 'https'));
+ $value = strtolower($value);
+ // Add Scheme
+ if ( strpos($value, 'http://') === false && strpos($value, 'https://') === false ) {
+ $value = 'https://' . $value;
}
- $this->getPlugin()->setSetting($key, $value, $blog_id);
+
+ $ssl_host = WordPressHTTPS_Url::fromString($value);
+
+ // Add Port
+ $port = (($blog_url->getPort() && $blog_url->getPort() != 80 && $blog_url->getPort() != 443) ? $port : null);
+ $ssl_host->setPort($port);
+
+ // Add Path
+ if ( strpos($ssl_host->getPath(), $blog_url->getPath()) !== true ) {
+ $path = '/'. ltrim(str_replace(rtrim($blog_url->getPath(), '/'), '', $ssl_host->getPath()), '/');
+ $ssl_host->setPath(rtrim($path, '/') . $blog_url->getPath());
+ }
+ $ssl_host->setPath(rtrim($ssl_host->getPath(), '/') . '/');
+ $value = $ssl_host->toString();
}
+ $this->getPlugin()->setSetting($key, $value, $blog_id);
}
}
- if ( isset($_POST['blog_default']) && is_array($_POST['blog_default']) && sizeof($_POST['blog_default']) > 0 ) {
- $this->getPlugin()->setSetting('network_defaults', $_POST['blog_default']);
- }
+ }
+ if ( isset($_POST['blog_default']) && is_array($_POST['blog_default']) && sizeof($_POST['blog_default']) > 0 ) {
+ $this->getPlugin()->setSetting('network_defaults', $_POST['blog_default']);
}
if ( $logout ) {
View
156 lib/WordPressHTTPS/Module/Settings.php
@@ -19,7 +19,8 @@ class WordPressHTTPS_Module_Settings extends Mvied_Plugin_Module {
*/
public function init() {
if ( is_admin() ) {
- add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_settings', array(&$this, 'save'));
+ add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_settings_save', array(&$this, 'save'));
+ add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_settings_reset', array(&$this, 'reset'));
add_action('wp_ajax_' . $this->getPlugin()->getSlug() . '_ajax_metabox', array(&$this, 'ajax_metabox'));
if ( isset($_GET['page']) && strpos($_GET['page'], $this->getPlugin()->getSlug()) !== false ) {
// Add meta boxes
@@ -182,11 +183,35 @@ public function admin_enqueue_scripts() {
public function render() {
require_once($this->getPlugin()->getDirectory() . '/admin/templates/settings.php');
}
+
+ /**
+ * Reset Settings
+ *
+ * @param none
+ * @return void
+ */
+ public function reset() {
+ if ( !wp_verify_nonce($_POST['_wpnonce'], $this->getPlugin()->getSlug() . '-options') ) {
+ return false;
+ }
+
+ $message = "Settings reset.";
+ $errors = array();
+ $reload = true;
+ $logout = false;
+
+ foreach ($this->getPlugin()->getSettings() as $key => $default) {
+ $this->getPlugin()->setSetting($key, $default);
+ }
+ $this->getPlugin()->install();
+
+ require_once($this->getPlugin()->getDirectory() . '/admin/templates/ajax_message.php');
+ }
/**
* Save Settings
*
- * @param array $settings
+ * @param none
* @return void
*/
public function save() {
@@ -198,85 +223,78 @@ public function save() {
$errors = array();
$reload = false;
$logout = false;
- if ( isset($_POST['settings-save']) ) {
- foreach ($this->getPlugin()->getSettings() as $key => $default) {
- if ( !array_key_exists($key, $_POST) && $default == 0 ) {
- $_POST[$key] = 0;
- $this->getPlugin()->setSetting($key, $_POST[$key]);
- } else if ( array_key_exists($key, $_POST) ) {
- if ( $key == 'ssl_host' ) {
- if ( $_POST[$key] != '' ) {
- $_POST[$key] = strtolower($_POST[$key]);
- // Add Scheme
- if ( strpos($_POST[$key], 'http://') === false && strpos($_POST[$key], 'https://') === false ) {
- $_POST[$key] = 'https://' . $_POST[$key];
- }
- $ssl_host = WordPressHTTPS_Url::fromString($_POST[$key]);
+ foreach ($this->getPlugin()->getSettings() as $key => $default) {
+ if ( !array_key_exists($key, $_POST) && $default == 0 ) {
+ $_POST[$key] = 0;
+ $this->getPlugin()->setSetting($key, $_POST[$key]);
+ } else if ( array_key_exists($key, $_POST) ) {
+ if ( $key == 'ssl_host' ) {
+ if ( $_POST[$key] != '' ) {
+ $_POST[$key] = strtolower($_POST[$key]);
+ // Add Scheme
+ if ( strpos($_POST[$key], 'http://') === false && strpos($_POST[$key], 'https://') === false ) {
+ $_POST[$key] = 'https://' . $_POST[$key];
+ }
- // Add Port
- $port = ((isset($_POST['ssl_port']) && is_int($_POST['ssl_port']) ) ? $_POST['ssl_port'] : $ssl_host->getPort());
- $port = (($port != 80 && $port != 443) ? $port : null);
- $ssl_host->setPort($port);
+ $ssl_host = WordPressHTTPS_Url::fromString($_POST[$key]);
- // Add Path
- if ( strpos($ssl_host->getPath(), $this->getPlugin()->getHttpUrl()->getPath()) !== true ) {
- $path = '/'. ltrim(str_replace(rtrim($this->getPlugin()->getHttpUrl()->getPath(), '/'), '', $ssl_host->getPath()), '/');
- $ssl_host->setPath(rtrim($path, '/') . $this->getPlugin()->getHttpUrl()->getPath());
- }
- $ssl_host->setPath(rtrim($ssl_host->getPath(), '/') . '/');
+ // Add Port
+ $port = ((isset($_POST['ssl_port']) && is_int($_POST['ssl_port']) ) ? $_POST['ssl_port'] : $ssl_host->getPort());
+ $port = ($port != 443 ? $port : null);
+ $ssl_host->setPort($port);
- if ( $ssl_host->toString() != $this->getPlugin()->getHttpsUrl()->toString() ) {
- // Ensure that the WordPress installation is accessible at this host
- //if ( $ssl_host->isValid() ) {
- // If secure domain has changed and currently on SSL, logout user
- if ( $this->getPlugin()->isSsl() ) {
- $logout = true;
- }
- $_POST[$key] = $ssl_host->setPort('')->toString();
- /*} else {
- $errors[] = '<strong>SSL Host</strong> - Invalid WordPress installation at ' . $ssl_host;
- $_POST[$key] = get_option($key);
- }*/
- } else {
- $_POST[$key] = $this->getPlugin()->getHttpsUrl()->toString();
- }
- } else {
- $_POST[$key] = get_option($key);
- }
- } else if ( $key == 'ssl_proxy' ) {
- // Reload if we're auto detecting the proxy and we're not in SSL
- if ( $_POST[$key] == 'auto' && ! $this->getPlugin()->isSsl() ) {
- $reload = true;
+ // Add Path
+ if ( strpos($ssl_host->getPath(), $this->getPlugin()->getHttpUrl()->getPath()) !== true ) {
+ $path = '/'. ltrim(str_replace(rtrim($this->getPlugin()->getHttpUrl()->getPath(), '/'), '', $ssl_host->getPath()), '/');
+ $ssl_host->setPath(rtrim($path, '/') . $this->getPlugin()->getHttpUrl()->getPath());
}
- } else if ( $key == 'ssl_admin' ) {
- if ( force_ssl_admin() && $this->getPlugin()->getSetting('ssl_host_diff') ) {
- $errors[] = '<strong>SSL Admin</strong> - FORCE_SSL_ADMIN should not be set to true in your wp-config.php while using a non-default SSL Host.';
- // If forcing SSL Admin and currently not SSL, logout user
- } else if ( $_POST[$key] == 1 && !$this->getPlugin()->isSsl() ) {
- $logout = true;
- }
- } else if ( $key == 'ssl_host_subdomain' ) {
- // Checks to see if the SSL Host is a subdomain
- $http_domain = $this->getPlugin()->getHttpUrl()->getBaseHost();
- $https_domain = $this->getPlugin()->getHttpsUrl()->getBaseHost();
+ $ssl_host->setPath(rtrim($ssl_host->getPath(), '/') . '/');
- if ( $ssl_host->setScheme('http') != $this->getPlugin()->getHttpUrl() && $http_domain == $https_domain ) {
- $_POST[$key] = 1;
+ if ( $ssl_host->toString() != $this->getPlugin()->getHttpsUrl()->toString() ) {
+ // Ensure that the WordPress installation is accessible at this host
+ //if ( $ssl_host->isValid() ) {
+ // If secure domain has changed and currently on SSL, logout user
+ if ( $this->getPlugin()->isSsl() ) {
+ $logout = true;
+ }
+ $_POST[$key] = $ssl_host->setPort('')->toString();
+ /*} else {
+ $errors[] = '<strong>SSL Host</strong> - Invalid WordPress installation at ' . $ssl_host;
+ $_POST[$key] = get_option($key);
+ }*/
} else {
- $_POST[$key] = 0;
+ $_POST[$key] = $this->getPlugin()->getHttpsUrl()->toString();
}
+ } else {
+ $_POST[$key] = get_option($key);
+ }
+ } else if ( $key == 'ssl_proxy' ) {
+ // Reload if we're auto detecting the proxy and we're not in SSL
+ if ( $_POST[$key] == 'auto' && ! $this->getPlugin()->isSsl() ) {
+ $reload = true;
+ }
+ } else if ( $key == 'ssl_admin' ) {
+ if ( force_ssl_admin() && $this->getPlugin()->getSetting('ssl_host_diff') ) {
+ $errors[] = '<strong>SSL Admin</strong> - FORCE_SSL_ADMIN should not be set to true in your wp-config.php while using a non-default SSL Host.';
+ // If forcing SSL Admin and currently not SSL, logout user
+ } else if ( $_POST[$key] == 1 && !$this->getPlugin()->isSsl() ) {
+ $logout = true;
}
+ } else if ( $key == 'ssl_host_subdomain' ) {
+ // Checks to see if the SSL Host is a subdomain
+ $http_domain = $this->getPlugin()->getHttpUrl()->getBaseHost();
+ $https_domain = $this->getPlugin()->getHttpsUrl()->getBaseHost();
- $this->getPlugin()->setSetting($key, $_POST[$key]);
+ if ( $ssl_host->setScheme('http') != $this->getPlugin()->getHttpUrl() && $http_domain == $https_domain ) {
+ $_POST[$key] = 1;
+ } else {
+ $_POST[$key] = 0;
+ }
}
+
+ $this->getPlugin()->setSetting($key, $_POST[$key]);
}
- } else if ( isset($_POST['settings-reset']) ) {
- foreach ($this->getPlugin()->getSettings() as $key => $default) {
- $this->getPlugin()->setSetting($key, $default);
- }
- $this->getPlugin()->install();
- $reload = true;
}
if ( $logout ) {

0 comments on commit b195144

Please sign in to comment.
Something went wrong with that request. Please try again.