diff --git a/includes/connectors.php b/includes/connectors.php index 7c803ab19..c22530c16 100644 --- a/includes/connectors.php +++ b/includes/connectors.php @@ -167,18 +167,24 @@ public static function is_logging_enabled_for_user( $user = null ) { $user = wp_get_current_user(); } - // If the user is not a valid user then we log action + $bool = true; + $user_roles = array_values( $user->roles ); + $excluded_authors = WP_Stream_Settings::get_excluded_by_key( 'authors' ); + $excluded_roles = WP_Stream_Settings::get_excluded_by_key( 'roles' ); + + // Don't log excluded users + if ( in_array( $user->ID, $excluded_authors ) ) { + $bool = false; + } + + // Don't log excluded user roles + if ( 0 !== count( array_intersect( $user_roles, $excluded_roles ) ) ) { + $bool = false; + } + + // If the user is not a valid user then we always log the action if ( ! ( $user instanceof WP_User ) || 0 === $user->ID ) { $bool = true; - } else { - // If a user is part of a role that we don't want to log, we disable it - $user_roles = array_values( $user->roles ); - $roles_logged = WP_Stream_Settings::get_excluded_by_key( 'authors_and_roles' ); - $bool = ( 0 === count( array_intersect( $user_roles, $roles_logged ) ) ); - //Check user id in exclude array - if ( $bool ) { - $bool = ! ( in_array( $user->ID, $roles_logged ) ); - } } /** diff --git a/includes/list-table.php b/includes/list-table.php index fed349444..5fa86eb2d 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -401,7 +401,7 @@ function assemble_records( $column, $table = '' ) { require_once WP_STREAM_INC_DIR . 'class-wp-stream-author.php'; $all_records = array(); - // Short circuit and return empty array if we have more than 10 users, to use Ajax instead + // If the number of users exceeds the max authors constant value then return an empty array and use AJAX instead $user_count = count_users(); $total_users = $user_count['total_users']; if ( $total_users > WP_Stream_Admin::PRELOAD_AUTHORS_MAX ) { @@ -751,7 +751,7 @@ function get_column_excluded_setting_key( $column ) { $output = 'ip_addresses'; break; case 'author': - $output = 'authors_and_roles'; + $output = 'authors'; break; default: $output = false; diff --git a/includes/network.php b/includes/network.php index dafb3ebcf..ba516c013 100644 --- a/includes/network.php +++ b/includes/network.php @@ -254,7 +254,8 @@ function get_network_admin_fields( $fields ) { 'private_feeds', ), 'exclude' => array( - 'authors_and_roles', + 'authors', + 'roles', 'connectors', 'contexts', 'actions', diff --git a/includes/query.php b/includes/query.php index 0c87ea21f..4efe08756 100755 --- a/includes/query.php +++ b/includes/query.php @@ -362,7 +362,10 @@ public static function add_excluded_record_args( $args ) { $args['action__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'actions' ); // Remove record of excluded author - $args['author__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'authors_and_roles' ); + $args['author__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'authors' ); + + // Remove record of excluded author role + $args['author_role__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'roles' ); // Remove record of excluded ip $args['ip__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'ip_addresses' ); diff --git a/includes/settings.php b/includes/settings.php index 548b599ed..d7635adc2 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -105,6 +105,7 @@ public static function get_users(){ 'user_url', ), 'orderby' => 'display_name', + 'number' => WP_Stream_Admin::PRELOAD_AUTHORS_MAX, ) ); @@ -212,6 +213,7 @@ public static function get_option_key() { $option_key = self::KEY; $current_page = wp_stream_filter_input( INPUT_GET, 'page' ); + if ( ! $current_page ) { $current_page = wp_stream_filter_input( INPUT_GET, 'action' ); } @@ -846,12 +848,13 @@ public static function get_active_connectors() { } /** - * @param $column string name of the setting key (actions|ip_addresses|contexts|connectors) + * @param $column string name of the setting key (authors|roles|actions|ip_addresses|contexts|connectors) * * @return array */ public static function get_excluded_by_key( $column ) { - $option_name = 'exclude_' . $column; + $option_name = ( 'authors' === $column || 'roles' === $column ) ? 'exclude_authors_and_roles' : 'exclude_' . $column; + $excluded_values = ( isset( self::$options[ $option_name ] ) ) ? self::$options[ $option_name ] : array(); if ( is_callable( $excluded_values ) ) { @@ -860,6 +863,21 @@ public static function get_excluded_by_key( $column ) { $excluded_values = wp_list_filter( $excluded_values, array( '__placeholder__' ), 'NOT' ); + if ( 'exclude_authors_and_roles' === $option_name ) { + // Convert numeric strings to integers + array_walk( $excluded_values, + function ( &$value ) { + if ( is_numeric( $value ) ) { + $value = absint( $value ); + } + } + ); + + $filter = ( 'roles' === $column ) ? 'is_string' : 'is_int'; // Author roles are always strings and author ID's are always integers + + $excluded_values = array_values( array_filter( $excluded_values, $filter ) ); // Reset the array keys + } + return $excluded_values; } diff --git a/stream.php b/stream.php index 697a10126..25731d1ab 100755 --- a/stream.php +++ b/stream.php @@ -83,9 +83,9 @@ private function __construct() { // Load languages add_action( 'plugins_loaded', array( __CLASS__, 'i18n' ) ); - // Load settings, enabling extensions to hook in + // Load settings at the same priority as connectors to support exclusions require_once WP_STREAM_INC_DIR . 'settings.php'; - add_action( 'init', array( 'WP_Stream_Settings', 'load' ) ); + add_action( 'init', array( 'WP_Stream_Settings', 'load' ), 9 ); // Load network class if ( is_multisite() ) { @@ -97,7 +97,7 @@ private function __construct() { require_once WP_STREAM_INC_DIR . 'log.php'; add_action( 'plugins_loaded', array( 'WP_Stream_Log', 'load' ) ); - // Load connectors + // Load connectors after widgets_init, but before the default of 10 require_once WP_STREAM_INC_DIR . 'connectors.php'; add_action( 'init', array( 'WP_Stream_Connectors', 'load' ), 9 ); diff --git a/tests/tests/test-stream.php b/tests/tests/test-stream.php index 15e8ed1c2..639219aa0 100644 --- a/tests/tests/test-stream.php +++ b/tests/tests/test-stream.php @@ -19,7 +19,7 @@ public function test_constructor() { $this->assertTrue( defined( 'WP_STREAM_INC_DIR' ), 'WP_STREAM_INC_DIR is not defined' ); $actions_tests = array( - array( 'init', 'WP_Stream_Settings', 'load' ), + array( 'init', 'WP_Stream_Settings', 'load', 9 ), array( 'plugins_loaded', 'WP_Stream_Log', 'load' ), array( 'init', 'WP_Stream_Connectors', 'load', 9 ), );