', __('You are using WordPress version', $this->name), __('. WP Minify recommends that you use WordPress 2.7 or newer.', $this->name), __('Please update', $this->name));
}
// check WP Minify version
if ( $this->need_upgrade() ) {
// load text domain for translations
load_plugin_textdomain($this->name);
$this->upgrade_options();
printf('
%s
', __('WP Minify options has been upgraded.', $this->name));
}
}
function update_options() {
// new options
$wpm_new_options = stripslashes_deep($_POST['wpm_options_update']);
// current options
$wpm_current_options = get_option($this->name);
// convert "on" to true and "off" to false for checkbox fields
// and set defaults for fields that are left blank
if ( isset($wpm_new_options['show_link']) && $wpm_new_options['show_link'] == "on")
$wpm_new_options['show_link'] = true;
else
$wpm_new_options['show_link'] = false;
if ( isset($wpm_new_options['debug']) )
$wpm_new_options['debug'] = true;
else
$wpm_new_options['debug'] = false;
if ( strlen(trim($wpm_new_options['js_include'])) > 0 )
$wpm_new_options['js_include'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['js_include'])));
else
$wpm_new_options['js_include'] = array();
if ( strlen(trim($wpm_new_options['js_exclude'])) > 0 )
$wpm_new_options['js_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['js_exclude'])));
else
$wpm_new_options['js_exclude'] = array();
if ( strlen(trim($wpm_new_options['css_include'])) > 0 )
$wpm_new_options['css_include'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['css_include'])));
else
$wpm_new_options['css_include'] = array();
if ( strlen(trim($wpm_new_options['css_exclude'])) > 0 )
$wpm_new_options['css_exclude'] = $this->array_trim(split(chr(10), str_replace(chr(13), '', $wpm_new_options['css_exclude'])));
else
$wpm_new_options['css_exclude'] = array();
// Update options
foreach($wpm_new_options as $key => $value) {
$wpm_current_options[$key] = $value;
}
update_option($this->name, $wpm_current_options);
}
function upgrade_options() {
$wpm_options = get_option($this->name);
if ( !$wpm_options ) {
add_option($this->name, $this->get_default_options());
}
else {
$default_options = $this->get_default_options();
foreach($default_options as $option_name => $option_value) {
if(!isset($wpm_options[$option_name])) {
$wpm_options[$option_name] = $option_value;
}
}
$wpm_options['version'] = $this->version;
update_option($this->name, $wpm_options);
}
}
function reset_options() {
$wpm_options = get_option($this->name);
if ( !$wpm_options ) {
add_option($this->name, $this->get_default_options());
}
else {
// persists some options
$default_options = $this->get_default_options();
$default_options['widget_ids'] = $wpm_options['widget_ids'];
update_option($this->name, $default_options);
}
}
function get_content_dir() {
// Pre-2.6 compatibility
if ( !defined('WP_CONTENT_DIR') )
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
return WP_CONTENT_DIR;
}
function get_plugin_dir() {
// Pre-2.6 compatibility
return $this->get_content_dir().'/plugins/'.plugin_basename(dirname(__FILE__));
}
function get_plugin_url() {
// Pre-2.6 compatibility
if ( !defined('WP_CONTENT_URL') )
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
return WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__));
}
function get_current_page_url() {
$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
$port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : '';
$url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"];
return $url;
}
function admin_menu() {
add_options_page('WP Minify', 'WP Minify', 'manage_options', 'wp-minify', array($this, 'admin_page'));
}
function admin_page() {
// load text domain for translations
load_plugin_textdomain($this->name);
if ( isset($_POST['wpm_options_update_submit']) ) {
// if user wants to update options
check_admin_referer($this->name);
$this->update_options();
printf('
%s
', __('WP Minify options has been updated.', $this->name));
}
elseif ( isset($_POST['wpm_options_clear_cache_submit']) ) {
// if user wants to regenerate nonce
check_admin_referer($this->name);
$this->clear_cache();
printf('
%s
', __('WP Minify cache has been cleared.', $this->name));
}
elseif ( isset($_POST['wpm_options_upgrade_submit']) ) {
// if user wants to upgrade options ( for new options on version upgrades )
check_admin_referer($this->name);
$this->upgrade_options();
printf('
%s
', __('WP Minify options has been upgraded.', $this->name));
}
elseif ( isset($_POST['wpm_options_reset_submit']) ) {
// if user wants to reset all options
check_admin_referer($this->name);
$this->reset_options();
printf('
%s
', __('WP Minify options has been reset.', $this->name));
}
if ( !$this->cache_dir_writable() ) {
printf('
%s%s
', __('Cache directory is not writable. Please grant your server write permissions to the directory:', $this->name), $this->get_plugin_dir().'/cache/');
}
printf('