当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_User_Query::prepare_query方法代码示例

本文整理汇总了PHP中WP_User_Query::prepare_query方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User_Query::prepare_query方法的具体用法?PHP WP_User_Query::prepare_query怎么用?PHP WP_User_Query::prepare_query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_User_Query的用法示例。


在下文中一共展示了WP_User_Query::prepare_query方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

 function __construct($search_term = '', $page_num = '', $search_args = array(), $meta_args = array(), $additional_url_args = array())
 {
     global $wpdb;
     $this->additional_url_args = $additional_url_args;
     if (!empty($search_args['users_per_page']) && is_numeric($search_args['users_per_page'])) {
         $this->users_per_page = $search_args['users_per_page'];
     }
     $this->search_term = $search_term;
     $this->raw_page = '' == $page_num ? false : (int) $page_num;
     $this->page_num = (int) ('' == $page_num) ? 1 : $page_num;
     $args = array('search' => $this->search_term, 'number' => $this->users_per_page, 'offset' => ($this->page_num - 1) * $this->users_per_page);
     $search_args['meta_key'] = 'role';
     //( isset( $search_args['meta_key'] ) ? $search_args['meta_key'] : '' );
     $search_args['meta_value'] = 'student';
     //( isset( $search_args['meta_value'] ) ? $search_args['meta_value'] : '' );
     if (!empty($meta_args)) {
         $meta_args['number'] = $this->users_per_page;
         $meta_args['offset'] = ($this->page_num - 1) * $this->users_per_page;
         $args = $meta_args;
     }
     if (is_multisite()) {
         $args['meta_key'] = $wpdb->prefix . 'role';
     }
     $args['blog_id'] = get_current_blog_id();
     $this->query_vars = wp_parse_args($args, array('meta_value' => $search_args['meta_value'], 'meta_compare' => '', 'include' => array(), 'exclude' => array(), 'search' => '', 'search_columns' => array(), 'orderby' => 'ID', 'order' => 'ASC', 'offset' => ($this->page_num - 1) * $this->users_per_page, 'number' => '', 'count_total' => true, 'fields' => 'all_with_meta', 'who' => '', 'has_published_posts' => null));
     add_action('pre_user_query', array(&$this, 'add_first_and_last'));
     parent::prepare_query();
     $this->query();
     $this->do_paging();
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:30,代码来源:class.studentsearch.php

示例2: get_members

 /**
  * Get users who signed up for a membership.
  *
  * @param array $args
  * @return WP_User_Query
  */
 public function get_members($args)
 {
     global $wpdb;
     $user_query = new WP_User_Query();
     $user_query->prepare_query($args);
     $user_query->query_from .= ' INNER JOIN ' . $this->tbl_members . ' ib_edu_m ON ib_edu_m.user_id = ' . $wpdb->users . '.ID';
     $user_query->query();
     return $user_query;
 }
开发者ID:zaro,项目名称:ibeducator,代码行数:15,代码来源:Memberships.php

示例3:

 function capture_query($args)
 {
     $args['count_total'] = false;
     $uq = new WP_User_Query();
     $uq->_p2p_capture = true;
     // needed by P2P_URL_Query
     $uq->prepare_query($args);
     return "SELECT {$uq->query_fields} {$uq->query_from} {$uq->query_where} {$uq->query_orderby} {$uq->query_limit}";
 }
开发者ID:vladflip,项目名称:carewp,代码行数:9,代码来源:side-user.php

示例4:

 function test_exclude()
 {
     $users = new WP_User_Query();
     $users->set('fields', '');
     $users->set('exclude', $this->user_id);
     $users->prepare_query();
     $users->query();
     $ids = $users->get_results();
     $this->assertNotContains($this->user_id, $ids);
 }
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:10,代码来源:query.php

示例5: array

 function capture_query($args)
 {
     $args['count_total'] = false;
     $uq = new WP_User_Query();
     $uq->_p2p_capture = true;
     // needed by P2P_URL_Query
     // see http://core.trac.wordpress.org/ticket/21119
     $uq->query_vars = wp_parse_args($args, array('blog_id' => $GLOBALS['blog_id'], 'role' => '', 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'include' => array(), 'exclude' => array(), 'search' => '', 'search_columns' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'number' => '', 'count_total' => true, 'fields' => 'all', 'who' => ''));
     $uq->prepare_query();
     return "SELECT {$uq->query_fields} {$uq->query_from} {$uq->query_where} {$uq->query_orderby} {$uq->query_limit}";
 }
开发者ID:TyRichards,项目名称:ty_the_band,代码行数:11,代码来源:side-user.php

示例6: array

 function __construct($search_term = '', $page_num = '')
 {
     global $wpdb;
     $this->search_term = $search_term;
     $this->raw_page = '' == $page_num ? false : (int) $page_num;
     $this->page_num = (int) ('' == $page_num) ? 1 : $page_num;
     $args = array('search' => $this->search_term, 'number' => $this->users_per_page, 'offset' => ($this->page_num - 1) * $this->users_per_page, 'fields' => 'all');
     $meta_key = 'role_ins';
     if (is_multisite()) {
         $args['meta_key'] = $wpdb->prefix . 'role_ins';
     } else {
         $args['meta_key'] = 'role_ins';
     }
     $args['blog_id'] = get_current_blog_id();
     $this->query_vars = wp_parse_args($args, array('meta_value' => 'instructor', 'meta_compare' => '', 'include' => array(), 'exclude' => array(), 'search' => '', 'search_columns' => '', 'counter' => '', 'orderby' => 'login', 'order' => 'ASC', 'offset' => ($this->page_num - 1) * $this->users_per_page, 'number' => $this->users_per_page, 'count_total' => true, 'fields' => 'all', 'who' => ''));
     $this->query_vars = $args;
     add_action('pre_user_query', array(&$this, 'add_first_and_last'));
     parent::prepare_query();
     $this->query();
     $this->do_paging();
 }
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:21,代码来源:class.instructorsearch.php

示例7: test_calling_prepare_query_a_second_time_should_not_add_another_cap_query_on_multisite

 /**
  * @ticket 22212
  * @ticket 21119
  */
 public function test_calling_prepare_query_a_second_time_should_not_add_another_cap_query_on_multisite()
 {
     if (!is_multisite()) {
         $this->markTestSkipped(__METHOD__ . ' requires Multisite.');
     }
     $site_id = get_current_blog_id();
     add_user_to_blog($site_id, self::$author_ids[0], 'author');
     $q = new WP_User_Query(array('include' => self::$author_ids[0]));
     $r1 = $q->request;
     $q->prepare_query(array('include' => self::$author_ids[0]));
     $r2 = $q->request;
     $q->prepare_query(array('include' => self::$author_ids[0]));
     $r3 = $q->request;
     $this->assertSame($r1, $r2);
     $this->assertSame($r1, $r3);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:20,代码来源:query.php

示例8:

 /**
  * @ticket 21119
  */
 function test_prepare_query()
 {
     $query = new WP_User_Query();
     $this->assertEmpty($query->query_fields);
     $this->assertEmpty($query->query_from);
     $this->assertEmpty($query->query_limit);
     $this->assertEmpty($query->query_orderby);
     $this->assertEmpty($query->query_where);
     $this->assertEmpty($query->query_vars);
     $_query_vars = $query->query_vars;
     $query->prepare_query();
     $this->assertNotEmpty($query->query_fields);
     $this->assertNotEmpty($query->query_from);
     $this->assertEmpty($query->query_limit);
     $this->assertNotEmpty($query->query_orderby);
     $this->assertNotEmpty($query->query_where);
     $this->assertNotEmpty($query->query_vars);
     $this->assertNotEquals($_query_vars, $query->query_vars);
     // All values get reset
     $query->prepare_query(array('number' => 8));
     $this->assertNotEmpty($query->query_limit);
     $this->assertEquals('LIMIT 8', $query->query_limit);
     // All values get reset
     $query->prepare_query(array('fields' => 'all'));
     $this->assertEmpty($query->query_limit);
     $this->assertEquals('', $query->query_limit);
     $_query_vars = $query->query_vars;
     $query->prepare_query();
     $this->assertEquals($_query_vars, $query->query_vars);
 }
开发者ID:Benrajalu,项目名称:philRaj,代码行数:33,代码来源:query.php

示例9: pre_user_query

 /**
  * Resets the user query to handle request for unapproved users only.
  *
  * @author Konstantin Obenland
  * @since  2.2.0 - 30.03.2013
  * @access public
  *
  * @param  WP_User_Query $query
  *
  * @return void
  */
 public function pre_user_query($query)
 {
     if ('wpau_unapproved' == $query->query_vars['role']) {
         unset($query->query_vars['meta_query'][0]);
         $query->query_vars['role'] = '';
         $query->query_vars['meta_key'] = 'wp-approve-user';
         $query->query_vars['meta_value'] = false;
         $query->prepare_query();
     }
 }
开发者ID:taeche,项目名称:SoDoEx,代码行数:21,代码来源:wp-approve-user.php

示例10: array

 /**
  * our own prepare_query
  * first, we call the original one
  * then do our own stuff for
  * levels, statuses, etc.
  */
 function prepare_query($query = array())
 {
     global $wpdb;
     global $WishListMemberInstance;
     // add display_name to search columns
     add_filter('user_search_columns', array($this, 'user_search_columns_filter'), 10, 3);
     parent::prepare_query($query);
     add_filter('user_search_columns', array($this, 'user_search_columns_filter'), 10);
     $wpm_levels = $WishListMemberInstance->GetOption('wpm_levels');
     $search_sql = array();
     /**
      * Filters By Membership Level
      * incomplete/nonmembers has special handling
      **/
     $level = $this->additional_filters['level'];
     if (!empty($level)) {
         if ($level == 'incomplete') {
             $search_sql[] = "{$wpdb->users}.user_login REGEXP '^temp_[a-f0-9]{32}'";
             $search_sql[] = "{$wpdb->users}.user_login = {$wpdb->users}.user_email";
         } else {
             if ($level == 'nonmembers') {
                 $search_sql[] = "(ul.level_id  IS NULL)";
             } else {
                 $search_sql[] = $wpdb->prepare("ul.level_id=%s", $this->additional_filters['level']);
             }
         }
     }
     /** Filters By Sequential Status **/
     $sequential_filter = isset($this->additional_filters['sequential']) ? $this->additional_filters['sequential'] : false;
     if ($sequential_filter) {
         $filter = $sequential_filter == 'on' ? 1 : 0;
         $search_sql[] = $wpdb->prepare("( uo.option_name='sequential' AND uo.option_value=%d ) ", $filter);
     }
     /**
      * Filters By Status
      * Note that expired members are handled differently
      */
     $status = isset($this->additional_filters['status']) ? $this->additional_filters['status'] : false;
     if ($status) {
         $expired_sql = array();
         $inactive_sql = array();
         $active_sql = array();
         //expired members are specially handled
         $ids = array();
         $expiredmembers = $WishListMemberInstance->ExpiredMembersID();
         //flatten the result
         $ids = call_user_func_array('array_merge', $expiredmembers);
         if (empty($ids)) {
             $ids = array(-1);
         }
         $expired_sql[] = "{$wpdb->users}.ID IN (" . implode(',', $ids) . ")";
         $inactives = array('cancelled', 'unconfirmed', 'forapproval');
         foreach ($inactives as $i) {
             $inactive_sql[] = $wpdb->prepare("( ulo.option_name=%s AND ulo.option_value=%d )", $i, 1);
         }
         switch ($status) {
             case 'expired':
                 $search_sql = array_merge($search_sql, $expired_sql);
                 break;
             case 'inactive':
                 $or_sql = array_merge($expired_sql, $inactive_sql);
                 $search_sql[] = "(" . implode(' OR ', $or_sql) . ")";
                 break;
             case 'cancelled':
             case 'uncomfirmed':
             case 'forapproval':
                 $search_sql[] = $wpdb->prepare("( ulo.option_name=%s AND ulo.option_value=%d )", $status, 1);
             default:
                 break;
         }
     }
     /**
      * Filter by Date Ranges
      * Again, due to expired being computed on the fly
      * it has to be handled in a specific way
      */
     $date_meta = !empty($this->additional_filters['date_type']) ? $this->additional_filters['date_type'] : false;
     if ($date_meta) {
         //no real option rather than initiate a sub-query since dates are stored as strings
         if ($date_meta == 'expiration_date') {
             $ids = array();
             $expired_ts_from = strtotime($this->additional_filters['from_date']);
             $expired_ts_to = strtotime($this->additional_filters['to_date']);
             if ($expired_ts_to <= 0) {
                 $expired_ts_to = time();
             }
             $expiredmembers = $WishListMemberInstance->ExpiredMembersID();
             foreach ($expiredmembers as $level_id => $expired_per_level) {
                 foreach ($expired_per_level as $user_id) {
                     $expired_ts = $WishListMemberInstance->LevelExpireDate($level_id, $user_id);
                     if ($expired_ts >= $expired_ts_from && $expired_ts <= $expired_ts_to) {
                         $ids[] = $user_id;
                     }
                 }
//.........这里部分代码省略.........
开发者ID:brooklyntri,项目名称:btc-plugins,代码行数:101,代码来源:UserSearch_WP31.php


注:本文中的WP_User_Query::prepare_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。