示例#1
0
 public static function start_timer()
 {
     self::$execution_start_time = self::microtime_float();
 }
 private function get_post_from_last_query()
 {
     global $wpdb;
     if (empty($wpdb->last_query)) {
         return null;
     }
     $keys = array('WHERE ID=');
     $post_id = 0;
     foreach ($keys as $key) {
         $post_id = URE_Utils::get_int_after_key($key, $wpdb->last_query);
         if ($post_id > 0) {
             break;
         }
     }
     if (empty($post_id)) {
         return null;
     }
     $post = get_post($post_id);
     return $post;
 }
 /**
  * Assign role to the users without role
  */
 public function make()
 {
     $this->job_init();
     $job_data = $this->lib->get_option('ure_assign_role_job');
     if (empty($job_data->users)) {
         return;
     }
     $users_processed = 0;
     foreach ($job_data->users as $key => $user_id) {
         if (!$this->lib->debug) {
             URE_Utils::sleep_to_maintain_ratio(self::TARGET_USAGE_FRACTION);
         }
         $this->assign_role_to_user($user_id, $job_data->new_role);
         unset($job_data->users[$key]);
         $users_processed++;
         if (!$this->lib->debug) {
             // Check if we still have some execution time left
             if (URE_Utils::get_execution_time() > self::MAX_EXECUTION_TIME || URE_Utils::server_too_busy() || $users_processed > MAX_USERS_TO_PROCESS) {
                 // let's stop
                 $this->job_cleanup($job_data);
                 return;
             }
         }
     }
     // foreach()
     $this->job_cleanup($job_data);
 }