Feature #2 Hook CleanUp job to Statify cron action
This commit is contained in:
parent
0c9e63b7ee
commit
f8ab4214de
@ -52,8 +52,10 @@ class StatifyBlacklist {
|
|||||||
/* Get multisite status */
|
/* Get multisite status */
|
||||||
self::$multisite = ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) );
|
self::$multisite = ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) );
|
||||||
|
|
||||||
/* Add Filter to statify hook */
|
/* Add Filter to statify hook if enabled */
|
||||||
add_filter( 'statify_skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) );
|
if ( self::$_options['active_referer'] != 1 ) {
|
||||||
|
add_filter( 'statify_skip_tracking', array( 'StatifyBlacklist', 'apply_blacklist_filter' ) );
|
||||||
|
}
|
||||||
|
|
||||||
/* Admin only filters */
|
/* Admin only filters */
|
||||||
if ( is_admin() ) {
|
if ( is_admin() ) {
|
||||||
@ -76,6 +78,13 @@ class StatifyBlacklist {
|
|||||||
add_filter( 'plugin_action_links', array( 'StatifyBlacklist_Admin', 'plugin_actions_links' ), 10, 2 );
|
add_filter( 'plugin_action_links', array( 'StatifyBlacklist_Admin', 'plugin_actions_links' ), 10, 2 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* CronJob to clean up database */
|
||||||
|
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
||||||
|
if ( self::$_options['cron_referer'] == 1 ) {
|
||||||
|
add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,6 +99,7 @@ class StatifyBlacklist {
|
|||||||
get_option( 'statify-blacklist' ),
|
get_option( 'statify-blacklist' ),
|
||||||
array(
|
array(
|
||||||
'active_referer' => 0,
|
'active_referer' => 0,
|
||||||
|
'cron_referer' => 0,
|
||||||
'referer' => array()
|
'referer' => array()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -19,7 +19,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
|||||||
public static function update_options( $options = null ) {
|
public static function update_options( $options = null ) {
|
||||||
if ( isset( $options ) && current_user_can( 'manage_options' ) ) {
|
if ( isset( $options ) && current_user_can( 'manage_options' ) ) {
|
||||||
/* Sanitize URLs and remove empty inputs */
|
/* Sanitize URLs and remove empty inputs */
|
||||||
$givenReferer = $options['referer'];
|
$givenReferer = $options['referer'];
|
||||||
$sanitizedReferer = self::sanitizeURLs( $givenReferer );
|
$sanitizedReferer = self::sanitizeURLs( $givenReferer );
|
||||||
|
|
||||||
/* Abort on errors */
|
/* Abort on errors */
|
||||||
@ -110,11 +110,11 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
|
|||||||
* Filter database for cleanup.
|
* Filter database for cleanup.
|
||||||
*
|
*
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
* @changed 1.2.1
|
* @changed 1.2.0
|
||||||
*/
|
*/
|
||||||
public static function cleanup_database() {
|
public static function cleanup_database() {
|
||||||
/* Check user permissions */
|
/* Check user permissions */
|
||||||
if ( ! current_user_can( 'manage_options' ) ) {
|
if ( ! current_user_can( 'manage_options' ) && ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) {
|
||||||
die( _e( 'Are you sure you want to do this?' ) );
|
die( _e( 'Are you sure you want to do this?' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
$statifyBlacklistUpdateResult = StatifyBlacklist_Admin::update_options(
|
$statifyBlacklistUpdateResult = StatifyBlacklist_Admin::update_options(
|
||||||
array(
|
array(
|
||||||
'active_referer' => (int) @$_POST['statifyblacklist']['active_referer'],
|
'active_referer' => (int) @$_POST['statifyblacklist']['active_referer'],
|
||||||
|
'cron_referer' => (int) @$_POST['statifyblacklist']['cron_referer'],
|
||||||
'referer' => array_flip( $referer )
|
'referer' => array_flip( $referer )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -40,7 +41,6 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
@ -71,6 +71,13 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
<?php esc_html_e( 'Activate referer blacklist', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'Activate referer blacklist', 'statify-blacklist' ); ?>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<label for="statify-blacklist_cron_referer">
|
||||||
|
<input type="checkbox" name="statifyblacklist[cron_referer]" id="statifyblacklist_cron_referer"
|
||||||
|
value="1" <?php checked( StatifyBlacklist::$_options['cron_referer'], 1 ); ?> />
|
||||||
|
<?php esc_html_e( 'CronJob execution', 'statify-blacklist' ); ?>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_referer">
|
<label for="statify-blacklist_referer">
|
||||||
<?php esc_html_e( 'Referer blacklist:', 'statify-blacklist' ); ?><br/>
|
<?php esc_html_e( 'Referer blacklist:', 'statify-blacklist' ); ?><br/>
|
||||||
@ -80,7 +87,8 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
} else {
|
} else {
|
||||||
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer'] ) ) );
|
print esc_html( implode( "\r\n", array_keys( StatifyBlacklist::$_options['referer'] ) ) );
|
||||||
}
|
}
|
||||||
?></textarea><br/>
|
?></textarea>
|
||||||
|
<br />
|
||||||
<small>
|
<small>
|
||||||
(<?php esc_html_e( 'Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist' ); ?>
|
(<?php esc_html_e( 'Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist' ); ?>
|
||||||
)
|
)
|
||||||
@ -92,11 +100,11 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
|
|||||||
|
|
||||||
<p class="submit">
|
<p class="submit">
|
||||||
<input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes' ) ?>">
|
<input class="button-primary" type="submit" name="submit" value="<?php _e( 'Save Changes' ) ?>">
|
||||||
<hr>
|
<hr />
|
||||||
<input class="button-secondary" type="submit" name="cleanUp"
|
<input class="button-secondary" type="submit" name="cleanUp"
|
||||||
value="<?php esc_html_e( 'CleanUp Database', 'statify-blacklist' ) ?>"
|
value="<?php esc_html_e( 'CleanUp Database', 'statify-blacklist' ) ?>"
|
||||||
onclick="return confirm('Do you really want to apply filters to database? This cannot be undone.');">
|
onclick="return confirm('Do you really want to apply filters to database? This cannot be undone.');">
|
||||||
<br>
|
<br />
|
||||||
<small><?php esc_html_e( 'Applies filter (even if disabled) to data stored in database. This cannot be undone!', 'statify-blacklist' ); ?></small>
|
<small><?php esc_html_e( 'Applies filter (even if disabled) to data stored in database. This cannot be undone!', 'statify-blacklist' ); ?></small>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user