Enhancement #1 Switched from in_array() to faster isset() for referer checking

This commit is contained in:
2016-08-21 19:21:22 +02:00
parent 1e0659e649
commit 19644dd62b
6 changed files with 62 additions and 23 deletions

View File

@ -28,7 +28,10 @@ class StatifyBlacklist_System extends StatifyBlacklist {
switch_to_blog( $site_id );
add_option(
'statify-blacklist',
array()
array(
'activate-referer' => 0,
'referer' => array()
)
);
}
@ -36,7 +39,10 @@ class StatifyBlacklist_System extends StatifyBlacklist {
} else {
add_option(
'statify-blacklist',
array()
array(
'activate-referer' => 0,
'referer' => array()
)
);
}
}
@ -66,4 +72,28 @@ class StatifyBlacklist_System extends StatifyBlacklist {
delete_option( 'statify-blacklist' );
}
}
/**
* Upgrade plugin options.
*
* @param object $upgrader Upgrader object (unused)
* @param array $options Options array
*
* @since 1.2.0
*/
public static function upgrade() {
self::update_options();
/* Check if config array is not associative (pre 1.2.0) */
if ( array_keys( self::$_options['referer'] ) === range( 0, count( self::$_options['referer'] ) - 1 ) ) {
/* Flip referer array to make domains keys */
$options = self::$_options;
$options['referer'] = array_flip( self::$_options['referer'] );
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
update_site_option( 'statify-blacklist', $options );
} else {
update_option( 'statify-blacklist', $options );
}
}
}
}