Exemplo n.º 1
0
 /**
  * Assembles records for display in search filters
  *
  * Gathers list of all authors/connectors, then compares it to
  * results of existing records.  All items that do not exist in records
  * get assigned a disabled value of "true".
  *
  * @uses   wp_stream_existing_records (see query.php)
  * @since  1.0.4
  *
  * @param  string  Column requested
  * @param  string  Table to be queried
  *
  * @return array   options to be displayed in search filters
  */
 function assemble_records($column, $table = '')
 {
     $setting_key = self::get_column_excluded_setting_key($column);
     $exclude_hide_previous_records = isset(WP_Stream_Settings::$options['exclude_hide_previous_records']) ? WP_Stream_Settings::$options['exclude_hide_previous_records'] : 0;
     /**
      * Toggle visibility of disabled connectors/actions/contexts on list table filter dropdown
      *
      * @param bool $hidden Visibility status, default is Hide Previous Record value set in Exclude setting.
      */
     $hide_disabled_column_filter = apply_filters('wp_stream_list_table_hide_disabled_ ' . $setting_key, 0 === $exclude_hide_previous_records ? false : true);
     // @todo eliminate special condition for authors, especially using a WP_User object as the value; should use string or stringifiable object
     if ('author' === $column) {
         require_once WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
         $all_records = array();
         // 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) {
             return array();
         }
         $authors = array_map(function ($user_id) {
             return new WP_Stream_Author($user_id);
         }, get_users(array('fields' => 'ID')));
         $authors[] = new WP_Stream_Author(0, array('is_wp_cli' => true));
         if ($hide_disabled_column_filter) {
             $excluded_records = WP_Stream_Settings::get_excluded_by_key($setting_key);
         }
         foreach ($authors as $author) {
             if ($hide_disabled_column_filter && in_array($author->id, $excluded_records)) {
                 continue;
             }
             $all_records[$author->id] = $author->get_display_name();
         }
     } else {
         $prefixed_column = sprintf('stream_%s', $column);
         $all_records = WP_Stream_Connectors::$term_labels[$prefixed_column];
         if (true === $hide_disabled_column_filter) {
             $excluded_records = WP_Stream_Settings::get_excluded_by_key($setting_key);
             foreach (array_keys($all_records) as $_connector) {
                 if (in_array($_connector, $excluded_records)) {
                     unset($all_records[$_connector]);
                 }
             }
         }
     }
     $existing_records = wp_stream_existing_records($column, $table);
     $active_records = array();
     $disabled_records = array();
     foreach ($all_records as $record => $label) {
         if (array_key_exists($record, $existing_records)) {
             $active_records[$record] = array('label' => $label, 'disabled' => '');
         } else {
             $disabled_records[$record] = array('label' => $label, 'disabled' => 'disabled="disabled"');
         }
     }
     // Remove WP-CLI pseudo user if no records with user=0 exist
     if (isset($disabled_records[0])) {
         unset($disabled_records[0]);
     }
     $sort = function ($a, $b) use($column) {
         $label_a = (string) $a['label'];
         $label_b = (string) $b['label'];
         if ($label_a === $label_b) {
             return 0;
         }
         return strtolower($label_a) < strtolower($label_b) ? -1 : 1;
     };
     uasort($active_records, $sort);
     uasort($disabled_records, $sort);
     // Not using array_merge() in order to preserve the array index for the Authors dropdown which uses the user_id as the key
     $all_records = $active_records + $disabled_records;
     return $all_records;
 }
Exemplo n.º 2
0
 /**
  * Function will add excluded settings args into stream query
  *
  * @param $args array query args passed to stream_query
  *
  * @return array
  */
 public static function add_excluded_record_args($args)
 {
     // Remove record of excluded connector
     $args['connector__not_in'] = WP_Stream_Settings::get_excluded_by_key('connectors');
     // Remove record of excluded context
     $args['context__not_in'] = WP_Stream_Settings::get_excluded_by_key('contexts');
     // Remove record of excluded actions
     $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');
     // 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');
     return $args;
 }
Exemplo n.º 3
0
 /**
  * This function is use to check whether logging is enabled
  *
  * @param $column string name of the setting key (actions|ip_addresses|contexts|connectors)
  * @param $value string to check in excluded array
  * @return array
  */
 public static function is_logging_enabled($column, $value)
 {
     $excluded_values = WP_Stream_Settings::get_excluded_by_key($column);
     $bool = !in_array($value, $excluded_values);
     return $bool;
 }