WP coding style
This commit is contained in:
parent
bff28ce85b
commit
1e0659e649
@ -8,8 +8,7 @@ defined('ABSPATH') OR exit;
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class StatifyBlacklist
|
class StatifyBlacklist {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Plugin options
|
* Plugin options
|
||||||
*
|
*
|
||||||
@ -31,8 +30,7 @@ class StatifyBlacklist
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function instance()
|
public static function instance() {
|
||||||
{
|
|
||||||
new self();
|
new self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +40,7 @@ class StatifyBlacklist
|
|||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @changed 1.1.2
|
* @changed 1.1.2
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct() {
|
||||||
{
|
|
||||||
/* Skip on autosave or AJAX */
|
/* Skip on autosave or AJAX */
|
||||||
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) OR ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) OR ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||||
return;
|
return;
|
||||||
@ -70,7 +67,10 @@ class StatifyBlacklist
|
|||||||
|
|
||||||
if ( is_multisite() ) {
|
if ( is_multisite() ) {
|
||||||
add_action( 'network_admin_menu', array( 'StatifyBlacklist_Admin', '_add_menu_page' ) );
|
add_action( 'network_admin_menu', array( 'StatifyBlacklist_Admin', '_add_menu_page' ) );
|
||||||
add_filter('network_admin_plugin_action_links', array('StatifyBlacklist_Admin', 'plugin_actions_links'), 10, 2);
|
add_filter( 'network_admin_plugin_action_links', array(
|
||||||
|
'StatifyBlacklist_Admin',
|
||||||
|
'plugin_actions_links'
|
||||||
|
), 10, 2 );
|
||||||
} else {
|
} else {
|
||||||
add_action( 'admin_menu', array( 'StatifyBlacklist_Admin', '_add_menu_page' ) );
|
add_action( 'admin_menu', array( 'StatifyBlacklist_Admin', '_add_menu_page' ) );
|
||||||
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 );
|
||||||
@ -110,15 +110,17 @@ class StatifyBlacklist
|
|||||||
/* Extract relevant domain parts */
|
/* Extract relevant domain parts */
|
||||||
$referer = strtolower( ( isset( $_SERVER['HTTP_REFERER'] ) ? parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) : '' ) );
|
$referer = strtolower( ( isset( $_SERVER['HTTP_REFERER'] ) ? parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ) : '' ) );
|
||||||
$referer = explode( '.', $referer );
|
$referer = explode( '.', $referer );
|
||||||
if( count($referer) >1 )
|
if ( count( $referer ) > 1 ) {
|
||||||
$referer = implode( '.', array_slice( $referer, - 2 ) );
|
$referer = implode( '.', array_slice( $referer, - 2 ) );
|
||||||
else
|
} else {
|
||||||
$referer = implode( '.', $referer );
|
$referer = implode( '.', $referer );
|
||||||
|
}
|
||||||
|
|
||||||
/* Get blacklist */
|
/* Get blacklist */
|
||||||
$blacklist = self::$_options['referer'];
|
$blacklist = self::$_options['referer'];
|
||||||
|
|
||||||
/* Check blacklist */
|
/* Check blacklist */
|
||||||
|
|
||||||
return in_array( $referer, $blacklist );
|
return in_array( $referer, $blacklist );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,7 @@ defined('ABSPATH') OR exit;
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class StatifyBlacklist_Admin extends StatifyBlacklist
|
class StatifyBlacklist_Admin extends StatifyBlacklist {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Update options
|
* Update options
|
||||||
*
|
*
|
||||||
@ -28,11 +27,12 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Update database on success */
|
/* Update database on success */
|
||||||
if ((is_multisite() && array_key_exists(STATIFYBLACKLIST_BASE, (array)get_site_option('active_sitewide_plugins'))))
|
if ( ( is_multisite() && array_key_exists( STATIFYBLACKLIST_BASE, (array) get_site_option( 'active_sitewide_plugins' ) ) ) ) {
|
||||||
update_site_option( 'statify-blacklist', $options );
|
update_site_option( 'statify-blacklist', $options );
|
||||||
else
|
} else {
|
||||||
update_option( 'statify-blacklist', $options );
|
update_option( 'statify-blacklist', $options );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Refresh options */
|
/* Refresh options */
|
||||||
parent::update_options();
|
parent::update_options();
|
||||||
@ -47,10 +47,17 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
*/
|
*/
|
||||||
public function _add_menu_page() {
|
public function _add_menu_page() {
|
||||||
$title = __( 'Statify Blacklist', 'statify-blacklist' );
|
$title = __( 'Statify Blacklist', 'statify-blacklist' );
|
||||||
if (self::$multisite)
|
if ( self::$multisite ) {
|
||||||
add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'statify-blacklist-settings', array('StatifyBlacklist_Admin', 'settings_page') );
|
add_submenu_page( 'settings.php', $title, $title, 'manage_network_plugins', 'statify-blacklist-settings', array(
|
||||||
else
|
'StatifyBlacklist_Admin',
|
||||||
add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'statify-blacklist', array('StatifyBlacklist_Admin', 'settings_page') );
|
'settings_page'
|
||||||
|
) );
|
||||||
|
} else {
|
||||||
|
add_submenu_page( 'options-general.php', $title, $title, 'manage_options', 'statify-blacklist', array(
|
||||||
|
'StatifyBlacklist_Admin',
|
||||||
|
'settings_page'
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +70,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
*
|
*
|
||||||
* @param $links
|
* @param $links
|
||||||
* @param $file
|
* @param $file
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
@ -71,6 +79,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
if ( $file == STATIFYBLACKLIST_BASE ) {
|
if ( $file == STATIFYBLACKLIST_BASE ) {
|
||||||
$links[] = '<a href="https://github.com/stklcode/statify-blacklist">GitHub</a>';
|
$links[] = '<a href="https://github.com/stklcode/statify-blacklist">GitHub</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +87,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
* Add plugin action links
|
* Add plugin action links
|
||||||
*
|
*
|
||||||
* @param array $input Registered links
|
* @param array $input Registered links
|
||||||
|
*
|
||||||
* @return array Merged links
|
* @return array Merged links
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
@ -91,6 +101,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
sprintf( '<a href="%s">%s</a>', esc_attr( add_query_arg( 'page', 'statify-blacklist', $base ) ), __( 'Settings' ) )
|
sprintf( '<a href="%s">%s</a>', esc_attr( add_query_arg( 'page', 'statify-blacklist', $base ) ), __( 'Settings' ) )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +113,9 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
*/
|
*/
|
||||||
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' ) ) {
|
||||||
die( _e( 'Are you sure you want to do this?' ) );
|
die( _e( 'Are you sure you want to do this?' ) );
|
||||||
|
}
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
@ -126,7 +138,9 @@ class StatifyBlacklist_Admin extends StatifyBlacklist
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize URLs and remove empty results
|
* Sanitize URLs and remove empty results
|
||||||
|
*
|
||||||
* @param $urls array given array of URLs
|
* @param $urls array given array of URLs
|
||||||
|
*
|
||||||
* @return array sanitized array
|
* @return array sanitized array
|
||||||
*
|
*
|
||||||
* @since 1.1.1
|
* @since 1.1.1
|
||||||
|
@ -8,8 +8,7 @@ defined('ABSPATH') OR exit;
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class StatifyBlacklist_System extends StatifyBlacklist
|
class StatifyBlacklist_System extends StatifyBlacklist {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Plugin install handler.
|
* Plugin install handler.
|
||||||
*
|
*
|
||||||
|
@ -33,6 +33,7 @@ spl_autoload_register('statifyBlacklist_autoload');
|
|||||||
* Autoloader for StatifyBlacklist classes.
|
* Autoloader for StatifyBlacklist classes.
|
||||||
*
|
*
|
||||||
* @param $class
|
* @param $class
|
||||||
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
function statifyBlacklist_autoload( $class ) {
|
function statifyBlacklist_autoload( $class ) {
|
||||||
|
@ -18,8 +18,11 @@ if ( !empty($_POST['statifyblacklist']) ) {
|
|||||||
StatifyBlacklist_Admin::cleanup_database();
|
StatifyBlacklist_Admin::cleanup_database();
|
||||||
} else {
|
} else {
|
||||||
/* Extract referer array */
|
/* Extract referer array */
|
||||||
if (empty(trim($_POST['statifyblacklist']['referer']))) $referer = array();
|
if ( empty( trim( $_POST['statifyblacklist']['referer'] ) ) ) {
|
||||||
else $referer = explode("\r\n", $_POST['statifyblacklist']['referer']);
|
$referer = array();
|
||||||
|
} else {
|
||||||
|
$referer = explode( "\r\n", $_POST['statifyblacklist']['referer'] );
|
||||||
|
}
|
||||||
|
|
||||||
/* Update options (data will be sanitized) */
|
/* Update options (data will be sanitized) */
|
||||||
$statifyBlacklistUpdateResult = StatifyBlacklist_Admin::update_options(
|
$statifyBlacklistUpdateResult = StatifyBlacklist_Admin::update_options(
|
||||||
@ -63,7 +66,8 @@ if ( !empty($_POST['statifyblacklist']) ) {
|
|||||||
<ul style="list-style: none;">
|
<ul style="list-style: none;">
|
||||||
<li>
|
<li>
|
||||||
<label for="statify-blacklist_active_referer">
|
<label for="statify-blacklist_active_referer">
|
||||||
<input type="checkbox" name="statifyblacklist[active_referer]" id="statifyblacklist_active_referer" value="1" <?php checked(StatifyBlacklist::$_options['active_referer'], 1); ?> />
|
<input type="checkbox" name="statifyblacklist[active_referer]" id="statifyblacklist_active_referer"
|
||||||
|
value="1" <?php checked( StatifyBlacklist::$_options['active_referer'], 1 ); ?> />
|
||||||
<?php esc_html_e( 'Activate referer blacklist', 'statify-blacklist' ); ?>
|
<?php esc_html_e( 'Activate referer blacklist', 'statify-blacklist' ); ?>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
@ -71,23 +75,29 @@ if ( !empty($_POST['statifyblacklist']) ) {
|
|||||||
<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/>
|
||||||
<textarea cols="40" rows="5" name="statifyblacklist[referer]" id="statify-blacklist_referer"><?php
|
<textarea cols="40" rows="5" name="statifyblacklist[referer]" id="statify-blacklist_referer"><?php
|
||||||
if (isset($statifyBlacklistUpdateResult) &&$statifyBlacklistUpdateResult !== false)
|
if ( isset( $statifyBlacklistUpdateResult ) && $statifyBlacklistUpdateResult !== false ) {
|
||||||
print esc_html( implode( "\r\n", $statifyBlacklistUpdateResult ) );
|
print esc_html( implode( "\r\n", $statifyBlacklistUpdateResult ) );
|
||||||
else
|
} else {
|
||||||
print esc_html( implode( "\r\n", StatifyBlacklist::$_options['referer'] ) );
|
print esc_html( implode( "\r\n", StatifyBlacklist::$_options['referer'] ) );
|
||||||
?></textarea><br />
|
}
|
||||||
<small>(<?php esc_html_e('Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist'); ?>)</small>
|
?></textarea>
|
||||||
|
<br />
|
||||||
|
<small>
|
||||||
|
(<?php esc_html_e( 'Add one domain (without subdomains) each line, e.g. example.com', 'statify-blacklist' ); ?>
|
||||||
|
)
|
||||||
|
</small>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<?php wp_nonce_field( 'statify-blacklist-settings' ); ?>
|
<?php wp_nonce_field( 'statify-blacklist-settings' ); ?>
|
||||||
|
|
||||||
<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" value="<?php esc_html_e('CleanUp Database', 'statify-blacklist') ?>"
|
<input class="button-secondary" type="submit" name="cleanUp"
|
||||||
|
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