Пример #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;
 }
 /**
  * Ajax callback function to search IP addresses, used on exclude setting page
  *
  * @uses WP_User_Query WordPress User Query class.
  * @return void
  */
 public static function get_ips()
 {
     if (!defined('DOING_AJAX') || !current_user_can(WP_Stream_Admin::SETTINGS_CAP)) {
         return;
     }
     check_ajax_referer('stream_get_ips', 'nonce');
     $ips = wp_stream_existing_records('ip');
     if ($ips) {
         wp_send_json_success($ips);
     } else {
         wp_send_json_error();
     }
 }
Пример #3
0
/**
 * existing_records()
 *
 * @deprecated 1.3.2
 * @deprecated Use wp_stream_existing_records
 * @see wp_stream_existing_records()
 */
function existing_records($column, $table = '')
{
    _deprecated_function(__FUNCTION__, '1.3.2', 'wp_stream_existing_records()');
    return wp_stream_existing_records($column, $table);
}