コード例 #1
0
 public function get_items(WP_REST_Request $request)
 {
     $args = array('id' => $request['id'], 'page' => $request['page'], 'records_per_page' => $request['records-per-page'], 'after_id' => $request['after-id'], 'before_id' => $request['before-id'], 'from' => $request['from'], 'to' => $request['to'], 'method' => $request['method'], 'status' => $request['status'], 'route' => $request['route'], 'route_match_type' => $request['route-match-type'], 'params' => $request['params']);
     $db = new WP_REST_API_Log_DB();
     $posts = $db->search($args);
     return rest_ensure_response(WP_REST_API_Log_Entry::from_posts($posts));
 }
コード例 #2
0
 public function purge_old_records($days_old = false, $dry_run = false)
 {
     if (empty($days_old)) {
         $days_old = WP_REST_API_Log_Settings_General::setting_get('general', 'purge-days');
     }
     $days_old = absint($days_old);
     if (empty($days_old)) {
         return;
     }
     $db = new WP_REST_API_Log_DB();
     $args = array('fields' => 'ids', 'to' => date('Y-m-d H:i', current_time('timestamp') - DAY_IN_SECONDS * $days_old), 'posts_per_page' => -1);
     $ids = $db->search($args);
     $number_deleted = 0;
     if (!empty($ids) && is_array($ids)) {
         foreach ($ids as $id) {
             if (!$dry_run) {
                 wp_delete_post($id, true);
             }
             $number_deleted++;
         }
     }
     return $number_deleted;
 }