prefix . NET360RECLAMACIONES_LEGACY_DB_PREFIX . '_peru_claim_history'; } public static function add( $claim_id, $type, $message = '', $user_id = null ) { global $wpdb; if ( null === $user_id ) { $user_id = get_current_user_id(); } $wpdb->insert( self::table(), array( 'claim_id' => (int) $claim_id, 'event_type' => sanitize_key( $type ), 'message' => sanitize_textarea_field( $message ), 'user_id' => $user_id ? (int) $user_id : null, 'created_at'=> current_time('mysql'), ) ); } public static function all( $claim_id ) { global $wpdb; $table = self::table(); $users = $wpdb->users; return $wpdb->get_results( $wpdb->prepare( 'SELECT h.*, u.display_name FROM %i h LEFT JOIN %i u ON u.ID = h.user_id WHERE h.claim_id = %d ORDER BY h.created_at DESC, h.id DESC', $table, $users, (int) $claim_id ) ); } }